42 lines
1.3 KiB
C++
42 lines
1.3 KiB
C++
#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);
|
|
};
|