mirror of
https://github.com/YACReader/yacreader
synced 2025-07-14 02:54:46 -04:00
Separate v1 and v2 server api classes and execution path.
This commit is contained in:
@ -0,0 +1,72 @@
|
||||
#include "foldercontentcontroller_v2.h"
|
||||
|
||||
#include <QUrl>
|
||||
|
||||
#include "db_helper.h"
|
||||
#include "comic_db.h"
|
||||
#include "folder.h"
|
||||
|
||||
#include "yacreader_server_data_helper.h"
|
||||
|
||||
#include "qnaturalsorting.h"
|
||||
|
||||
#include <ctime>
|
||||
using namespace std;
|
||||
|
||||
struct LibraryItemSorter
|
||||
{
|
||||
bool operator()(const LibraryItem * a,const LibraryItem * b) const
|
||||
{
|
||||
return naturalSortLessThanCI(a->name,b->name);
|
||||
}
|
||||
};
|
||||
|
||||
FolderContentControllerV2::FolderContentControllerV2() {}
|
||||
|
||||
void FolderContentControllerV2::service(HttpRequest& request, HttpResponse& response)
|
||||
{
|
||||
response.setHeader("Content-Type", "text/plain; charset=utf-8");
|
||||
|
||||
QString path = QUrl::fromPercentEncoding(request.getPath()).toUtf8();
|
||||
QStringList pathElements = path.split('/');
|
||||
int libraryId = pathElements.at(3).toInt();
|
||||
qulonglong parentId = pathElements.at(5).toULongLong();
|
||||
|
||||
serviceContent(libraryId, parentId, response);
|
||||
|
||||
response.write("",true);
|
||||
}
|
||||
|
||||
void FolderContentControllerV2::serviceContent(const int &library, const qulonglong &folderId, HttpResponse &response)
|
||||
{
|
||||
//clock_t begin = clock();
|
||||
|
||||
QList<LibraryItem *> folderContent = DBHelper::getFolderSubfoldersFromLibrary(library,folderId);
|
||||
QList<LibraryItem *> folderComics = DBHelper::getFolderComicsFromLibrary(library,folderId);
|
||||
|
||||
folderContent.append(folderComics);
|
||||
qSort(folderContent.begin(),folderContent.end(),LibraryItemSorter());
|
||||
|
||||
folderComics.clear();
|
||||
|
||||
ComicDB * currentComic;
|
||||
Folder * currentFolder;
|
||||
for(QList<LibraryItem *>::const_iterator itr = folderContent.constBegin();itr!=folderContent.constEnd();itr++)
|
||||
{
|
||||
if((*itr)->isDir())
|
||||
{
|
||||
currentFolder = (Folder *)(*itr);
|
||||
response.write(YACReaderServerDataHelper::folderToYSFormat(library, *currentFolder).toUtf8());
|
||||
}
|
||||
else
|
||||
{
|
||||
currentComic = (ComicDB *)(*itr);
|
||||
response.write(YACReaderServerDataHelper::comicToYSFormat(library, *currentComic).toUtf8());
|
||||
}
|
||||
}
|
||||
|
||||
/*clock_t end = clock();
|
||||
double msecs = double(end - begin);
|
||||
|
||||
response.write(QString("%1ms").arg(msecs).toUtf8());*/
|
||||
}
|
Reference in New Issue
Block a user