Support image filters on syncback from ios and android clients

This commit is contained in:
luisangelsm
2025-11-19 18:10:02 +01:00
parent 14ad6f3a2d
commit b94dc7fcf5
3 changed files with 92 additions and 37 deletions

View File

@ -1084,7 +1084,7 @@ void DBHelper::updateFromRemoteClient(qulonglong libraryId, const ComicInfo &com
QSqlDatabase::removeDatabase(connectionName); QSqlDatabase::removeDatabase(connectionName);
} }
QMap<qulonglong, QList<ComicDB>> DBHelper::updateFromRemoteClient(const QMap<qulonglong, QList<ComicInfo>> &comics, bool clientSendsHasBeenOpened) QMap<qulonglong, QList<ComicDB>> DBHelper::updateFromRemoteClient(const QMap<qulonglong, QList<ComicInfo>> &comics, bool clientSendsHasBeenOpened, bool clientSendsImageFilters)
{ {
QMap<qulonglong, QList<ComicDB>> moreRecentComics; QMap<qulonglong, QList<ComicDB>> moreRecentComics;
@ -1105,7 +1105,9 @@ QMap<qulonglong, QList<ComicDB>> DBHelper::updateFromRemoteClient(const QMap<qul
"currentPage = :currentPage, " "currentPage = :currentPage, "
"hasBeenOpened = :hasBeenOpened, " "hasBeenOpened = :hasBeenOpened, "
"lastTimeOpened = :lastTimeOpened, " "lastTimeOpened = :lastTimeOpened, "
"rating = :rating" "rating = :rating, "
"imageFiltersJson = :imageFiltersJson, "
"lastTimeImageFiltersSet = :lastTimeImageFiltersSet "
" WHERE id = :id "); " WHERE id = :id ");
foreach (ComicInfo comicInfo, comics[libraryId]) { foreach (ComicInfo comicInfo, comics[libraryId]) {
@ -1129,6 +1131,12 @@ QMap<qulonglong, QList<ComicDB>> DBHelper::updateFromRemoteClient(const QMap<qul
isMoreRecent = true; isMoreRecent = true;
} }
if (clientSendsImageFilters) {
if (comic.info.lastTimeImageFiltersSet.toULongLong() > comicInfo.lastTimeImageFiltersSet.toULongLong()) {
isMoreRecent = true;
}
}
comic.info.currentPage = qMax(comic.info.currentPage, comicInfo.currentPage); comic.info.currentPage = qMax(comic.info.currentPage, comicInfo.currentPage);
if (comic.info.currentPage == comic.info.numPages) if (comic.info.currentPage == comic.info.numPages)
@ -1148,12 +1156,21 @@ QMap<qulonglong, QList<ComicDB>> DBHelper::updateFromRemoteClient(const QMap<qul
if (comicInfo.rating > 0) if (comicInfo.rating > 0)
comic.info.rating = comicInfo.rating; 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(":read", comic.info.read ? 1 : 0);
updateComicInfo.bindValue(":currentPage", comic.info.currentPage); updateComicInfo.bindValue(":currentPage", comic.info.currentPage);
updateComicInfo.bindValue(":hasBeenOpened", comic.info.hasBeenOpened ? 1 : 0); updateComicInfo.bindValue(":hasBeenOpened", comic.info.hasBeenOpened ? 1 : 0);
updateComicInfo.bindValue(":lastTimeOpened", comic.info.lastTimeOpened); updateComicInfo.bindValue(":lastTimeOpened", comic.info.lastTimeOpened);
updateComicInfo.bindValue(":id", comic.info.id); updateComicInfo.bindValue(":id", comic.info.id);
updateComicInfo.bindValue(":rating", comic.info.rating); updateComicInfo.bindValue(":rating", comic.info.rating);
updateComicInfo.bindValue(":imageFiltersJson", comic.info.imageFiltersJson);
updateComicInfo.bindValue(":lastTimeImageFiltersSet", comic.info.lastTimeImageFiltersSet);
updateComicInfo.exec(); updateComicInfo.exec();
if (isMoreRecent) { if (isMoreRecent) {

View File

@ -76,7 +76,7 @@ public:
static void setComicAsReading(qulonglong libraryId, const ComicInfo &comicInfo); static void setComicAsReading(qulonglong libraryId, const ComicInfo &comicInfo);
[[deprecated("Server v1")]] static void updateFromRemoteClient(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 void updateReadingRemoteProgress(const ComicInfo &comicInfo, QSqlDatabase &db);
static QMap<qulonglong, QList<ComicDB>> updateFromRemoteClient(const QMap<qulonglong, QList<ComicInfo>> &comics, bool clientSendsHasBeenOpened); static QMap<qulonglong, QList<ComicDB>> updateFromRemoteClient(const QMap<qulonglong, QList<ComicInfo>> &comics, bool clientSendsHasBeenOpened, bool clientSendsImageFilters);
static void updateFromRemoteClientWithHash(const QList<ComicInfo> &comics); static void updateFromRemoteClientWithHash(const QList<ComicInfo> &comics);
static void renameLabel(qulonglong id, const QString &name, QSqlDatabase &db); static void renameLabel(qulonglong id, const QString &name, QSqlDatabase &db);
static void renameList(qulonglong id, const QString &name, QSqlDatabase &db); static void renameList(qulonglong id, const QString &name, QSqlDatabase &db);

View File

@ -38,48 +38,70 @@ void SyncControllerV2::service(HttpRequest &request, HttpResponse &response)
auto libraries = DBHelper::getLibraries(); auto libraries = DBHelper::getLibraries();
bool clientSendsHasBeenOpened = false; bool clientSendsHasBeenOpened = false;
bool clientSendsImageFilters = false;
foreach (QString comicInfo, data) { foreach (QString comicInfo, data) {
if (comicInfo.isEmpty()) {
continue;
}
QList<QString> comicInfoProgress = comicInfo.split("\t"); QList<QString> comicInfoProgress = comicInfo.split("\t");
if (comicInfoProgress.length() >= 9) { if (comicInfoProgress.isEmpty()) {
if (comicInfoProgress.at(0) != "u") { continue;
}
if (comicInfoProgress.at(0) == "u") { // Android
clientSendsHasBeenOpened = true;
if (comicInfoProgress.length() < 9) {
continue; continue;
} }
clientSendsHasBeenOpened = true;
auto libraryUuid = QUuid(comicInfoProgress.at(1)); 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; if (libraryUuid.isNull()) {
info.currentPage = currentPage; continue;
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<ComicInfo>();
}
comics[libraryId].push_back(info);
} }
} 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<ComicInfo>();
}
comics[libraryId].push_back(info);
} else { // iOS
if (comicInfoProgress.length() < 6) {
continue;
}
if (comicInfoProgress.at(0) != "unknown") { if (comicInfoProgress.at(0) != "unknown") {
libraryId = comicInfoProgress.at(0).toULongLong(); libraryId = comicInfoProgress.at(0).toULongLong();
comicId = comicInfoProgress.at(1).toULongLong(); comicId = comicInfoProgress.at(1).toULongLong();
@ -104,7 +126,16 @@ void SyncControllerV2::service(HttpRequest &request, HttpResponse &response)
if (!comics.contains(libraryId)) { if (!comics.contains(libraryId)) {
comics[libraryId] = QList<ComicInfo>(); comics[libraryId] = QList<ComicInfo>();
} }
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); comics[libraryId].push_back(info);
} else { } else {
hash = comicInfoProgress.at(2); hash = comicInfoProgress.at(2);
currentPage = comicInfoProgress.at(3).toInt(); currentPage = comicInfoProgress.at(3).toInt();
@ -119,6 +150,13 @@ void SyncControllerV2::service(HttpRequest &request, HttpResponse &response)
lastTimeOpened = comicInfoProgress.at(5).toULong(); lastTimeOpened = comicInfoProgress.at(5).toULong();
info.lastTimeOpened = lastTimeOpened; 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); comicsWithNoLibrary.push_back(info);
} }
} }
@ -127,13 +165,13 @@ void SyncControllerV2::service(HttpRequest &request, HttpResponse &response)
QJsonArray items; QJsonArray items;
if (!comics.isEmpty()) { if (!comics.isEmpty()) {
auto moreRecentComicsFound = DBHelper::updateFromRemoteClient(comics, clientSendsHasBeenOpened); auto moreRecentComicsFound = DBHelper::updateFromRemoteClient(comics, clientSendsHasBeenOpened, clientSendsImageFilters);
foreach (qulonglong libraryId, moreRecentComicsFound.keys()) { foreach (qulonglong libraryId, moreRecentComicsFound.keys()) {
auto libraryUuid = DBHelper::getLibraries().getLibraryIdFromLegacyId(libraryId); auto libraryUuid = DBHelper::getLibraries().getLibraryIdFromLegacyId(libraryId);
foreach (ComicDB comic, moreRecentComicsFound[libraryId]) { foreach (ComicDB comic, moreRecentComicsFound[libraryId]) {
items.append(YACReaderServerDataHelper::comicToJSON(libraryId, libraryUuid, comic)); items.append(YACReaderServerDataHelper::fullComicToJSON(libraryId, libraryUuid, comic));
} }
} }
} }