MCPcopy Create free account
hub / github.com/YACReader/yacreader / service

Method service

YACReaderLibrary/server/controllers/v2/pagecontroller_v2.cpp:16–101  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

14PageControllerV2::PageControllerV2() { }
15
16void 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);

Callers

nothing calls this directly

Calls 14

writeMethod · 0.80
getPathMethod · 0.80
splitMethod · 0.80
getCurrentRemoteComicMethod · 0.80
getCurrentComicMethod · 0.80
getCurrentComicIdMethod · 0.80
hasBeenAnErrorOpeningMethod · 0.80
dismissCurrentComicMethod · 0.80
pageIsLoadedMethod · 0.80

Tested by

no test coverage detected