添加文件缓存

This commit is contained in:
asypost committed 2026-07-14 21:28:08 +08:00
1 parent fb63205a70
commit 95b68b9542
18 files changed
+481 -107

No files matched your search

+13 -12
View File
@@ -20,11 +20,12 @@
#include "file_info.hpp"
#include "repo_entry.hpp"
#include "repo_info.hpp"
#include "seafile_api_interface.hpp"
#include "server_info.hpp"
#include "token_type.hpp"
namespace seafile {
class SeaFileApi final {
namespace seafile::api {
class SeaFileApi final:public ISeaFileApi {
//base url of the seafile api server
std::string base_url;
@@ -104,7 +105,7 @@ namespace seafile {
* @return token when success else SeafileException
*/
tl::expected<AuthToken, SeafileException>
authToken(const std::string &username, const std::string &password) {
authToken(const std::string &username, const std::string &password) override {
const nlohmann::json body = {
{"username", username},
{"password", password}
@@ -113,7 +114,7 @@ namespace seafile {
}
tl::expected<ServerInfo, SeafileException>
serverInfo() const {
serverInfo() const override{
const auto response = cpr::Get(
cpr::Url{makeUrl("/api2/server-info/")},
cpr::Header{
@@ -130,7 +131,7 @@ namespace seafile {
* @return default repo info
*/
tl::expected<DefaultRepo, SeafileException>
defaultRepo(const std::string &token, const TokenType token_type) const {
defaultRepo(const std::string &token, const TokenType token_type) const override{
const auto auth = makeAuthToken(token, token_type);
const auto url = makeUrl("/api2/default-repo/");
const auto response = cpr::Get(cpr::Url{url},
@@ -142,7 +143,7 @@ namespace seafile {
}
tl::expected<RepoInfo, SeafileException>
repoInfo(const std::string &repo_id, const std::string &token, const TokenType token_type) const {
repoInfo(const std::string &repo_id, const std::string &token, const TokenType token_type) const override{
const auto url = makeUrl(std::format("/api2/repos/{}/", repo_id));
const auto auth = makeAuthToken(token, token_type);
@@ -164,7 +165,7 @@ namespace seafile {
*/
tl::expected<std::vector<RepoEntry>, SeafileException>
repoDir(const std::string &repo_id, const std::string &path, const std::string &token,
const TokenType token_type) const {
const TokenType token_type) const override{
const auto url = cpr::Url{makeUrl(std::format("/api2/repos/{}/dir/", repo_id))};
const auto auth = makeAuthToken(token, token_type);
@@ -181,7 +182,7 @@ namespace seafile {
tl::expected<AccountInfo, SeafileException>
accountInfo(const std::string &token,
const TokenType token_type) const {
const TokenType token_type) const override{
const auto url = cpr::Url{makeUrl("/api2/account/info/")};
const auto auth = makeAuthToken(token, token_type);
@@ -195,7 +196,7 @@ namespace seafile {
tl::expected<FileInfo, SeafileException>
fileDetail(const std::string &repo_id, const std::string &path, const std::string &token,
const TokenType token_type) const {
const TokenType token_type) const override{
const auto url = cpr::Url{makeUrl(std::format("/api2/repos/{}/file/detail/", repo_id))};
const auto auth = makeAuthToken(token, token_type);
@@ -211,7 +212,7 @@ namespace seafile {
tl::expected<std::string, SeafileException>
downloadFileUrl(const std::string &repo_id, const std::string &path, const std::string &token,
const TokenType token_type) const {
const TokenType token_type) const override{
const auto auth = makeAuthToken(token, token_type);
const auto url = cpr::Url{makeUrl(std::format("/api2/repos/{}/file/", repo_id))};
const auto response = cpr::Get(url,
@@ -231,7 +232,7 @@ namespace seafile {
const std::optional<size_t> start,
const std::optional<size_t> end,
const std::string &token,
const TokenType token_type) const {
const TokenType token_type) const override{
if (auto download_url = downloadFileUrl(repo_id, path, token, token_type); download_url.has_value()) {
const auto auth = makeAuthToken(token, token_type);
const auto url = cpr::Url{download_url.value()};
@@ -255,7 +256,7 @@ namespace seafile {
}
tl::expected<DirInfo, SeafileException> dirDetail(const std::string &repo_id, const std::string &path,
const std::string &token, const TokenType token_type) const {
const std::string &token, const TokenType token_type) const override{
const auto auth = makeAuthToken(token, token_type);
const auto url = cpr::Url{makeUrl(std::format("/api/v2.1/repos/{}/dir/detail/", repo_id))};
const auto response = cpr::Get(url, cpr::Header{