mirror of
https://github.com/YACReader/yacreader
synced 2025-05-28 03:10:27 -04:00
commit
50cfb5e505
@ -22,6 +22,7 @@ Version counting is based on semantic versioning (Major.Feature.Patch)
|
||||
|
||||
### YACReaderLibraryServer
|
||||
* Add `rescan-xml-info` command.
|
||||
* Improved API to provide better integration with the clients (Android 1.4.0 and iOS 3.29.0).
|
||||
|
||||
## All Apps
|
||||
* New universal builds for macos.
|
||||
|
@ -189,6 +189,57 @@ QString DBHelper::getFolderName(qulonglong libraryId, qulonglong id)
|
||||
QSqlDatabase::removeDatabase(connectionName);
|
||||
return name;
|
||||
}
|
||||
|
||||
Folder DBHelper::getFolder(qulonglong libraryId, qulonglong id)
|
||||
{
|
||||
QString libraryPath = DBHelper::getLibraries().getPath(libraryId);
|
||||
|
||||
Folder folder;
|
||||
QString connectionName = "";
|
||||
|
||||
{
|
||||
QSqlDatabase db = DataBaseManagement::loadDatabase(libraryPath + "/.yacreaderlibrary");
|
||||
QSqlQuery selectQuery(db); // TODO check
|
||||
selectQuery.prepare("SELECT * FROM folder WHERE id = :id");
|
||||
selectQuery.bindValue(":id", id);
|
||||
selectQuery.exec();
|
||||
|
||||
auto record = selectQuery.record();
|
||||
|
||||
int name = record.indexOf("name");
|
||||
int path = record.indexOf("path");
|
||||
int finished = record.indexOf("finished");
|
||||
int completed = record.indexOf("completed");
|
||||
int id = record.indexOf("id");
|
||||
int parentId = record.indexOf("parentId");
|
||||
int numChildren = record.indexOf("numChildren");
|
||||
int firstChildHash = record.indexOf("firstChildHash");
|
||||
int customImage = record.indexOf("customImage");
|
||||
int type = record.indexOf("type");
|
||||
int added = record.indexOf("added");
|
||||
int updated = record.indexOf("updated");
|
||||
|
||||
if (selectQuery.next()) {
|
||||
folder = Folder(selectQuery.value(id).toULongLong(), parentId, selectQuery.value(name).toString(), selectQuery.value(path).toString());
|
||||
|
||||
folder.finished = selectQuery.value(finished).toBool();
|
||||
folder.completed = selectQuery.value(completed).toBool();
|
||||
if (!selectQuery.value(numChildren).isNull() && selectQuery.value(numChildren).isValid()) {
|
||||
folder.numChildren = selectQuery.value(numChildren).toInt();
|
||||
}
|
||||
folder.firstChildHash = selectQuery.value(firstChildHash).toString();
|
||||
folder.customImage = selectQuery.value(customImage).toString();
|
||||
folder.type = selectQuery.value(type).value<YACReader::FileType>();
|
||||
folder.added = selectQuery.value(added).toLongLong();
|
||||
folder.updated = selectQuery.value(updated).toLongLong();
|
||||
}
|
||||
connectionName = db.connectionName();
|
||||
}
|
||||
|
||||
QSqlDatabase::removeDatabase(connectionName);
|
||||
return folder;
|
||||
}
|
||||
|
||||
QList<QString> DBHelper::getLibrariesNames()
|
||||
{
|
||||
auto names = getLibraries().getNames();
|
||||
@ -292,7 +343,7 @@ QList<ComicDB> DBHelper::getReading(qulonglong libraryId)
|
||||
{
|
||||
QSqlDatabase db = DataBaseManagement::loadDatabase(libraryPath + "/.yacreaderlibrary");
|
||||
QSqlQuery selectQuery(db);
|
||||
selectQuery.prepare("SELECT c.id,c.parentId,c.fileName,ci.title,ci.currentPage,ci.numPages,ci.hash,ci.read,ci.coverSizeRatio "
|
||||
selectQuery.prepare("SELECT c.id,c.parentId,c.fileName,ci.title,ci.currentPage,ci.numPages,ci.hash,ci.read,ci.coverSizeRatio,ci.number "
|
||||
"FROM comic c INNER JOIN comic_info ci ON (c.comicInfoId = ci.id) "
|
||||
"WHERE ci.hasBeenOpened = 1 AND ci.read = 0 "
|
||||
"ORDER BY ci.lastTimeOpened DESC");
|
||||
@ -301,6 +352,7 @@ QList<ComicDB> DBHelper::getReading(qulonglong libraryId)
|
||||
while (selectQuery.next()) {
|
||||
ComicDB comic;
|
||||
|
||||
// TODO: use QVariant when possible to keep nulls
|
||||
comic.id = selectQuery.value(0).toULongLong();
|
||||
comic.parentId = selectQuery.value(1).toULongLong();
|
||||
comic.name = selectQuery.value(2).toString();
|
||||
@ -310,6 +362,7 @@ QList<ComicDB> DBHelper::getReading(qulonglong libraryId)
|
||||
comic.info.hash = selectQuery.value(6).toString();
|
||||
comic.info.read = selectQuery.value(7).toBool();
|
||||
comic.info.coverSizeRatio = selectQuery.value(8).toFloat();
|
||||
comic.info.number = selectQuery.value(9);
|
||||
|
||||
list.append(comic);
|
||||
}
|
||||
@ -1010,13 +1063,18 @@ QMap<qulonglong, QList<ComicDB>> DBHelper::updateFromRemoteClient(const QMap<qul
|
||||
|
||||
foreach (ComicInfo comicInfo, comics[libraryId]) {
|
||||
bool found;
|
||||
// TODO: sanitize this -> comicInfo.id contains comic id
|
||||
ComicDB comic = DBHelper::loadComic(comicInfo.id, db, found);
|
||||
|
||||
if (comic.info.hash == comicInfo.hash) {
|
||||
bool isMoreRecent = false;
|
||||
|
||||
// completion takes precedence over lastTimeOpened, if we just want to synchronize the lastest status we should use only lastTimeOpened
|
||||
if ((comic.info.currentPage > 1 && comic.info.currentPage > comicInfo.currentPage) || comic.info.hasBeenOpened || (comic.info.read && !comicInfo.read)) {
|
||||
if ((comic.info.currentPage > 1 && comic.info.currentPage > comicInfo.currentPage) || (comic.info.read && !comicInfo.read)) {
|
||||
isMoreRecent = true;
|
||||
}
|
||||
|
||||
if (comic.info.hasBeenOpened && comic.info.currentPage > comicInfo.currentPage) {
|
||||
isMoreRecent = true;
|
||||
}
|
||||
|
||||
|
@ -31,6 +31,7 @@ public:
|
||||
static ComicDB getComicInfo(qulonglong libraryId, qulonglong id);
|
||||
static QList<ComicDB> getSiblings(qulonglong libraryId, qulonglong parentId);
|
||||
static QString getFolderName(qulonglong libraryId, qulonglong id);
|
||||
static Folder getFolder(qulonglong libraryId, qulonglong id);
|
||||
static QList<QString> getLibrariesNames();
|
||||
static QString getLibraryName(int id);
|
||||
static QList<ComicDB> getLabelComics(qulonglong libraryId, qulonglong labelId);
|
||||
|
@ -4,12 +4,10 @@
|
||||
|
||||
#include "db_helper.h"
|
||||
#include "comic_db.h"
|
||||
#include "folder.h"
|
||||
|
||||
#include "yacreader_libraries.h"
|
||||
#include "yacreader_server_data_helper.h"
|
||||
|
||||
#include "qnaturalsorting.h"
|
||||
|
||||
#include <ctime>
|
||||
|
||||
using stefanfrings::HttpRequest;
|
||||
@ -35,9 +33,11 @@ void ComicFullinfoController_v2::service(HttpRequest &request, HttpResponse &res
|
||||
|
||||
void ComicFullinfoController_v2::serviceContent(const int &libraryId, const qulonglong &comicId, HttpResponse &response)
|
||||
{
|
||||
auto libraryUuid = DBHelper::getLibraries().getLibraryIdFromLegacyId(libraryId);
|
||||
|
||||
ComicDB comic = DBHelper::getComicInfo(libraryId, comicId);
|
||||
|
||||
QJsonObject json = YACReaderServerDataHelper::fullComicToJSON(libraryId, comic);
|
||||
QJsonObject json = YACReaderServerDataHelper::fullComicToJSON(libraryId, libraryUuid, comic);
|
||||
|
||||
QJsonDocument output(json);
|
||||
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include "db_helper.h"
|
||||
#include "comic_db.h"
|
||||
|
||||
#include "yacreader_libraries.h"
|
||||
#include "yacreader_server_data_helper.h"
|
||||
|
||||
using stefanfrings::HttpRequest;
|
||||
@ -25,12 +26,14 @@ void FavoritesControllerV2::service(HttpRequest &request, HttpResponse &response
|
||||
|
||||
void FavoritesControllerV2::serviceContent(const int library, HttpResponse &response)
|
||||
{
|
||||
auto libraryUuid = DBHelper::getLibraries().getLibraryIdFromLegacyId(library);
|
||||
|
||||
QList<ComicDB> comics = DBHelper::getFavorites(library);
|
||||
|
||||
QJsonArray items;
|
||||
|
||||
for (const ComicDB &comic : comics) {
|
||||
items.append(YACReaderServerDataHelper::comicToJSON(library, comic));
|
||||
items.append(YACReaderServerDataHelper::comicToJSON(library, libraryUuid, comic));
|
||||
}
|
||||
|
||||
QJsonDocument output(items);
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include "comic_db.h"
|
||||
#include "folder.h"
|
||||
|
||||
#include "yacreader_libraries.h"
|
||||
#include "yacreader_server_data_helper.h"
|
||||
|
||||
#include "qnaturalsorting.h"
|
||||
@ -41,6 +42,8 @@ void FolderContentControllerV2::serviceContent(const int &library, const qulongl
|
||||
#ifdef QT_DEBUG
|
||||
auto started = std::chrono::high_resolution_clock::now();
|
||||
#endif
|
||||
auto libraryUuid = DBHelper::getLibraries().getLibraryIdFromLegacyId(library);
|
||||
|
||||
QList<LibraryItem *> folderContent = DBHelper::getFolderSubfoldersFromLibrary(library, folderId);
|
||||
QList<LibraryItem *> folderComics = DBHelper::getFolderComicsFromLibrary(library, folderId);
|
||||
|
||||
@ -56,10 +59,10 @@ void FolderContentControllerV2::serviceContent(const int &library, const qulongl
|
||||
for (QList<LibraryItem *>::const_iterator itr = folderContent.constBegin(); itr != folderContent.constEnd(); itr++) {
|
||||
if ((*itr)->isDir()) {
|
||||
currentFolder = (Folder *)(*itr);
|
||||
items.append(YACReaderServerDataHelper::folderToJSON(library, *currentFolder));
|
||||
items.append(YACReaderServerDataHelper::folderToJSON(library, libraryUuid, *currentFolder));
|
||||
} else {
|
||||
currentComic = (ComicDB *)(*itr);
|
||||
items.append(YACReaderServerDataHelper::comicToJSON(library, *currentComic));
|
||||
items.append(YACReaderServerDataHelper::comicToJSON(library, libraryUuid, *currentComic));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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
|
@ -2,11 +2,6 @@
|
||||
#include "db_helper.h" //get libraries
|
||||
#include "yacreader_libraries.h"
|
||||
|
||||
#include "template.h"
|
||||
#include "../static.h"
|
||||
|
||||
#include "QsLog.h"
|
||||
|
||||
using stefanfrings::HttpRequest;
|
||||
using stefanfrings::HttpResponse;
|
||||
|
||||
@ -16,20 +11,18 @@ void LibrariesControllerV2::service(HttpRequest & /* request */, HttpResponse &r
|
||||
{
|
||||
response.setHeader("Content-Type", "application/json");
|
||||
|
||||
YACReaderLibraries libraries = DBHelper::getLibraries();
|
||||
QList<QString> names = DBHelper::getLibrariesNames();
|
||||
auto libraries = DBHelper::getLibraries().sortedLibraries();
|
||||
|
||||
QJsonArray librariesJson;
|
||||
|
||||
int currentId = 0;
|
||||
foreach (QString name, names) {
|
||||
currentId = libraries.getId(name);
|
||||
QJsonObject library;
|
||||
foreach (YACReaderLibrary library, libraries) {
|
||||
QJsonObject libraryJson;
|
||||
|
||||
library["name"] = name;
|
||||
library["id"] = currentId;
|
||||
libraryJson["name"] = library.getName();
|
||||
libraryJson["id"] = library.getLegacyId();
|
||||
libraryJson["uuid"] = library.getId().toString();
|
||||
|
||||
librariesJson.append(library);
|
||||
librariesJson.append(libraryJson);
|
||||
}
|
||||
|
||||
QJsonDocument output(librariesJson);
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include "db_helper.h"
|
||||
#include "comic_db.h"
|
||||
|
||||
#include "yacreader_libraries.h"
|
||||
#include "yacreader_server_data_helper.h"
|
||||
|
||||
using stefanfrings::HttpRequest;
|
||||
@ -28,12 +29,14 @@ void ReadingComicsControllerV2::service(HttpRequest &request, HttpResponse &resp
|
||||
|
||||
void ReadingComicsControllerV2::serviceContent(const int &library, HttpResponse &response)
|
||||
{
|
||||
auto libraryUuid = DBHelper::getLibraries().getLibraryIdFromLegacyId(library);
|
||||
|
||||
QList<ComicDB> readingComics = DBHelper::getReading(library);
|
||||
|
||||
QJsonArray comics;
|
||||
|
||||
for (const ComicDB &comic : readingComics) {
|
||||
comics.append(YACReaderServerDataHelper::comicToJSON(library, comic));
|
||||
comics.append(YACReaderServerDataHelper::comicToJSON(library, libraryUuid, comic));
|
||||
}
|
||||
|
||||
QJsonDocument output(comics);
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include "db_helper.h"
|
||||
#include "comic_db.h"
|
||||
|
||||
#include "yacreader_libraries.h"
|
||||
#include "yacreader_server_data_helper.h"
|
||||
|
||||
using stefanfrings::HttpRequest;
|
||||
@ -28,12 +29,14 @@ void ReadingListContentControllerV2::service(HttpRequest &request, HttpResponse
|
||||
|
||||
void ReadingListContentControllerV2::serviceContent(const int &library, const qulonglong &readingListId, HttpResponse &response)
|
||||
{
|
||||
auto libraryUuid = DBHelper::getLibraries().getLibraryIdFromLegacyId(library);
|
||||
|
||||
QList<ComicDB> comics = DBHelper::getReadingListFullContent(library, readingListId);
|
||||
|
||||
QJsonArray items;
|
||||
|
||||
for (const ComicDB &comic : comics) {
|
||||
items.append(YACReaderServerDataHelper::comicToJSON(library, comic));
|
||||
items.append(YACReaderServerDataHelper::comicToJSON(library, libraryUuid, comic));
|
||||
}
|
||||
|
||||
QJsonDocument output(items);
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
#include "db_helper.h"
|
||||
#include "reading_list.h"
|
||||
#include "yacreader_libraries.h"
|
||||
#include "yacreader_server_data_helper.h"
|
||||
|
||||
using stefanfrings::HttpRequest;
|
||||
@ -26,12 +27,14 @@ void ReadingListsControllerV2::service(HttpRequest &request, HttpResponse &respo
|
||||
|
||||
void ReadingListsControllerV2::serviceContent(const int library, HttpResponse &response)
|
||||
{
|
||||
auto libraryUuid = DBHelper::getLibraries().getLibraryIdFromLegacyId(library);
|
||||
|
||||
QList<ReadingList> readingLists = DBHelper::getReadingLists(library);
|
||||
|
||||
QJsonArray items;
|
||||
|
||||
for (QList<ReadingList>::const_iterator itr = readingLists.constBegin(); itr != readingLists.constEnd(); itr++) {
|
||||
items.append(YACReaderServerDataHelper::readingListToJSON(library, *itr));
|
||||
items.append(YACReaderServerDataHelper::readingListToJSON(library, libraryUuid, *itr));
|
||||
}
|
||||
|
||||
QJsonDocument output(items);
|
||||
|
@ -5,6 +5,7 @@
|
||||
|
||||
#include "comic_db.h"
|
||||
#include "db_helper.h"
|
||||
#include "yacreader_libraries.h"
|
||||
#include "yacreader_server_data_helper.h"
|
||||
|
||||
using stefanfrings::HttpRequest;
|
||||
@ -33,10 +34,46 @@ void SyncControllerV2::service(HttpRequest &request, HttpResponse &response)
|
||||
QString hash;
|
||||
QMap<qulonglong, QList<ComicInfo>> comics;
|
||||
QList<ComicInfo> comicsWithNoLibrary;
|
||||
|
||||
auto libraries = DBHelper::getLibraries();
|
||||
|
||||
foreach (QString comicInfo, data) {
|
||||
QList<QString> comicInfoProgress = comicInfo.split("\t");
|
||||
|
||||
if (comicInfoProgress.length() >= 6) {
|
||||
if (comicInfoProgress.length() >= 8) {
|
||||
if (comicInfoProgress.at(0) != "u") {
|
||||
continue;
|
||||
}
|
||||
|
||||
auto libraryUuid = QUuid(comicInfoProgress.at(1));
|
||||
if (!libraryUuid.isNull()) {
|
||||
auto libraryId = libraries.getIdFromUuid(libraryUuid);
|
||||
if (libraryId == -1) {
|
||||
continue;
|
||||
}
|
||||
comicId = comicInfoProgress.at(2).toULongLong();
|
||||
hash = comicInfoProgress.at(3);
|
||||
currentPage = comicInfoProgress.at(4).toInt();
|
||||
|
||||
ComicInfo info;
|
||||
info.currentPage = currentPage;
|
||||
info.hash = hash; // TODO remove the hash check and add UUIDs for libraries
|
||||
info.id = comicId;
|
||||
|
||||
currentRating = comicInfoProgress.at(5).toInt();
|
||||
info.rating = currentRating;
|
||||
|
||||
lastTimeOpened = comicInfoProgress.at(6).toULong();
|
||||
info.lastTimeOpened = lastTimeOpened;
|
||||
|
||||
info.read = comicInfoProgress.at(7).toInt();
|
||||
|
||||
if (!comics.contains(libraryId)) {
|
||||
comics[libraryId] = QList<ComicInfo>();
|
||||
}
|
||||
comics[libraryId].push_back(info);
|
||||
}
|
||||
} else if (comicInfoProgress.length() >= 6) {
|
||||
if (comicInfoProgress.at(0) != "unknown") {
|
||||
libraryId = comicInfoProgress.at(0).toULongLong();
|
||||
comicId = comicInfoProgress.at(1).toULongLong();
|
||||
@ -81,13 +118,17 @@ void SyncControllerV2::service(HttpRequest &request, HttpResponse &response)
|
||||
}
|
||||
}
|
||||
|
||||
auto moreRecentComicsFound = DBHelper::updateFromRemoteClient(comics);
|
||||
|
||||
QJsonArray items;
|
||||
|
||||
foreach (qulonglong libraryId, moreRecentComicsFound.keys()) {
|
||||
foreach (ComicDB comic, moreRecentComicsFound[libraryId]) {
|
||||
items.append(YACReaderServerDataHelper::comicToJSON(libraryId, comic));
|
||||
if (!comics.isEmpty()) {
|
||||
auto moreRecentComicsFound = DBHelper::updateFromRemoteClient(comics);
|
||||
|
||||
foreach (qulonglong libraryId, moreRecentComicsFound.keys()) {
|
||||
auto libraryUuid = DBHelper::getLibraries().getLibraryIdFromLegacyId(libraryId);
|
||||
|
||||
foreach (ComicDB comic, moreRecentComicsFound[libraryId]) {
|
||||
items.append(YACReaderServerDataHelper::comicToJSON(libraryId, libraryUuid, comic));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include "db_helper.h"
|
||||
#include "comic_db.h"
|
||||
|
||||
#include "yacreader_libraries.h"
|
||||
#include "yacreader_server_data_helper.h"
|
||||
|
||||
#include <QUrl>
|
||||
@ -30,12 +31,14 @@ void TagContentControllerV2::service(HttpRequest &request, HttpResponse &respons
|
||||
|
||||
void TagContentControllerV2::serviceContent(const int &library, const qulonglong &tagId, HttpResponse &response)
|
||||
{
|
||||
auto libraryUuid = DBHelper::getLibraries().getLibraryIdFromLegacyId(library);
|
||||
|
||||
QList<ComicDB> comics = DBHelper::getLabelComics(library, tagId);
|
||||
|
||||
QJsonArray items;
|
||||
|
||||
for (const ComicDB &comic : comics) {
|
||||
items.append(YACReaderServerDataHelper::comicToJSON(library, comic));
|
||||
items.append(YACReaderServerDataHelper::comicToJSON(library, libraryUuid, comic));
|
||||
}
|
||||
|
||||
QJsonDocument output(items);
|
||||
|
@ -4,13 +4,9 @@
|
||||
#include "yacreader_libraries.h"
|
||||
|
||||
#include "reading_list.h"
|
||||
#include "../static.h"
|
||||
#include "yacreader_global.h"
|
||||
|
||||
#include "yacreader_server_data_helper.h"
|
||||
|
||||
#include "QsLog.h"
|
||||
|
||||
using stefanfrings::HttpRequest;
|
||||
using stefanfrings::HttpResponse;
|
||||
|
||||
@ -26,10 +22,12 @@ void TagsControllerV2::service(HttpRequest &request, HttpResponse &response)
|
||||
|
||||
QList<Label> labels = DBHelper::getLabels(libraryId);
|
||||
|
||||
auto libraryUuid = DBHelper::getLibraries().getLibraryIdFromLegacyId(libraryId);
|
||||
|
||||
QJsonArray items;
|
||||
|
||||
for (QList<Label>::const_iterator itr = labels.constBegin(); itr != labels.constEnd(); itr++) {
|
||||
items.append(YACReaderServerDataHelper::labelToJSON(libraryId, *itr));
|
||||
items.append(YACReaderServerDataHelper::labelToJSON(libraryId, libraryUuid, *itr));
|
||||
}
|
||||
|
||||
QJsonDocument output(items);
|
||||
|
@ -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));
|
||||
|
@ -9,6 +9,7 @@ DEPENDPATH += $$PWD/controllers/v2
|
||||
|
||||
|
||||
HEADERS += \
|
||||
$$PWD/controllers/v2/foldermetadatacontroller_v2.h \
|
||||
$$PWD/controllers/v2/searchcontroller_v2.h \
|
||||
$$PWD/static.h \
|
||||
$$PWD/requestmapper.h \
|
||||
@ -54,6 +55,7 @@ HEADERS += \
|
||||
|
||||
|
||||
SOURCES += \
|
||||
$$PWD/controllers/v2/foldermetadatacontroller_v2.cpp \
|
||||
$$PWD/controllers/v2/searchcontroller_v2.cpp \
|
||||
$$PWD/static.cpp \
|
||||
$$PWD/requestmapper.cpp \
|
||||
@ -100,4 +102,4 @@ SOURCES += \
|
||||
include(../../third_party/QtWebApp/httpserver/httpserver.pri)
|
||||
include(../../third_party/QtWebApp/templateengine/templateengine.pri)
|
||||
|
||||
DEFINES += SERVER_VERSION_NUMBER=\\\"2.0\\\"
|
||||
DEFINES += SERVER_VERSION_NUMBER=\\\"2.1\\\"
|
||||
|
@ -1,5 +1,35 @@
|
||||
#include "yacreader_server_data_helper.h"
|
||||
|
||||
void variantToJson(const QString &name, QMetaType::Type type, const QVariant &value, QJsonObject &json)
|
||||
{
|
||||
if (value.isNull() || !value.isValid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (type) {
|
||||
case QMetaType::Bool:
|
||||
json[name] = value.toBool();
|
||||
break;
|
||||
case QMetaType::Int:
|
||||
json[name] = value.toInt();
|
||||
break;
|
||||
case QMetaType::Float:
|
||||
json[name] = value.toFloat();
|
||||
break;
|
||||
case QMetaType::Double:
|
||||
json[name] = value.toDouble();
|
||||
break;
|
||||
case QMetaType::LongLong:
|
||||
json[name] = value.toLongLong();
|
||||
break;
|
||||
case QMetaType::QString:
|
||||
json[name] = value.toString();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
QString YACReaderServerDataHelper::folderToYSFormat(const qulonglong libraryId, const Folder &folder)
|
||||
{
|
||||
return QString("f\x1F\t%1\x1F\t%2\x1F\t%3\x1F\t%4\x1F\t%5\x1E\r\n")
|
||||
@ -23,13 +53,16 @@ QString YACReaderServerDataHelper::comicToYSFormat(const qulonglong libraryId, c
|
||||
.arg(comic.info.read ? 1 : 0);
|
||||
}
|
||||
|
||||
QJsonObject YACReaderServerDataHelper::folderToJSON(const qulonglong libraryId, const Folder &folder)
|
||||
QJsonObject YACReaderServerDataHelper::folderToJSON(const qulonglong libraryId, const QUuid libraryUuid, const Folder &folder)
|
||||
{
|
||||
QJsonObject json;
|
||||
|
||||
json["type"] = "folder";
|
||||
json["id"] = QString::number(folder.id);
|
||||
json["library_id"] = QString::number(libraryId);
|
||||
if (!libraryUuid.isNull()) {
|
||||
json["library_uuid"] = libraryUuid.toString();
|
||||
}
|
||||
json["folder_name"] = folder.name;
|
||||
json["num_children"] = folder.numChildren;
|
||||
json["first_comic_hash"] = folder.firstChildHash;
|
||||
@ -40,93 +73,117 @@ QJsonObject YACReaderServerDataHelper::folderToJSON(const qulonglong libraryId,
|
||||
json["file_type"] = static_cast<typename std::underlying_type<YACReader::FileType>::type>(folder.type);
|
||||
json["added"] = folder.added;
|
||||
json["updated"] = folder.updated;
|
||||
// 9.14
|
||||
json["parent_id"] = QString::number(folder.parentId);
|
||||
json["path"] = folder.path;
|
||||
|
||||
return json;
|
||||
}
|
||||
|
||||
QJsonObject YACReaderServerDataHelper::comicToJSON(const qulonglong libraryId, const ComicDB &comic)
|
||||
QJsonObject YACReaderServerDataHelper::comicToJSON(const qulonglong libraryId, const QUuid libraryUuid, const ComicDB &comic)
|
||||
{
|
||||
QJsonObject json;
|
||||
|
||||
json["type"] = "comic";
|
||||
json["id"] = QString::number(comic.id);
|
||||
json["comic_info_id"] = QString::number(comic.info.id);
|
||||
json["parent_id"] = QString::number(comic.parentId); // 9.14
|
||||
json["library_id"] = QString::number(libraryId);
|
||||
if (!libraryUuid.isNull()) {
|
||||
json["library_uuid"] = libraryUuid.toString();
|
||||
}
|
||||
json["file_name"] = comic.name;
|
||||
json["file_size"] = QString::number(comic.getFileSize());
|
||||
json["hash"] = comic.info.hash;
|
||||
json["cover_page"] = comic.info.coverPage.toInt(); // 9.13
|
||||
json["path"] = comic.path; // 9.14
|
||||
|
||||
json["current_page"] = comic.info.currentPage;
|
||||
json["num_pages"] = comic.info.numPages.toInt();
|
||||
json["read"] = comic.info.read;
|
||||
json["cover_size_ratio"] = comic.info.coverSizeRatio.toFloat();
|
||||
json["title"] = comic.info.title.toString();
|
||||
json["number"] = comic.info.number.toInt(); // 9.13 legacy, kept for compatibility with old clients
|
||||
json["universal_number"] = comic.info.number.toString(); // 9.13, text based number
|
||||
json["last_time_opened"] = comic.info.lastTimeOpened.toLongLong();
|
||||
auto type = comic.info.type.value<YACReader::FileType>();
|
||||
json["manga"] = type == YACReader::FileType::Manga; // legacy, kept for compatibility with old clients
|
||||
json["file_type"] = comic.info.type.toInt(); // 9.13
|
||||
json["cover_size_ratio"] = comic.info.coverSizeRatio.toFloat();
|
||||
|
||||
// legacy
|
||||
json["number"] = comic.info.number.toInt();
|
||||
|
||||
variantToJson("cover_page", QMetaType::Int, comic.info.coverPage, json);
|
||||
variantToJson("title", QMetaType::QString, comic.info.title, json);
|
||||
variantToJson("universal_number", QMetaType::QString, comic.info.number, json);
|
||||
variantToJson("last_time_opened", QMetaType::LongLong, comic.info.lastTimeOpened, json);
|
||||
|
||||
variantToJson("added", QMetaType::LongLong, comic.info.added, json);
|
||||
|
||||
return json;
|
||||
}
|
||||
|
||||
QJsonObject YACReaderServerDataHelper::fullComicToJSON(const qulonglong libraryId, const ComicDB &comic)
|
||||
QJsonObject YACReaderServerDataHelper::fullComicToJSON(const qulonglong libraryId, const QUuid libraryUuid, const ComicDB &comic)
|
||||
{
|
||||
QJsonObject json = comicToJSON(libraryId, comic);
|
||||
QJsonObject json = comicToJSON(libraryId, libraryUuid, comic);
|
||||
|
||||
json["volume"] = comic.info.volume.toString();
|
||||
json["total_volume_count"] = comic.info.count.toInt();
|
||||
json["genre"] = comic.info.genere.toString();
|
||||
json["date"] = comic.info.date.toString();
|
||||
|
||||
json["synopsis"] = comic.info.synopsis.toString();
|
||||
variantToJson("volume", QMetaType::QString, comic.info.volume, json);
|
||||
variantToJson("total_volume_count", QMetaType::Int, comic.info.count, json);
|
||||
variantToJson("genre", QMetaType::QString, comic.info.genere, json);
|
||||
variantToJson("date", QMetaType::QString, comic.info.date, json);
|
||||
variantToJson("synopsis", QMetaType::QString, comic.info.synopsis, json);
|
||||
|
||||
// 9.13
|
||||
json["count"] = comic.info.count.toInt();
|
||||
json["story_arc"] = comic.info.storyArc.toString();
|
||||
json["arc_number"] = comic.info.arcNumber.toString();
|
||||
json["arc_count"] = comic.info.arcCount.toInt();
|
||||
json["writer"] = comic.info.writer.toString();
|
||||
json["penciller"] = comic.info.penciller.toString();
|
||||
json["inker"] = comic.info.inker.toString();
|
||||
json["colorist"] = comic.info.colorist.toString();
|
||||
json["letterer"] = comic.info.letterer.toString();
|
||||
json["cover_artist"] = comic.info.coverArtist.toString();
|
||||
json["publisher"] = comic.info.publisher.toString();
|
||||
json["format"] = comic.info.format.toString();
|
||||
json["color"] = comic.info.color.toBool();
|
||||
json["age_rating"] = comic.info.ageRating.toString();
|
||||
json["editor"] = comic.info.editor.toString();
|
||||
json["characters"] = comic.info.characters.toString();
|
||||
json["notes"] = comic.info.notes.toString();
|
||||
json["added"] = comic.info.added.toLongLong();
|
||||
json["editor"] = comic.info.editor.toString();
|
||||
json["imprint"] = comic.info.imprint.toString();
|
||||
json["teams"] = comic.info.teams.toString();
|
||||
json["locations"] = comic.info.locations.toString();
|
||||
json["series"] = comic.info.series.toString();
|
||||
json["alternate_series"] = comic.info.alternateSeries.toString();
|
||||
json["alternate_number"] = comic.info.alternateNumber.toString();
|
||||
json["alternate_count"] = comic.info.alternateCount.toInt();
|
||||
json["language_iso"] = comic.info.languageISO.toString();
|
||||
json["series_group"] = comic.info.seriesGroup.toString();
|
||||
json["main_character_or_team"] = comic.info.mainCharacterOrTeam.toString();
|
||||
json["review"] = comic.info.review.toString();
|
||||
json["tags"] = comic.info.tags.toString();
|
||||
auto type = comic.info.type.value<YACReader::FileType>();
|
||||
json["manga"] = type == YACReader::FileType::Manga; // legacy, kept for compatibility with old clients
|
||||
json["file_type"] = comic.info.type.toInt(); // 9.13
|
||||
variantToJson("count", QMetaType::Int, comic.info.count, json);
|
||||
variantToJson("story_arc", QMetaType::QString, comic.info.storyArc, json);
|
||||
variantToJson("arc_number", QMetaType::QString, comic.info.arcNumber, json);
|
||||
variantToJson("arc_count", QMetaType::Int, comic.info.arcCount, json);
|
||||
variantToJson("writer", QMetaType::QString, comic.info.writer, json);
|
||||
variantToJson("penciller", QMetaType::QString, comic.info.penciller, json);
|
||||
variantToJson("inker", QMetaType::QString, comic.info.inker, json);
|
||||
variantToJson("colorist", QMetaType::QString, comic.info.colorist, json);
|
||||
variantToJson("letterer", QMetaType::QString, comic.info.letterer, json);
|
||||
variantToJson("cover_artist", QMetaType::QString, comic.info.coverArtist, json);
|
||||
variantToJson("publisher", QMetaType::QString, comic.info.publisher, json);
|
||||
variantToJson("format", QMetaType::QString, comic.info.format, json);
|
||||
variantToJson("color", QMetaType::Bool, comic.info.color, json);
|
||||
variantToJson("age_rating", QMetaType::QString, comic.info.ageRating, json);
|
||||
variantToJson("editor", QMetaType::QString, comic.info.editor, json);
|
||||
variantToJson("characters", QMetaType::QString, comic.info.characters, json);
|
||||
variantToJson("notes", QMetaType::QString, comic.info.notes, json);
|
||||
variantToJson("imprint", QMetaType::QString, comic.info.imprint, json);
|
||||
variantToJson("teams", QMetaType::QString, comic.info.teams, json);
|
||||
variantToJson("locations", QMetaType::QString, comic.info.locations, json);
|
||||
variantToJson("series", QMetaType::QString, comic.info.series, json);
|
||||
variantToJson("alternate_series", QMetaType::QString, comic.info.alternateSeries, json);
|
||||
variantToJson("alternate_number", QMetaType::QString, comic.info.alternateNumber, json);
|
||||
variantToJson("alternate_count", QMetaType::Int, comic.info.alternateCount, json);
|
||||
variantToJson("language_iso", QMetaType::QString, comic.info.languageISO, json);
|
||||
variantToJson("series_group", QMetaType::QString, comic.info.seriesGroup, json);
|
||||
variantToJson("main_character_or_team", QMetaType::QString, comic.info.mainCharacterOrTeam, json);
|
||||
variantToJson("review", QMetaType::QString, comic.info.review, json);
|
||||
variantToJson("tags", QMetaType::QString, comic.info.tags, json);
|
||||
// 9.14
|
||||
json["rating"] = comic.info.rating;
|
||||
variantToJson("comic_vine_id", QMetaType::QString, comic.info.comicVineID, json);
|
||||
variantToJson("original_cover_size", QMetaType::QString, comic.info.originalCoverSize, json);
|
||||
json["edited"] = comic.info.edited;
|
||||
json["has_been_opened"] = comic.info.hasBeenOpened;
|
||||
json["bookmark1"] = comic.info.bookmark1;
|
||||
json["bookmark2"] = comic.info.bookmark2;
|
||||
json["bookmark3"] = comic.info.bookmark3;
|
||||
json["brightness"] = comic.info.brightness;
|
||||
json["contrast"] = comic.info.contrast;
|
||||
json["gamma"] = comic.info.gamma;
|
||||
|
||||
return json;
|
||||
}
|
||||
|
||||
QJsonObject YACReaderServerDataHelper::readingListToJSON(const qulonglong libraryId, const ReadingList &readingList)
|
||||
QJsonObject YACReaderServerDataHelper::readingListToJSON(const qulonglong libraryId, const QUuid libraryUuid, const ReadingList &readingList)
|
||||
{
|
||||
QJsonObject json;
|
||||
|
||||
json["type"] = "reading_list";
|
||||
json["id"] = QString::number(readingList.getId());
|
||||
json["library_id"] = QString::number(libraryId);
|
||||
if (!libraryUuid.isNull()) {
|
||||
json["library_uuid"] = libraryUuid.toString();
|
||||
}
|
||||
json["reading_list_name"] = readingList.getName();
|
||||
|
||||
// TODO
|
||||
@ -136,13 +193,16 @@ QJsonObject YACReaderServerDataHelper::readingListToJSON(const qulonglong librar
|
||||
return json;
|
||||
}
|
||||
|
||||
QJsonObject YACReaderServerDataHelper::labelToJSON(const qulonglong libraryId, const Label &label)
|
||||
QJsonObject YACReaderServerDataHelper::labelToJSON(const qulonglong libraryId, const QUuid libraryUuid, const Label &label)
|
||||
{
|
||||
QJsonObject json;
|
||||
|
||||
json["type"] = "label";
|
||||
json["id"] = QString::number(label.getId());
|
||||
json["library_id"] = QString::number(libraryId);
|
||||
if (!libraryUuid.isNull()) {
|
||||
json["library_uuid"] = libraryUuid.toString();
|
||||
}
|
||||
json["label_name"] = label.getName();
|
||||
json["color_id"] = label.getColorID();
|
||||
|
||||
|
@ -12,11 +12,11 @@ public:
|
||||
static QString folderToYSFormat(const qulonglong libraryId, const Folder &folder);
|
||||
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 fullComicToJSON(const qulonglong libraryId, const ComicDB &comic);
|
||||
static QJsonObject readingListToJSON(const qulonglong libraryId, const ReadingList &readingList);
|
||||
static QJsonObject labelToJSON(const qulonglong libraryId, const Label &label);
|
||||
static QJsonObject folderToJSON(const qulonglong libraryId, const QUuid libraryUuid, const Folder &folder);
|
||||
static QJsonObject comicToJSON(const qulonglong libraryId, const QUuid libraryUuid, const ComicDB &comic);
|
||||
static QJsonObject fullComicToJSON(const qulonglong libraryId, const QUuid libraryUuid, const ComicDB &comic);
|
||||
static QJsonObject readingListToJSON(const qulonglong libraryId, const QUuid libraryUuid, const ReadingList &readingList);
|
||||
static QJsonObject labelToJSON(const qulonglong libraryId, const QUuid libraryUuid, const Label &label);
|
||||
|
||||
private:
|
||||
YACReaderServerDataHelper();
|
||||
|
@ -1,4 +1,5 @@
|
||||
#include "yacreader_libraries.h"
|
||||
#include "qnaturalsorting.h"
|
||||
#include "yacreader_global.h"
|
||||
|
||||
void writeIdToLibraryFolder(const QString &path, const QUuid &id)
|
||||
@ -100,6 +101,12 @@ int YACReaderLibraries::getId(const QString &name)
|
||||
return library != libraries.cend() ? library->getLegacyId() : -1;
|
||||
}
|
||||
|
||||
int YACReaderLibraries::getIdFromUuid(const QUuid &uuid)
|
||||
{
|
||||
auto library = std::find_if(libraries.cbegin(), libraries.cend(), [uuid](const YACReaderLibrary &library) { return library.getId() == uuid; });
|
||||
return library != libraries.cend() ? library->getLegacyId() : -1;
|
||||
}
|
||||
|
||||
YACReaderLibraries &YACReaderLibraries::operator=(const YACReaderLibraries &source)
|
||||
{
|
||||
libraries = source.libraries;
|
||||
@ -111,6 +118,19 @@ QList<YACReaderLibrary> YACReaderLibraries::getLibraries() const
|
||||
return libraries;
|
||||
}
|
||||
|
||||
QList<YACReaderLibrary> YACReaderLibraries::sortedLibraries() const
|
||||
{
|
||||
auto sortedLibraries = libraries;
|
||||
std::sort(sortedLibraries.begin(), sortedLibraries.end(), [](const YACReaderLibrary &library1, const YACReaderLibrary &library2) { return naturalSortLessThanCI(library1.getName(), library2.getName()); });
|
||||
return sortedLibraries;
|
||||
}
|
||||
|
||||
QUuid YACReaderLibraries::getLibraryIdFromLegacyId(int legacyId) const
|
||||
{
|
||||
auto library = std::find_if(libraries.cbegin(), libraries.cend(), [legacyId](const YACReaderLibrary &library) { return library.getLegacyId() == legacyId; });
|
||||
return library != libraries.cend() ? library->getId() : QUuid();
|
||||
}
|
||||
|
||||
void YACReaderLibraries::addLibrary(const QString &name, const QString &path)
|
||||
{
|
||||
int legacyId = 0;
|
||||
|
@ -23,8 +23,11 @@ public:
|
||||
void remove(const QString &name);
|
||||
void rename(const QString &oldName, const QString &newName);
|
||||
int getId(const QString &name);
|
||||
int getIdFromUuid(const QUuid &uuid);
|
||||
YACReaderLibraries &operator=(const YACReaderLibraries &source);
|
||||
QList<YACReaderLibrary> getLibraries() const;
|
||||
QList<YACReaderLibrary> sortedLibraries() const;
|
||||
QUuid getLibraryIdFromLegacyId(int legacyId) const;
|
||||
public slots:
|
||||
void addLibrary(const QString &name, const QString &path);
|
||||
void load();
|
||||
|
@ -6,7 +6,7 @@
|
||||
#include <QMetaType>
|
||||
#include <QAbstractItemModel>
|
||||
|
||||
#define VERSION "9.14.0"
|
||||
#define VERSION "9.14.1"
|
||||
|
||||
// Used to check if the database needs to be updated, the version is stored in the database.
|
||||
// This value is only incremented when the database structure changes.
|
||||
|
Loading…
Reference in New Issue
Block a user