Send optional document metadata with KOSync progress uploads
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user