diff --git a/YACReaderLibrary/server/controllers/foldercontentcontroller.cpp b/YACReaderLibrary/server/controllers/foldercontentcontroller.cpp new file mode 100644 index 00000000..2fcaf8a4 --- /dev/null +++ b/YACReaderLibrary/server/controllers/foldercontentcontroller.cpp @@ -0,0 +1,70 @@ +#include "foldercontentcontroller.h" + +#include + +#include "db_helper.h" +#include "comic_db.h" +#include "folder.h" + +#include "qnaturalsorting.h" + +#include +using namespace std; + +struct LibraryItemSorter +{ + bool operator()(const LibraryItem * a,const LibraryItem * b) const + { + return naturalSortLessThanCI(a->name,b->name); + } +}; + +FolderContentController::FolderContentController() {} + +void FolderContentController::service(HttpRequest& request, HttpResponse& response) +{ + response.setHeader("Content-Type", "plain/text; charset=utf-8"); + + QString path = QUrl::fromPercentEncoding(request.getPath()).toUtf8(); + QStringList pathElements = path.split('/'); + int libraryId = pathElements.at(2).toInt(); + qulonglong parentId = pathElements.at(4).toULongLong(); + + serviceContent(libraryId, parentId, response); + + response.writeText("",true); +} + +void FolderContentController::serviceContent(const int &library, const qulonglong &folderId, HttpResponse &response) +{ + clock_t begin = clock(); + + QList folderContent = DBHelper::getFolderSubfoldersFromLibrary(library,folderId); + QList folderComics = DBHelper::getFolderComicsFromLibrary(library,folderId); + + folderContent.append(folderComics); + qSort(folderContent.begin(),folderContent.end(),LibraryItemSorter()); + + folderComics.clear(); + + ComicDB * currentComic; + Folder * currentFolder; + for(QList::const_iterator itr = folderContent.constBegin();itr!=folderContent.constEnd();itr++) + { + if((*itr)->isDir()) + { + currentFolder = (Folder *)(*itr); + response.writeText(QString("f:%1:%2:%3:%4\r\n").arg(library).arg(currentFolder->id).arg(currentFolder->name).arg(currentFolder->numChildren)); + } + else + { + currentComic = (ComicDB *)(*itr); + response.writeText(QString("c:%1:%2:%3:%4:%5\r\n").arg(library).arg(currentComic->id).arg(currentComic->getFileName()).arg(currentComic->getFileSize()).arg(currentComic->info.hash)); + } + } + + clock_t end = clock(); + double msecs = double(end - begin); + + response.writeText(QString("%1ms").arg(msecs)); +} diff --git a/YACReaderLibrary/server/controllers/foldercontentcontroller.h b/YACReaderLibrary/server/controllers/foldercontentcontroller.h new file mode 100644 index 00000000..aa986042 --- /dev/null +++ b/YACReaderLibrary/server/controllers/foldercontentcontroller.h @@ -0,0 +1,22 @@ +#ifndef FOLDERCONTENTCONTROLLER_H +#define FOLDERCONTENTCONTROLLER_H + +#include "httprequest.h" +#include "httpresponse.h" +#include "httprequesthandler.h" + +class FolderContentController : public HttpRequestHandler { + Q_OBJECT + Q_DISABLE_COPY(FolderContentController); +public: + /** Constructor */ + FolderContentController(); + + /** Generates the response */ + void service(HttpRequest& request, HttpResponse& response); + +private: + void serviceContent(const int &library, const qulonglong &folderId, HttpResponse &response); +}; + +#endif // FOLDERCONTENTCONTROLLER_H diff --git a/YACReaderLibrary/server/requestmapper.cpp b/YACReaderLibrary/server/requestmapper.cpp index 75bbe613..97213261 100644 --- a/YACReaderLibrary/server/requestmapper.cpp +++ b/YACReaderLibrary/server/requestmapper.cpp @@ -23,6 +23,7 @@ #include "controllers/comicdownloadinfocontroller.h" #include "controllers/synccontroller.h" #include "controllers/versioncontroller.h" +#include "controllers/foldercontentcontroller.h" #include "db_helper.h" #include "yacreader_libraries.h" @@ -107,6 +108,7 @@ void RequestMapper::service(HttpRequest& request, HttpResponse& response) { static const QRegExp comicPage("/library/.+/comic/[0-9]+/page/[0-9]+/?"); //get comic page static const QRegExp comicPageRemote("/library/.+/comic/[0-9]+/page/[0-9]+/remote?"); //get comic page (remote reading) static const QRegExp serverVersion("/version/?"); + static const QRegExp folderContent("/library/.+/folder/[0-9]+/content/?"); static const QRegExp sync("/sync"); @@ -169,6 +171,10 @@ void RequestMapper::service(HttpRequest& request, HttpResponse& response) { { UpdateComicController().service(request, response); } + else if(folderContent.exactMatch(path)) + { + FolderContentController().service(request, response); + } } else { diff --git a/YACReaderLibrary/server/server.pri b/YACReaderLibrary/server/server.pri index 19eb50a8..6f1588b4 100644 --- a/YACReaderLibrary/server/server.pri +++ b/YACReaderLibrary/server/server.pri @@ -17,7 +17,8 @@ HEADERS += \ $$PWD/controllers/comicdownloadinfocontroller.h \ $$PWD/controllers/synccontroller.h \ #v2 - $$PWD/controllers/versioncontroller.h + $$PWD/controllers/versioncontroller.h \ + $$PWD/controllers/foldercontentcontroller.h SOURCES += \ $$PWD/static.cpp \ @@ -35,7 +36,8 @@ SOURCES += \ $$PWD/controllers/comicdownloadinfocontroller.cpp \ $$PWD/controllers/synccontroller.cpp \ #v2 - $$PWD/controllers/versioncontroller.cpp + $$PWD/controllers/versioncontroller.cpp \ + $$PWD/controllers/foldercontentcontroller.cpp include(lib/bfLogging/bfLogging.pri) include(lib/bfHttpServer/bfHttpServer.pri)