Merge pull request #178 from jpirnay/feat-koreader-metadata

feat: Send optional document metadata with KOSync progress uploads (upstream pr 1820 by nperez0111)
This commit is contained in:
jpirnay
2026-05-06 23:18:38 +02:00
committed by GitHub
10 changed files with 78 additions and 7 deletions
+1
View File
@@ -170,6 +170,7 @@ STR_FILENAME: "Filename"
STR_BINARY: "Binary"
STR_MENU_KOSYNC_BEHAVIOR: "Sync Behavior"
STR_KO_SYNC_ON_BOOK_CLOSE: "Auto-Push on Book Close"
STR_SEND_METADATA: "Send Document Metadata"
STR_KO_AUTO_SYNC_SKIPPED: "Remote ahead, skipping"
STR_KO_LONGPRESS_HINT: "Hold Confirm to open with sync"
STR_SET_CREDENTIALS_FIRST: "Set credentials first"
@@ -175,3 +175,8 @@ void KOReaderCredentialStore::setMatchMethod(DocumentMatchMethod method) {
matchMethod = method;
LOG_DBG("KRS", "Set match method: %s", method == DocumentMatchMethod::FILENAME ? "Filename" : "Binary");
}
void KOReaderCredentialStore::setSendMetadata(bool value) {
sendMetadata = value;
LOG_DBG("KRS", "Send metadata: %s", value ? "enabled" : "disabled");
}
@@ -27,6 +27,7 @@ class KOReaderCredentialStore {
std::string password;
std::string serverUrl; // Custom sync server URL (empty = default)
DocumentMatchMethod matchMethod = DocumentMatchMethod::FILENAME; // Default to filename for compatibility
bool sendMetadata = false;
// Private constructor for singleton
KOReaderCredentialStore() = default;
@@ -72,6 +73,10 @@ class KOReaderCredentialStore {
// Document matching method
void setMatchMethod(DocumentMatchMethod method);
DocumentMatchMethod getMatchMethod() const { return matchMethod; }
// Send document metadata (filename, title, authors) with progress uploads
void setSendMetadata(bool value);
bool getSendMetadata() const { return sendMetadata; }
};
// Helper macro to access credential store
+7
View File
@@ -555,6 +555,13 @@ KOReaderSyncClient::Error KOReaderSyncClient::updateProgress(const KOReaderProgr
doc["device"] = DEVICE_NAME;
doc["device_id"] = DEVICE_ID;
if (progress.metadata) {
JsonObject meta = doc["metadata"].to<JsonObject>();
meta["filename"] = progress.metadata->filename;
meta["title"] = progress.metadata->title;
meta["authors"] = progress.metadata->authors;
}
std::string body;
serializeJson(doc, body);
+19 -6
View File
@@ -1,16 +1,29 @@
#pragma once
#include <optional>
#include <string>
/**
* Optional document metadata sent alongside progress uploads.
* Only populated when KOReaderCredentialStore::getSendMetadata() is true.
* The official sync server ignores this field; custom servers may use it.
*/
struct KOReaderMetadata {
std::string filename;
std::string title;
std::string authors;
};
/**
* Progress data from KOReader sync server.
*/
struct KOReaderProgress {
std::string document; // Document hash
std::string progress; // XPath-like progress string
float percentage; // Progress percentage (0.0 to 1.0)
std::string device; // Device name
std::string deviceId; // Device ID
int64_t timestamp; // Unix timestamp of last update
std::string document; // Document hash
std::string progress; // XPath-like progress string
float percentage; // Progress percentage (0.0 to 1.0)
std::string device; // Device name
std::string deviceId; // Device ID
int64_t timestamp; // Unix timestamp of last update
std::optional<KOReaderMetadata> metadata; // Optional document metadata
};
/**