mirror of
https://github.com/YACReader/yacreader
synced 2025-05-28 03:10:27 -04:00
Use json in foldercontentcontoller_v2
This commit is contained in:
parent
c36d4501cc
commit
c1ba2fe77e
@ -25,7 +25,7 @@ FolderContentControllerV2::FolderContentControllerV2() {}
|
|||||||
|
|
||||||
void FolderContentControllerV2::service(HttpRequest& request, HttpResponse& response)
|
void FolderContentControllerV2::service(HttpRequest& request, HttpResponse& response)
|
||||||
{
|
{
|
||||||
response.setHeader("Content-Type", "text/plain; charset=utf-8");
|
response.setHeader("Content-Type", "application/json");
|
||||||
|
|
||||||
QString path = QUrl::fromPercentEncoding(request.getPath()).toUtf8();
|
QString path = QUrl::fromPercentEncoding(request.getPath()).toUtf8();
|
||||||
QStringList pathElements = path.split('/');
|
QStringList pathElements = path.split('/');
|
||||||
@ -34,13 +34,12 @@ void FolderContentControllerV2::service(HttpRequest& request, HttpResponse& resp
|
|||||||
|
|
||||||
serviceContent(libraryId, parentId, response);
|
serviceContent(libraryId, parentId, response);
|
||||||
|
|
||||||
|
response.setStatus(200,"OK");
|
||||||
response.write("",true);
|
response.write("",true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FolderContentControllerV2::serviceContent(const int &library, const qulonglong &folderId, HttpResponse &response)
|
void FolderContentControllerV2::serviceContent(const int &library, const qulonglong &folderId, HttpResponse &response)
|
||||||
{
|
{
|
||||||
//clock_t begin = clock();
|
|
||||||
|
|
||||||
QList<LibraryItem *> folderContent = DBHelper::getFolderSubfoldersFromLibrary(library,folderId);
|
QList<LibraryItem *> folderContent = DBHelper::getFolderSubfoldersFromLibrary(library,folderId);
|
||||||
QList<LibraryItem *> folderComics = DBHelper::getFolderComicsFromLibrary(library,folderId);
|
QList<LibraryItem *> folderComics = DBHelper::getFolderComicsFromLibrary(library,folderId);
|
||||||
|
|
||||||
@ -49,6 +48,8 @@ void FolderContentControllerV2::serviceContent(const int &library, const qulongl
|
|||||||
|
|
||||||
folderComics.clear();
|
folderComics.clear();
|
||||||
|
|
||||||
|
QJsonArray items;
|
||||||
|
|
||||||
ComicDB * currentComic;
|
ComicDB * currentComic;
|
||||||
Folder * currentFolder;
|
Folder * currentFolder;
|
||||||
for(QList<LibraryItem *>::const_iterator itr = folderContent.constBegin();itr!=folderContent.constEnd();itr++)
|
for(QList<LibraryItem *>::const_iterator itr = folderContent.constBegin();itr!=folderContent.constEnd();itr++)
|
||||||
@ -56,17 +57,16 @@ void FolderContentControllerV2::serviceContent(const int &library, const qulongl
|
|||||||
if((*itr)->isDir())
|
if((*itr)->isDir())
|
||||||
{
|
{
|
||||||
currentFolder = (Folder *)(*itr);
|
currentFolder = (Folder *)(*itr);
|
||||||
response.write(YACReaderServerDataHelper::folderToYSFormat(library, *currentFolder).toUtf8());
|
items.append(YACReaderServerDataHelper::folderToJSON(library, *currentFolder));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
currentComic = (ComicDB *)(*itr);
|
currentComic = (ComicDB *)(*itr);
|
||||||
response.write(YACReaderServerDataHelper::comicToYSFormat(library, *currentComic).toUtf8());
|
items.append(YACReaderServerDataHelper::comicToJSON(library, *currentComic));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*clock_t end = clock();
|
QJsonDocument output(items);
|
||||||
double msecs = double(end - begin);
|
|
||||||
|
|
||||||
response.write(QString("%1ms").arg(msecs).toUtf8());*/
|
response.write(output.toJson());
|
||||||
}
|
}
|
||||||
|
@ -23,12 +23,27 @@ QString YACReaderServerDataHelper::comicToYSFormat(const qulonglong libraryId,co
|
|||||||
.arg(comic.info.read?1:0);
|
.arg(comic.info.read?1:0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QJsonObject YACReaderServerDataHelper::folderToJSON(const qulonglong libraryId, const Folder & folder)
|
||||||
|
{
|
||||||
|
QJsonObject json;
|
||||||
|
|
||||||
|
json["type"] = "folder";
|
||||||
|
json["id"] = QString::number(folder.id);
|
||||||
|
json["library_id"] = QString::number(libraryId);
|
||||||
|
json["folder_name"] = folder.name;
|
||||||
|
json["num_children"] = QString::number(folder.getNumChildren());
|
||||||
|
json["first_comic_hash"] = folder.getFirstChildHash();
|
||||||
|
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
QJsonObject YACReaderServerDataHelper::comicToJSON(const qulonglong libraryId, const ComicDB & comic)
|
QJsonObject YACReaderServerDataHelper::comicToJSON(const qulonglong libraryId, const ComicDB & comic)
|
||||||
{
|
{
|
||||||
QJsonObject json;
|
QJsonObject json;
|
||||||
|
|
||||||
json["type"] = "comic";
|
json["type"] = "comic";
|
||||||
json["id"] = QString::number(comic.id);
|
json["id"] = QString::number(comic.id);
|
||||||
|
json["library_id"] = QString::number(libraryId);
|
||||||
json["file_name"] = comic.name;
|
json["file_name"] = comic.name;
|
||||||
json["file_size"] = QString::number(comic.getFileSize());
|
json["file_size"] = QString::number(comic.getFileSize());
|
||||||
json["hash"] = comic.info.hash;
|
json["hash"] = comic.info.hash;
|
||||||
|
@ -11,6 +11,7 @@ public:
|
|||||||
static QString folderToYSFormat(const qulonglong libraryId, const Folder & folder);
|
static QString folderToYSFormat(const qulonglong libraryId, const Folder & folder);
|
||||||
static QString comicToYSFormat(const qulonglong libraryId, const ComicDB & comic);
|
static QString comicToYSFormat(const qulonglong libraryId, const ComicDB & comic);
|
||||||
|
|
||||||
|
static QJsonObject folderToJSON(const qulonglong libraryId, const Folder & folder);
|
||||||
static QJsonObject comicToJSON(const qulonglong libraryId, const ComicDB & comic);
|
static QJsonObject comicToJSON(const qulonglong libraryId, const ComicDB & comic);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Loading…
Reference in New Issue
Block a user