mirror of
https://github.com/YACReader/yacreader
synced 2025-05-28 03:10:27 -04:00
Add new controller for getting a folder
This commit is contained in:
parent
5728d4bb18
commit
53f7fd4a28
@ -0,0 +1,34 @@
|
||||
#include "foldermetadatacontroller_v2.h"
|
||||
|
||||
#include "db_helper.h"
|
||||
#include "folder.h"
|
||||
|
||||
#include "yacreader_libraries.h"
|
||||
#include "yacreader_server_data_helper.h"
|
||||
|
||||
FolderMetadataControllerV2::FolderMetadataControllerV2() { }
|
||||
|
||||
void FolderMetadataControllerV2::service(stefanfrings::HttpRequest &request, stefanfrings::HttpResponse &response)
|
||||
{
|
||||
response.setHeader("Content-Type", "application/json");
|
||||
|
||||
QString path = QUrl::fromPercentEncoding(request.getPath()).toUtf8();
|
||||
QStringList pathElements = path.split('/');
|
||||
int libraryId = pathElements.at(3).toInt();
|
||||
qulonglong folderId = pathElements.at(5).toULongLong();
|
||||
|
||||
auto folder = DBHelper::getFolder(libraryId, folderId);
|
||||
if (!folder.knownId) {
|
||||
response.setStatus(404, "not found");
|
||||
response.write("404 not found", true);
|
||||
return;
|
||||
}
|
||||
|
||||
auto libraryUuid = DBHelper::getLibraries().getLibraryIdFromLegacyId(libraryId);
|
||||
|
||||
auto json = YACReaderServerDataHelper::folderToJSON(libraryId, libraryUuid, folder);
|
||||
|
||||
QJsonDocument output(json);
|
||||
|
||||
response.write(output.toJson(QJsonDocument::Compact));
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
#ifndef FOLDERMETADATACONTROLLERV2_H
|
||||
#define FOLDERMETADATACONTROLLERV2_H
|
||||
|
||||
#include "httprequest.h"
|
||||
#include "httpresponse.h"
|
||||
#include "httprequesthandler.h"
|
||||
|
||||
class FolderMetadataControllerV2 : public stefanfrings::HttpRequestHandler
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_DISABLE_COPY(FolderMetadataControllerV2)
|
||||
public:
|
||||
/** Constructor */
|
||||
FolderMetadataControllerV2();
|
||||
|
||||
/** Generates the response */
|
||||
void service(stefanfrings::HttpRequest &request, stefanfrings::HttpResponse &response) override;
|
||||
};
|
||||
|
||||
#endif // FOLDERMETADATACONTROLLERV2_H
|
@ -35,6 +35,7 @@
|
||||
#include "controllers/v2/comicfullinfocontroller_v2.h"
|
||||
#include "controllers/v2/comiccontrollerinreadinglist_v2.h"
|
||||
#include "controllers/v2/searchcontroller_v2.h"
|
||||
#include "controllers/v2/foldermetadatacontroller_v2.h"
|
||||
|
||||
#include "controllers/webui/statuspagecontroller.h"
|
||||
|
||||
@ -237,7 +238,7 @@ void RequestMapper::serviceV2(HttpRequest &request, HttpResponse &response)
|
||||
{
|
||||
QByteArray path = request.getPath();
|
||||
|
||||
QRegExp folderInfo("/v2/library/.+/folder/[0-9]+/info/?"); // get folder info
|
||||
QRegExp folderInfo("/v2/library/.+/folder/[0-9]+/info/?"); // get folder info (all comics in a folder including subfolders recursively)
|
||||
QRegExp comicDownloadInfo("/v2/library/.+/comic/[0-9]+/info/?"); // get comic info (full download info)
|
||||
QRegExp comicOpenForDownloading("/v2/library/.+/comic/[0-9]+/?"); // get comic info (full info + opening)
|
||||
QRegExp comicOpenForRemoteReading("/v2/library/.+/comic/[0-9]+/remote/?"); // the server will open for reading the comic
|
||||
@ -250,6 +251,7 @@ void RequestMapper::serviceV2(HttpRequest &request, HttpResponse &response)
|
||||
QRegExp comicPageRemote("/v2/library/.+/comic/[0-9]+/page/[0-9]+/remote?"); // get comic page (remote reading)
|
||||
QRegExp serverVersion("/v2/version/?");
|
||||
QRegExp folderContent("/v2/library/.+/folder/[0-9]+/content/?");
|
||||
QRegExp folderMetadata("/v2/library/.+/folder/[0-9]+/metadata/?"); // get the folder metadata json (9.14)
|
||||
QRegExp favs("/v2/library/.+/favs/?");
|
||||
QRegExp reading("/v2/library/.+/reading/?");
|
||||
QRegExp tags("/v2/library/.+/tags/?");
|
||||
@ -322,6 +324,11 @@ void RequestMapper::serviceV2(HttpRequest &request, HttpResponse &response)
|
||||
TagInfoControllerV2().service(request, response);
|
||||
} else if (search.exactMatch(path)) {
|
||||
SearchController().service(request, response);
|
||||
} else if (folderMetadata.exactMatch(path)) {
|
||||
FolderMetadataControllerV2().service(request, response);
|
||||
} else {
|
||||
response.setStatus(404, "not found");
|
||||
response.write("404 not found", true);
|
||||
}
|
||||
} else {
|
||||
// response.writeText(library.cap(1));
|
||||
|
Loading…
Reference in New Issue
Block a user