From a3f314976479ce619244c5a479e38264bbb732c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20=C3=81ngel=20San=20Mart=C3=ADn?= Date: Thu, 29 Aug 2024 19:01:48 +0200 Subject: [PATCH] Return 404 if the comic is not found --- .../server/controllers/v2/comiccontroller_v2.cpp | 6 ++++++ .../v2/comiccontrollerinreadinglist_v2.cpp | 6 ++++++ .../v2/comicdownloadinfocontroller_v2.cpp | 6 ++++++ .../controllers/v2/comicfullinfocontroller_v2.cpp | 12 +++++++++--- 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/YACReaderLibrary/server/controllers/v2/comiccontroller_v2.cpp b/YACReaderLibrary/server/controllers/v2/comiccontroller_v2.cpp index 1332777d..c2d457be 100644 --- a/YACReaderLibrary/server/controllers/v2/comiccontroller_v2.cpp +++ b/YACReaderLibrary/server/controllers/v2/comiccontroller_v2.cpp @@ -57,6 +57,12 @@ void ComicControllerV2::service(HttpRequest &request, HttpResponse &response) ComicDB comic = DBHelper::getComicInfo(libraryId, comicId); + if (!comic.info.existOnDb) { + response.setStatus(404, "Not Found"); + response.write("", true); + return; + } + Comic *comicFile = FactoryComic::newComic(libraries.getPath(libraryId) + comic.path); if (comicFile != nullptr) { diff --git a/YACReaderLibrary/server/controllers/v2/comiccontrollerinreadinglist_v2.cpp b/YACReaderLibrary/server/controllers/v2/comiccontrollerinreadinglist_v2.cpp index 3cb41eb1..96113d2e 100644 --- a/YACReaderLibrary/server/controllers/v2/comiccontrollerinreadinglist_v2.cpp +++ b/YACReaderLibrary/server/controllers/v2/comiccontrollerinreadinglist_v2.cpp @@ -44,6 +44,12 @@ void ComicControllerInReadingListV2::service(HttpRequest &request, HttpResponse ComicDB comic = DBHelper::getComicInfo(libraryId, comicId); + if (!comic.info.existOnDb) { + response.setStatus(404, "Not Found"); + response.write("", true); + return; + } + Comic *comicFile = FactoryComic::newComic(libraries.getPath(libraryId) + comic.path); if (comicFile != nullptr) { diff --git a/YACReaderLibrary/server/controllers/v2/comicdownloadinfocontroller_v2.cpp b/YACReaderLibrary/server/controllers/v2/comicdownloadinfocontroller_v2.cpp index 70af0f94..c9a97a0b 100644 --- a/YACReaderLibrary/server/controllers/v2/comicdownloadinfocontroller_v2.cpp +++ b/YACReaderLibrary/server/controllers/v2/comicdownloadinfocontroller_v2.cpp @@ -22,6 +22,12 @@ void ComicDownloadInfoControllerV2::service(HttpRequest &request, HttpResponse & ComicDB comic = DBHelper::getComicInfo(libraryId, comicId); + if (!comic.info.existOnDb) { + response.setStatus(404, "Not Found"); + response.write("", true); + return; + } + // TODO: check if the comic wasn't found; response.write(QString("fileName:%1\r\n").arg(comic.getFileName()).toUtf8()); response.write(QString("fileSize:%1\r\n").arg(comic.getFileSize()).toUtf8()); diff --git a/YACReaderLibrary/server/controllers/v2/comicfullinfocontroller_v2.cpp b/YACReaderLibrary/server/controllers/v2/comicfullinfocontroller_v2.cpp index 8bc43ce6..8f06c83b 100644 --- a/YACReaderLibrary/server/controllers/v2/comicfullinfocontroller_v2.cpp +++ b/YACReaderLibrary/server/controllers/v2/comicfullinfocontroller_v2.cpp @@ -26,9 +26,6 @@ void ComicFullinfoController_v2::service(HttpRequest &request, HttpResponse &res qulonglong comicId = pathElements.at(5).toULongLong(); serviceContent(libraryId, comicId, response); - - response.setStatus(200, "OK"); - response.write("", true); } void ComicFullinfoController_v2::serviceContent(const int &libraryId, const qulonglong &comicId, HttpResponse &response) @@ -37,9 +34,18 @@ void ComicFullinfoController_v2::serviceContent(const int &libraryId, const qulo ComicDB comic = DBHelper::getComicInfo(libraryId, comicId); + if (!comic.info.existOnDb) { + response.setStatus(404, "Not Found"); + response.write("", true); + return; + } + QJsonObject json = YACReaderServerDataHelper::fullComicToJSON(libraryId, libraryUuid, comic); QJsonDocument output(json); response.write(output.toJson(QJsonDocument::Compact)); + + response.setStatus(200, "OK"); + response.write("", true); }