feat(githubsync): add GitHub Sync plugin to sync epubs from a private GitHub repo on boot
This commit is contained in:
1 parent
e4f411dde5
commit
6abf076a3e
9 files changed
+963
-655
No files matched your search
@@ -0,0 +1,41 @@
|
||||
#pragma once
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <functional>
|
||||
#include <string>
|
||||
|
||||
struct GitHubSyncConfig {
|
||||
std::string username;
|
||||
std::string pat;
|
||||
std::string repo;
|
||||
std::string branch;
|
||||
};
|
||||
|
||||
enum class GitHubSyncResult {
|
||||
OK,
|
||||
NOT_CONFIGURED,
|
||||
NO_WIFI,
|
||||
AUTH_ERROR,
|
||||
REPO_NOT_FOUND,
|
||||
API_ERROR,
|
||||
SD_ERROR,
|
||||
PARSE_ERROR
|
||||
};
|
||||
|
||||
using GitHubSyncProgressCallback = std::function<void(const std::string &status)>;
|
||||
|
||||
class GitHubSync {
|
||||
public:
|
||||
static bool loadConfig(GitHubSyncConfig &cfg);
|
||||
static void saveConfig(const GitHubSyncConfig &cfg);
|
||||
static bool isConfigured();
|
||||
static GitHubSyncResult sync(GitHubSyncProgressCallback onProgress = nullptr);
|
||||
static const char* resultMessage(GitHubSyncResult r);
|
||||
|
||||
private:
|
||||
static bool fetchFileList(const GitHubSyncConfig &cfg, std::string &outJson, GitHubSyncResult &err);
|
||||
static bool downloadFile(const GitHubSyncConfig &cfg, const std::string &downloadUrl, const std::string &name, const std::string &sha, GitHubSyncResult &err, GitHubSyncProgressCallback onProgress);
|
||||
static std::string loadLocalSha(const std::string &filename);
|
||||
static void saveLocalSha(const std::string &filename, const std::string &sha);
|
||||
static std::string shaFilePath(const std::string &filename);
|
||||
};
|
||||
Reference in new issue
Block a user