| 15 | ComicControllerV2::ComicControllerV2() { } |
| 16 | |
| 17 | void 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); |
nothing calls this directly
no test coverage detected