getAttribute('code'); $codes = array_keys(ini()->getPlaylists()); if (!in_array($code, $codes, true)) { return $response->withStatus(404); } $filePath = cache_path("qr-codes/$code.jpg"); if (file_exists($filePath)) { $raw = file_get_contents($filePath); } else { $options = new QROptions([ 'version' => 5, 'outputType' => QRCode::OUTPUT_IMAGE_JPG, 'eccLevel' => QRCode::ECC_L, ]); $data = base_url("$code"); $raw = (new QRCode($options))->render($data, $filePath); $raw = base64_decode(str_replace('data:image/jpg;base64,', '', $raw)); } $mime = mime_content_type($filePath); $response->getBody()->write($raw); return $response->withStatus(200) ->withHeader('Content-Type', $mime); } /** * Возвращает информацию о плейлисте * * @param ServerRequestInterface $request * @param ResponseInterface $response * @return ResponseInterface * @throws Exception */ public function json(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface { $code = $request->getAttributes()['code']; try { $playlist = ini()->getPlaylist($code); return $this->responseJson($response, 200, $playlist); } catch (PlaylistNotFoundException $e) { return $this->responseJsonError($response, 404, $e); } } }