Files
Crosspoint/lib/KOReaderSync/KOReaderSyncClient.h
T

77 lines
2.5 KiB
C++

#pragma once
#include <cstdint>
#include <optional>
#include <string>
/**
* Optional document metadata sent alongside progress sync requests.
* Mirrors the metadata object added in KOReader PR #15306.
* The official sync server ignores this field; custom servers may use it.
*/
struct KOReaderMetadata {
std::string filename; // e.g. "my_book.epub"
std::string title; // Document title from EPUB metadata
std::string authors; // Author(s) from EPUB metadata
};
/**
* 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::optional<KOReaderMetadata> metadata; // Optional document metadata
};
/**
* HTTP client for KOReader sync API.
*
* Base URL: https://sync.koreader.rocks:443/
*
* API Endpoints:
* GET /users/auth - Authenticate (validate credentials)
* GET /syncs/progress/:document - Get progress for a document
* PUT /syncs/progress - Update progress for a document
*
* Authentication:
* x-auth-user: username
* x-auth-key: MD5 hash of password
*/
class KOReaderSyncClient {
public:
enum Error { OK = 0, NO_CREDENTIALS, NETWORK_ERROR, AUTH_FAILED, SERVER_ERROR, JSON_ERROR, NOT_FOUND, LOW_MEMORY };
/**
* Authenticate with the sync server (validate credentials).
* @return OK on success, error code on failure
*/
static Error authenticate();
/**
* Get reading progress for a document.
* @param documentHash The document hash (from KOReaderDocumentId)
* @param outProgress Output: the progress data
* @return OK on success, NOT_FOUND if no progress exists, error code on failure
*/
static Error getProgress(const std::string& documentHash, KOReaderProgress& outProgress);
/**
* Update reading progress for a document.
* @param progress The progress data to upload
* @return OK on success, error code on failure
*/
static Error updateProgress(const KOReaderProgress& progress);
/**
* Get human-readable error message.
*/
static const char* errorString(Error error);
/** HTTP status code from the last request (for diagnostics). */
static int lastHttpCode;
};