mirror of
https://github.com/YACReader/yacreader
synced 2025-06-04 01:28:55 -04:00
Update the sync controller for new clients
This commit is contained in:
parent
04f0d22563
commit
a4f36396f5
@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
#include "comic_db.h"
|
#include "comic_db.h"
|
||||||
#include "db_helper.h"
|
#include "db_helper.h"
|
||||||
|
#include "yacreader_libraries.h"
|
||||||
#include "yacreader_server_data_helper.h"
|
#include "yacreader_server_data_helper.h"
|
||||||
|
|
||||||
using stefanfrings::HttpRequest;
|
using stefanfrings::HttpRequest;
|
||||||
@ -33,10 +34,46 @@ void SyncControllerV2::service(HttpRequest &request, HttpResponse &response)
|
|||||||
QString hash;
|
QString hash;
|
||||||
QMap<qulonglong, QList<ComicInfo>> comics;
|
QMap<qulonglong, QList<ComicInfo>> comics;
|
||||||
QList<ComicInfo> comicsWithNoLibrary;
|
QList<ComicInfo> comicsWithNoLibrary;
|
||||||
|
|
||||||
|
auto libraries = DBHelper::getLibraries();
|
||||||
|
|
||||||
foreach (QString comicInfo, data) {
|
foreach (QString comicInfo, data) {
|
||||||
QList<QString> comicInfoProgress = comicInfo.split("\t");
|
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") {
|
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();
|
||||||
@ -81,13 +118,17 @@ void SyncControllerV2::service(HttpRequest &request, HttpResponse &response)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto moreRecentComicsFound = DBHelper::updateFromRemoteClient(comics);
|
|
||||||
|
|
||||||
QJsonArray items;
|
QJsonArray items;
|
||||||
|
|
||||||
foreach (qulonglong libraryId, moreRecentComicsFound.keys()) {
|
if (!comics.isEmpty()) {
|
||||||
foreach (ComicDB comic, moreRecentComicsFound[libraryId]) {
|
auto moreRecentComicsFound = DBHelper::updateFromRemoteClient(comics);
|
||||||
items.append(YACReaderServerDataHelper::comicToJSON(libraryId, comic));
|
|
||||||
|
foreach (qulonglong libraryId, moreRecentComicsFound.keys()) {
|
||||||
|
auto libraryUuid = DBHelper::getLibraries().getLibraryIdFromLegacyId(libraryId);
|
||||||
|
|
||||||
|
foreach (ComicDB comic, moreRecentComicsFound[libraryId]) {
|
||||||
|
items.append(YACReaderServerDataHelper::comicToJSON(libraryId, libraryUuid, comic));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user