60 lines
1.7 KiB
C
60 lines
1.7 KiB
C
|
|
#pragma once
|
||
|
|
#include <string>
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 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
|
||
|
|
};
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 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 };
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 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);
|
||
|
|
};
|