From b94dc7fcf50edf777859d9f1e5c11f9db03c71c2 Mon Sep 17 00:00:00 2001 From: luisangelsm Date: Wed, 19 Nov 2025 18:10:02 +0100 Subject: [PATCH] Support image filters on syncback from ios and android clients --- YACReaderLibrary/db_helper.cpp | 21 +++- YACReaderLibrary/db_helper.h | 2 +- .../controllers/v2/synccontroller_v2.cpp | 106 ++++++++++++------ 3 files changed, 92 insertions(+), 37 deletions(-) diff --git a/YACReaderLibrary/db_helper.cpp b/YACReaderLibrary/db_helper.cpp index c2963004..42d1bf82 100644 --- a/YACReaderLibrary/db_helper.cpp +++ b/YACReaderLibrary/db_helper.cpp @@ -1084,7 +1084,7 @@ void DBHelper::updateFromRemoteClient(qulonglong libraryId, const ComicInfo &com QSqlDatabase::removeDatabase(connectionName); } -QMap> DBHelper::updateFromRemoteClient(const QMap> &comics, bool clientSendsHasBeenOpened) +QMap> DBHelper::updateFromRemoteClient(const QMap> &comics, bool clientSendsHasBeenOpened, bool clientSendsImageFilters) { QMap> moreRecentComics; @@ -1105,7 +1105,9 @@ QMap> DBHelper::updateFromRemoteClient(const QMap> DBHelper::updateFromRemoteClient(const QMap comicInfo.lastTimeImageFiltersSet.toULongLong()) { + isMoreRecent = true; + } + } + comic.info.currentPage = qMax(comic.info.currentPage, comicInfo.currentPage); if (comic.info.currentPage == comic.info.numPages) @@ -1148,12 +1156,21 @@ QMap> DBHelper::updateFromRemoteClient(const QMap 0) comic.info.rating = comicInfo.rating; + if (clientSendsImageFilters) { + if (comic.info.lastTimeImageFiltersSet.toULongLong() < comicInfo.lastTimeImageFiltersSet.toULongLong()) { + comic.info.imageFiltersJson = comicInfo.imageFiltersJson; + comic.info.lastTimeImageFiltersSet = comicInfo.lastTimeImageFiltersSet; + } + } + updateComicInfo.bindValue(":read", comic.info.read ? 1 : 0); updateComicInfo.bindValue(":currentPage", comic.info.currentPage); updateComicInfo.bindValue(":hasBeenOpened", comic.info.hasBeenOpened ? 1 : 0); updateComicInfo.bindValue(":lastTimeOpened", comic.info.lastTimeOpened); updateComicInfo.bindValue(":id", comic.info.id); updateComicInfo.bindValue(":rating", comic.info.rating); + updateComicInfo.bindValue(":imageFiltersJson", comic.info.imageFiltersJson); + updateComicInfo.bindValue(":lastTimeImageFiltersSet", comic.info.lastTimeImageFiltersSet); updateComicInfo.exec(); if (isMoreRecent) { diff --git a/YACReaderLibrary/db_helper.h b/YACReaderLibrary/db_helper.h index 37d80250..56d22670 100644 --- a/YACReaderLibrary/db_helper.h +++ b/YACReaderLibrary/db_helper.h @@ -76,7 +76,7 @@ public: static void setComicAsReading(qulonglong libraryId, const ComicInfo &comicInfo); [[deprecated("Server v1")]] static void updateFromRemoteClient(qulonglong libraryId, const ComicInfo &comicInfo); static void updateReadingRemoteProgress(const ComicInfo &comicInfo, QSqlDatabase &db); - static QMap> updateFromRemoteClient(const QMap> &comics, bool clientSendsHasBeenOpened); + static QMap> updateFromRemoteClient(const QMap> &comics, bool clientSendsHasBeenOpened, bool clientSendsImageFilters); static void updateFromRemoteClientWithHash(const QList &comics); static void renameLabel(qulonglong id, const QString &name, QSqlDatabase &db); static void renameList(qulonglong id, const QString &name, QSqlDatabase &db); diff --git a/YACReaderLibrary/server/controllers/v2/synccontroller_v2.cpp b/YACReaderLibrary/server/controllers/v2/synccontroller_v2.cpp index 3b34ba70..a64a1182 100644 --- a/YACReaderLibrary/server/controllers/v2/synccontroller_v2.cpp +++ b/YACReaderLibrary/server/controllers/v2/synccontroller_v2.cpp @@ -38,48 +38,70 @@ void SyncControllerV2::service(HttpRequest &request, HttpResponse &response) auto libraries = DBHelper::getLibraries(); bool clientSendsHasBeenOpened = false; + bool clientSendsImageFilters = false; foreach (QString comicInfo, data) { + if (comicInfo.isEmpty()) { + continue; + } + QList comicInfoProgress = comicInfo.split("\t"); - if (comicInfoProgress.length() >= 9) { - if (comicInfoProgress.at(0) != "u") { + if (comicInfoProgress.isEmpty()) { + continue; + } + + if (comicInfoProgress.at(0) == "u") { // Android + clientSendsHasBeenOpened = true; + + if (comicInfoProgress.length() < 9) { continue; } - clientSendsHasBeenOpened = true; - 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.hasBeenOpened = comicInfoProgress.at(7).toInt(); - - info.read = comicInfoProgress.at(8).toInt(); - - if (!comics.contains(libraryId)) { - comics[libraryId] = QList(); - } - comics[libraryId].push_back(info); + if (libraryUuid.isNull()) { + continue; } - } else if (comicInfoProgress.length() >= 6) { + + 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.hasBeenOpened = comicInfoProgress.at(7).toInt(); + + info.read = comicInfoProgress.at(8).toInt(); + + if (comicInfoProgress.length() >= 11) { // info includes image filters + info.lastTimeImageFiltersSet = comicInfoProgress.at(9); + info.imageFiltersJson = comicInfoProgress.at(10); + clientSendsImageFilters = true; + } + + if (!comics.contains(libraryId)) { + comics[libraryId] = QList(); + } + comics[libraryId].push_back(info); + } else { // iOS + if (comicInfoProgress.length() < 6) { + continue; + } + if (comicInfoProgress.at(0) != "unknown") { libraryId = comicInfoProgress.at(0).toULongLong(); comicId = comicInfoProgress.at(1).toULongLong(); @@ -104,7 +126,16 @@ void SyncControllerV2::service(HttpRequest &request, HttpResponse &response) if (!comics.contains(libraryId)) { comics[libraryId] = QList(); } + + if (comicInfoProgress.length() >= 9) { // info includes image filters + info.lastTimeImageFiltersSet = comicInfoProgress.at(7); + info.imageFiltersJson = comicInfoProgress.at(8); + + clientSendsImageFilters = true; + } + comics[libraryId].push_back(info); + } else { hash = comicInfoProgress.at(2); currentPage = comicInfoProgress.at(3).toInt(); @@ -119,6 +150,13 @@ void SyncControllerV2::service(HttpRequest &request, HttpResponse &response) lastTimeOpened = comicInfoProgress.at(5).toULong(); info.lastTimeOpened = lastTimeOpened; + if (comicInfoProgress.length() >= 9) { // info includes image filters + info.lastTimeImageFiltersSet = comicInfoProgress.at(7); + info.imageFiltersJson = comicInfoProgress.at(8); + + clientSendsImageFilters = true; + } + comicsWithNoLibrary.push_back(info); } } @@ -127,13 +165,13 @@ void SyncControllerV2::service(HttpRequest &request, HttpResponse &response) QJsonArray items; if (!comics.isEmpty()) { - auto moreRecentComicsFound = DBHelper::updateFromRemoteClient(comics, clientSendsHasBeenOpened); + auto moreRecentComicsFound = DBHelper::updateFromRemoteClient(comics, clientSendsHasBeenOpened, clientSendsImageFilters); foreach (qulonglong libraryId, moreRecentComicsFound.keys()) { auto libraryUuid = DBHelper::getLibraries().getLibraryIdFromLegacyId(libraryId); foreach (ComicDB comic, moreRecentComicsFound[libraryId]) { - items.append(YACReaderServerDataHelper::comicToJSON(libraryId, libraryUuid, comic)); + items.append(YACReaderServerDataHelper::fullComicToJSON(libraryId, libraryUuid, comic)); } } }