初步实现功能
This commit is contained in:
1 parent
f23c6a3fbb
commit
f0b6efb126
15 files changed
+783
-708
No files matched your search
@@ -15,9 +15,14 @@ namespace seafile::fs
|
||||
DIRECTORY,
|
||||
};
|
||||
|
||||
|
||||
/// 仓库 id
|
||||
std::string repo_id;
|
||||
std::string path;
|
||||
|
||||
/// 仓库内绝对路径(如 /folder/file.txt)
|
||||
std::string repo_path;
|
||||
|
||||
/// 虚拟全路径(如 /repo-name/folder/file.txt)
|
||||
std::string full_path;
|
||||
|
||||
Type type;
|
||||
|
||||
|
||||
@@ -4,38 +4,34 @@
|
||||
|
||||
#ifndef SEADISK_SEAFILE_FILE_SYSTEM_HPP
|
||||
#define SEADISK_SEAFILE_FILE_SYSTEM_HPP
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <winfsp/winfsp.h>
|
||||
|
||||
#include "seafile/api/seafile_api.hpp"
|
||||
#include "seafile/api/token_type.hpp"
|
||||
#include "seafile/api/cached_seafile_api.hpp"
|
||||
#include "seafile/cache/cache.hpp"
|
||||
#include "seafile/fs/seafile_store.hpp"
|
||||
#include "seafile/fs/storage/repo_entry.hpp"
|
||||
#include "seafile/fs/storage/repo_info.hpp"
|
||||
|
||||
namespace seafile::fs
|
||||
{
|
||||
class SeafileFileSystem final
|
||||
{
|
||||
using SeafileException = api::SeafileException;
|
||||
using TokenType = api::TokenType;
|
||||
using ISeaFileApi = api::ISeaFileApi;
|
||||
using RepoEntry = api::RepoEntry;
|
||||
using RepoInfo = storage::RepoInfo;
|
||||
using RepoEntry = storage::RepoEntry;
|
||||
|
||||
|
||||
std::string repo_id;
|
||||
std::shared_ptr<ISeaFileApi> api;
|
||||
std::unique_ptr<SeafileStore> store;
|
||||
std::wstring volume_label;
|
||||
|
||||
public:
|
||||
explicit SeafileFileSystem(const std::string& server,
|
||||
const std::wstring& volume_label) : volume_label(volume_label)
|
||||
explicit SeafileFileSystem(std::unique_ptr<SeafileStore> store,
|
||||
const std::wstring& volume_label)
|
||||
: store(std::move(store)), volume_label(volume_label)
|
||||
{
|
||||
this->api = std::make_shared<api::CachedSeafileApi>(
|
||||
std::make_shared<api::SeaFileApi>(server)
|
||||
);
|
||||
}
|
||||
|
||||
tl::expected<void, SeafileException> initialize(const std::string& username, const std::string& password);
|
||||
tl::expected<void, SeafileException> initialize();
|
||||
|
||||
SeafileFileSystem(const SeafileFileSystem&) = delete;
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <sqlite_orm/sqlite_orm.h>
|
||||
|
||||
#include "storage/repo_entry.hpp"
|
||||
#include "storage/repo_info.hpp"
|
||||
|
||||
namespace seafile::fs
|
||||
{
|
||||
@@ -40,20 +41,41 @@ namespace seafile::fs
|
||||
/// 检查是否需要更新元素据,如果需要同步则自动同步
|
||||
tl::expected<void, api::SeafileException> checkAndSync(const std::string& repo_id);
|
||||
|
||||
/// 同步元数据
|
||||
[[nodiscard]] tl::expected<void, api::SeafileException> syncRepoEntry(const std::string& repo_id) const;
|
||||
/// 返回路径的信息
|
||||
/// @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;
|
||||
|
||||
/// 同步用户信息
|
||||
tl::expected<void, api::SeafileException> syncUserInfo();
|
||||
[[nodiscard]] tl::expected<void, api::SeafileException> syncUserInfo();
|
||||
|
||||
/// 同步repo信息
|
||||
tl::expected<void, api::SeafileException> syncRepos();
|
||||
[[nodiscard]] tl::expected<std::vector<storage::RepoInfo>, api::SeafileException> syncRepos();
|
||||
|
||||
/// 同步
|
||||
tl::expected<void, api::SeafileException> sync();
|
||||
|
||||
static std::filesystem::path storePath() ;
|
||||
[[nodiscard]] tl::expected<void, api::SeafileException> sync();
|
||||
|
||||
static std::filesystem::path storePath();
|
||||
|
||||
/// 获取路径信息
|
||||
/// @param path 路径
|
||||
@@ -62,6 +84,14 @@ namespace seafile::fs
|
||||
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);
|
||||
|
||||
std::vector<storage::RepoEntry> queryDirectChildren(
|
||||
const std::string& repo_id, const std::string& parent_path);
|
||||
|
||||
struct Database;
|
||||
std::unique_ptr<Database> database;
|
||||
std::string api_server;
|
||||
|
||||
@@ -59,7 +59,7 @@ namespace seafile::fs::storage
|
||||
/// Whether the entry is starred by the current user.
|
||||
std::optional<bool> starred{};
|
||||
|
||||
static auto from_api_model(const std::string& repo_id, const std::string& path,
|
||||
static auto from_api_model(const std::string& repo_id, const std::string& parent_path,
|
||||
const api::RepoEntry& entry) -> RepoEntry;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
//
|
||||
// Created by Shell on 2026/7/30.
|
||||
//
|
||||
|
||||
#ifndef SEADISK_STORAGE_REPO_INFO_HPP
|
||||
#define SEADISK_STORAGE_REPO_INFO_HPP
|
||||
#include <string>
|
||||
|
||||
#include "seafile/api/repo_info.hpp"
|
||||
|
||||
namespace seafile::fs::storage {
|
||||
/**
|
||||
*@brief Seafile repository metadata.
|
||||
*/
|
||||
struct RepoInfo final {
|
||||
/// Object type, usually "repo".
|
||||
std::string type;
|
||||
|
||||
/// Repository UUID.
|
||||
std::string id;
|
||||
|
||||
/// Repository owner identifier.
|
||||
std::string owner;
|
||||
|
||||
/// Repository name.
|
||||
std::string name;
|
||||
|
||||
/// Last modification time (Unix timestamp, seconds).
|
||||
std::int64_t mtime{};
|
||||
|
||||
/// Repository size in bytes.
|
||||
std::uint64_t size{};
|
||||
|
||||
/// Indicates whether the repository is encrypted.
|
||||
bool encrypted{};
|
||||
|
||||
/// Root directory object ID.
|
||||
std::string root;
|
||||
|
||||
/// Current user's permission (e.g. "r", "rw").
|
||||
std::string permission;
|
||||
|
||||
/// Internal email address of the last modifier.
|
||||
std::string modifier_email;
|
||||
|
||||
/// Contact email address of the last modifier.
|
||||
std::string modifier_contact_email;
|
||||
|
||||
/// Display name of the last modifier.
|
||||
std::string modifier_name;
|
||||
|
||||
/// Total number of files in the repository.
|
||||
std::uint64_t file_count{};
|
||||
|
||||
/// Head commit identifier.
|
||||
std::string head_commit_id;
|
||||
|
||||
/// Repository encryption version.
|
||||
int enc_version{};
|
||||
|
||||
/// Encryption salt.
|
||||
std::string salt;
|
||||
|
||||
/// Encryption magic value.
|
||||
std::string magic;
|
||||
|
||||
/// Repository random key.
|
||||
std::string random_key;
|
||||
|
||||
static auto from_api_model(const api::RepoInfo& repo_info) -> RepoInfo;
|
||||
};
|
||||
}
|
||||
#endif //SEADISK_STORAGE_REPO_INFO_HPP
|
||||
Reference in new issue
Block a user