mirror of
https://github.com/YACReader/yacreader
synced 2025-07-14 11:04:25 -04:00
Send back more recent comic status to the client on sync
This commit is contained in:
@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
#include "comic_db.h"
|
#include "comic_db.h"
|
||||||
#include "db_helper.h"
|
#include "db_helper.h"
|
||||||
|
#include "yacreader_server_data_helper.h"
|
||||||
|
|
||||||
using stefanfrings::HttpRequest;
|
using stefanfrings::HttpRequest;
|
||||||
using stefanfrings::HttpResponse;
|
using stefanfrings::HttpResponse;
|
||||||
@ -15,13 +16,13 @@ SyncControllerV2::SyncControllerV2()
|
|||||||
|
|
||||||
void SyncControllerV2::service(HttpRequest &request, HttpResponse &response)
|
void SyncControllerV2::service(HttpRequest &request, HttpResponse &response)
|
||||||
{
|
{
|
||||||
|
response.setHeader("Content-Type", "text/plain; charset=utf-8");
|
||||||
|
|
||||||
QString postData = QString::fromUtf8(request.getBody());
|
QString postData = QString::fromUtf8(request.getBody());
|
||||||
|
|
||||||
QLOG_TRACE() << "POST DATA: " << postData;
|
QLOG_TRACE() << "POST DATA: " << postData;
|
||||||
|
|
||||||
if (postData.length() > 0) {
|
if (postData.length() > 0) {
|
||||||
response.write("OK", true);
|
|
||||||
|
|
||||||
QList<QString> data = postData.split("\n");
|
QList<QString> data = postData.split("\n");
|
||||||
|
|
||||||
qulonglong libraryId;
|
qulonglong libraryId;
|
||||||
@ -35,7 +36,7 @@ void SyncControllerV2::service(HttpRequest &request, HttpResponse &response)
|
|||||||
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() >= 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();
|
||||||
@ -52,6 +53,11 @@ 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() >= 7) {
|
||||||
|
info.read = comicInfoProgress.at(6).toInt();
|
||||||
|
}
|
||||||
|
|
||||||
if (!comics.contains(libraryId)) {
|
if (!comics.contains(libraryId)) {
|
||||||
comics[libraryId] = QList<ComicInfo>();
|
comics[libraryId] = QList<ComicInfo>();
|
||||||
}
|
}
|
||||||
@ -75,11 +81,26 @@ void SyncControllerV2::service(HttpRequest &request, HttpResponse &response)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DBHelper::updateFromRemoteClient(comics);
|
auto moreRecentComicsFound = DBHelper::updateFromRemoteClient(comics);
|
||||||
|
|
||||||
|
QJsonArray items;
|
||||||
|
|
||||||
|
foreach (qulonglong libraryId, moreRecentComicsFound.keys()) {
|
||||||
|
foreach (ComicDB comic, moreRecentComicsFound[libraryId]) {
|
||||||
|
items.append(YACReaderServerDataHelper::comicToJSON(libraryId, comic));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QJsonDocument output(items);
|
||||||
|
|
||||||
|
response.write(output.toJson(QJsonDocument::Compact), true);
|
||||||
|
|
||||||
|
//TODO does it make sense to send these back? The source is not YACReaderLibrary...
|
||||||
DBHelper::updateFromRemoteClientWithHash(comicsWithNoLibrary);
|
DBHelper::updateFromRemoteClientWithHash(comicsWithNoLibrary);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
response.setStatus(412, "No comic info received");
|
response.setStatus(412, "No comic info received");
|
||||||
response.write("", true);
|
response.write("[]", true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user