104 lines
3.8 KiB
C++
104 lines
3.8 KiB
C++
//
|
|
// Created by Shell on 2026/7/16.
|
|
//
|
|
|
|
#ifndef SEADISK_SEAFILE_STORE_HPP
|
|
#define SEADISK_SEAFILE_STORE_HPP
|
|
#include "seafile/api/seafile_api.hpp"
|
|
#include <sqlite_orm/sqlite_orm.h>
|
|
|
|
#include "storage/repo_entry.hpp"
|
|
#include "storage/repo_info.hpp"
|
|
|
|
namespace seafile::fs
|
|
{
|
|
class SeafileStore final
|
|
{
|
|
public:
|
|
/// construction
|
|
/// @param db_path database file path
|
|
/// @param server the server url of seafile
|
|
/// @param user user
|
|
/// @param password password
|
|
SeafileStore(const std::string& db_path, const std::string& server, const std::string& user,
|
|
const std::string& password);
|
|
|
|
SeafileStore(const SeafileStore&) = delete;
|
|
|
|
~SeafileStore();
|
|
|
|
tl::expected<void, api::SeafileException> auth();
|
|
|
|
///初始化数据库信息
|
|
[[nodiscard]] tl::expected<void, api::SeafileException> init();
|
|
|
|
/// 检查是否已经更新到最新
|
|
/// @return true 已经最新,false 需要更新
|
|
tl::expected<bool, api::SeafileException> checkIsUpdated(const std::string& repo_id);
|
|
|
|
/// 检查是否需要更新元素据,如果需要同步则自动同步
|
|
tl::expected<void, api::SeafileException> checkAndSync(const std::string& repo_id);
|
|
|
|
/// 返回路径的信息
|
|
/// @param path 需要查询的路径
|
|
/// @return 路径信息
|
|
[[nodiscard]] tl::expected<std::variant<storage::RepoInfo, storage::RepoEntry>, api::SeafileException> pathInfo(
|
|
const std::string& path);
|
|
|
|
/// 返回路径下面的子项目信息
|
|
/// @param path 路径
|
|
/// @return 子项目信息
|
|
[[nodiscard]] tl::expected<std::variant<std::vector<storage::RepoInfo>, std::vector<storage::RepoEntry>>,
|
|
api::SeafileException> listDir(const std::string& path);
|
|
|
|
/// 读取文件内容
|
|
/// @param repo_id 仓库 id
|
|
/// @param path 仓库内绝对路径
|
|
/// @param offset 起始偏移
|
|
/// @param length 读取长度
|
|
/// @return 文件内容
|
|
[[nodiscard]] tl::expected<std::string, api::SeafileException> readFile(
|
|
const std::string& repo_id, const std::string& path, size_t offset, size_t length) const;
|
|
|
|
/// 获取已缓存的账号信息(用于卷大小)
|
|
/// @return 账号信息
|
|
[[nodiscard]] tl::expected<api::AccountInfo, api::SeafileException> accountInfo() const;
|
|
|
|
/// 同步用户信息
|
|
[[nodiscard]] tl::expected<void, api::SeafileException> syncUserInfo() const;
|
|
|
|
/// 同步repo信息
|
|
[[nodiscard]] tl::expected<std::vector<storage::RepoInfo>, api::SeafileException> syncRepos();
|
|
|
|
/// 同步
|
|
[[nodiscard]] tl::expected<void, api::SeafileException> sync();
|
|
|
|
static std::filesystem::path storePath();
|
|
|
|
/// 获取路径信息
|
|
/// @param repo_id repo id
|
|
/// @param path 路径
|
|
/// @return 路径信息
|
|
tl::expected<storage::RepoEntry, api::SeafileException> findRepoEntry(
|
|
const std::string& repo_id, const std::string& path);
|
|
|
|
private:
|
|
tl::expected<storage::RepoInfo, api::SeafileException> findRepoByName(const std::string& name);
|
|
|
|
tl::expected<void, api::SeafileException> fetchAndStoreRepoDir(
|
|
const std::string& repo_id, const std::string& parent_path) const;
|
|
|
|
std::vector<storage::RepoEntry> queryDirectoryChildren(
|
|
const std::string& repo_id, const std::string& parent_path);
|
|
|
|
class Database;
|
|
std::unique_ptr<Database> database;
|
|
std::string api_server;
|
|
std::string username;
|
|
std::string password;
|
|
api::SeaFileApi api;
|
|
};
|
|
}
|
|
|
|
#endif //SEADISK_SEAFILE_STORE_HPP
|