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

Method service

YACReaderLibrary/server/controllers/v2/comiccontroller_v2.cpp:17–129  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

15ComicControllerV2::ComicControllerV2() { }
16
17void ComicControllerV2::service(HttpRequest &request, HttpResponse &response)
18{
19
20 QByteArray token = request.getHeader("x-request-id");
21 YACReaderHttpSession *ySession = Static::yacreaderSessionStore->getYACReaderSessionHttpSession(token);
22
23 if (ySession == nullptr) {
24 response.setStatus(404, "not found");
25 response.write("404 not found", true);
26 return;
27 }
28
29 QString path = QUrl::fromPercentEncoding(request.getPath()).toUtf8();
30 QStringList pathElements = path.split('/');
31 qulonglong libraryId = pathElements.at(3).toLongLong();
32 QString libraryName = DBHelper::getLibraryName(libraryId);
33 qulonglong comicId = pathElements.at(5).toULongLong();
34
35 bool remoteComic = path.endsWith("remote");
36
37 // TODO
38 // if(pathElements.size() == 6)
39 //{
40 // QString action = pathElements.at(5);
41 // if(!action.isEmpty() && (action == "close"))
42 // {
43 // session.dismissCurrentComic();
44 // response.write("",true);
45 // return;
46 // }
47 // }
48
49 YACReaderLibraries libraries = DBHelper::getLibraries();
50
51 ComicDB comic = DBHelper::getComicInfo(libraryId, comicId);
52
53 if (!comic.info.existOnDb) {
54 response.setStatus(404, "Not Found");
55 response.write("", true);
56 return;
57 }
58
59 Comic *comicFile = FactoryComic::newComic(libraries.getPath(libraryId) + comic.path);
60
61 if (comicFile != nullptr) {
62 QThread *thread = nullptr;
63
64 thread = new QThread();
65
66 comicFile->moveToThread(thread);
67
68 connect(comicFile, QOverload<>::of(&Comic::errorOpening), thread, &QThread::quit);
69 connect(comicFile, QOverload<QString>::of(&Comic::errorOpening), thread, &QThread::quit);
70 connect(comicFile, &Comic::imagesLoaded, thread, &QThread::quit);
71 connect(thread, &QThread::started, comicFile, &Comic::process);
72 connect(thread, &QThread::finished, thread, &QObject::deleteLater);
73
74 comicFile->load(libraries.getPath(libraryId) + comic.path);

Callers

nothing calls this directly

Calls 11

LibraryItemSorterClass · 0.85
writeMethod · 0.80
getPathMethod · 0.80
splitMethod · 0.80
startMethod · 0.80
setCurrentRemoteComicMethod · 0.80
setCurrentComicMethod · 0.80
toTXTMethod · 0.80
QStringClass · 0.50
loadMethod · 0.45

Tested by

no test coverage detected