| 14 | PageControllerV2::PageControllerV2() { } |
| 15 | |
| 16 | void PageControllerV2::service(HttpRequest &request, HttpResponse &response) |
| 17 | { |
| 18 | QByteArray token = request.getHeader("x-request-id"); |
| 19 | YACReaderHttpSession *ySession = Static::yacreaderSessionStore->getYACReaderSessionHttpSession(token); |
| 20 | |
| 21 | if (ySession == nullptr) { |
| 22 | response.setStatus(424, "no session for this comic"); |
| 23 | response.write("424 no session for this comic", true); |
| 24 | return; |
| 25 | } |
| 26 | |
| 27 | QString path = QUrl::fromPercentEncoding(request.getPath()).toUtf8(); |
| 28 | bool remote = path.endsWith("remote"); |
| 29 | |
| 30 | QStringList pathElements = path.split('/'); |
| 31 | qulonglong comicId = pathElements.at(5).toULongLong(); |
| 32 | unsigned int page = pathElements.at(7).toUInt(); |
| 33 | |
| 34 | Comic *comicFile; |
| 35 | qulonglong currentComicId; |
| 36 | if (remote) { |
| 37 | QLOG_TRACE() << "se recupera comic remoto para servir páginas"; |
| 38 | comicFile = ySession->getCurrentRemoteComic(); |
| 39 | currentComicId = ySession->getCurrentRemoteComicId(); |
| 40 | } else { |
| 41 | QLOG_TRACE() << "se recupera comic para servir páginas"; |
| 42 | comicFile = ySession->getCurrentComic(); |
| 43 | currentComicId = ySession->getCurrentComicId(); |
| 44 | } |
| 45 | |
| 46 | if (comicFile == nullptr) { |
| 47 | response.setStatus(404, "not found"); |
| 48 | response.write("404 not found", true); |
| 49 | return; |
| 50 | } |
| 51 | |
| 52 | if (comicFile->hasBeenAnErrorOpening()) { |
| 53 | // delete comicFile; |
| 54 | if (remote) |
| 55 | ySession->dismissCurrentRemoteComic(); |
| 56 | else |
| 57 | ySession->dismissCurrentComic(); |
| 58 | |
| 59 | response.setStatus(404, "not found"); |
| 60 | response.write("404 not found", true); |
| 61 | return; |
| 62 | } |
| 63 | |
| 64 | if (currentComicId != 0 && !QPointer<Comic>(comicFile).isNull()) { |
| 65 | if (comicFile->numPages() == 0) { |
| 66 | response.setStatus(412, "opening file"); |
| 67 | response.write("412 opening file", true); |
| 68 | } else { |
| 69 | if (comicId == currentComicId && page < comicFile->numPages()) { |
| 70 | if (comicFile->pageIsLoaded(page)) { |
| 71 | response.setHeader("Content-Type", "image/jpeg"); |
| 72 | response.setHeader("Transfer-Encoding", "chunked"); |
| 73 | QByteArray pageData = comicFile->getRawPage(page); |
nothing calls this directly
no test coverage detected