From f0c5de374eb0c61b48ffa4e4aa70db82c03ecc3f Mon Sep 17 00:00:00 2001 From: shell Date: Tue, 21 Jul 2026 22:49:56 +0800 Subject: [PATCH] clean seafile api --- include/seafile/fs/file_context.hpp | 4 ---- include/seafile/util/version.hpp | 27 ++++++++++++----------- src/seafile/fs/seafile_file_system.cpp | 7 +++--- src/seafile/util/version.cpp | 30 +++++++++++--------------- 4 files changed, 30 insertions(+), 38 deletions(-) diff --git a/include/seafile/fs/file_context.hpp b/include/seafile/fs/file_context.hpp index b091ade..ef68991 100644 --- a/include/seafile/fs/file_context.hpp +++ b/include/seafile/fs/file_context.hpp @@ -22,10 +22,6 @@ namespace seafile::fs Type type; uint64_t size{}; - - std::string download_url; - - }; } diff --git a/include/seafile/util/version.hpp b/include/seafile/util/version.hpp index 511d6bd..9dc1565 100644 --- a/include/seafile/util/version.hpp +++ b/include/seafile/util/version.hpp @@ -6,10 +6,9 @@ #define SEADISK_VERSION_HPP #include #include +#include -namespace seafile::util -{ - +namespace seafile::util { /** * @brief Semantic version parser. * @@ -18,12 +17,19 @@ namespace seafile::util * 10.0 * 10.0.2 */ - class Version final - { + class Version final { public: Version() = default; - explicit Version(const std::string& version); + explicit Version(const std::string &version); + + Version(const Version &) = default; + + Version(Version &&) noexcept = default; + + Version &operator=(const Version &) = default; + + Version &operator=(Version &&) noexcept = default; [[nodiscard]] int major() const noexcept; @@ -37,19 +43,14 @@ namespace seafile::util [[nodiscard]] std::string toString() const; - bool operator==(const Version& other) const; - - bool operator<(const Version& other) const; - + std::strong_ordering operator<=>(const Version &other) const; private: - void parse(const std::string& version); + void parse(const std::string &version); - private: int major_{0}; std::optional minor_; std::optional patch_; }; - } #endif //SEADISK_VERSION_HPP diff --git a/src/seafile/fs/seafile_file_system.cpp b/src/seafile/fs/seafile_file_system.cpp index f25cfe7..911b36b 100644 --- a/src/seafile/fs/seafile_file_system.cpp +++ b/src/seafile/fs/seafile_file_system.cpp @@ -54,7 +54,6 @@ namespace seafile::fs const auto authToken = api->auth(username, password); if (authToken.has_value()) { - this->token = authToken.value().token; if (const auto repo = api->defaultRepo(); repo.has_value()) { this->repo_id = repo.value().repo_id.value_or(""); @@ -140,7 +139,7 @@ namespace seafile::fs auto repo = api->repoInfo(repo_id); if (!repo.has_value()) return STATUS_OBJECT_NAME_NOT_FOUND; - const auto ctx = new SeaFileContext{repo->id, path, SeaFileContext::Type::DIRECTORY, 0, ""}; + const auto ctx = new SeaFileContext{repo->id, path, SeaFileContext::Type::DIRECTORY, 0}; *PFileContext = ctx; SetFileInfo(FileInfo, FILE_ATTRIBUTE_DIRECTORY, repo->size, repo->mtime); spdlog::info(std::format("open directory {} success", path)); @@ -150,7 +149,7 @@ namespace seafile::fs if (const auto dirInfo = api->dirDetail(repo_id, path); dirInfo.has_value()) { const auto& info = dirInfo.value(); - const auto ctx = new SeaFileContext{info.repo_id, info.path, SeaFileContext::Type::DIRECTORY, 0, ""}; + const auto ctx = new SeaFileContext{info.repo_id, info.path, SeaFileContext::Type::DIRECTORY, 0}; *PFileContext = ctx; SetFileInfo(FileInfo,FILE_ATTRIBUTE_DIRECTORY, 0, 0); spdlog::info(std::format("open directory {} success", path)); @@ -161,7 +160,7 @@ namespace seafile::fs if (const auto fileInfo = api->fileDetail(repo_id, path); fileInfo.has_value()) { const auto& info = fileInfo.value(); - const auto ctx = new SeaFileContext(repo_id, path, SeaFileContext::Type::FILE, info.size, ""); + const auto ctx = new SeaFileContext(repo_id, path, SeaFileContext::Type::FILE, info.size); *PFileContext = ctx; SetFileInfo(FileInfo,FILE_ATTRIBUTE_ARCHIVE, info.size, 0); spdlog::info(std::format("open file {} success", path)); diff --git a/src/seafile/util/version.cpp b/src/seafile/util/version.cpp index 2a42cbc..9b9a36f 100644 --- a/src/seafile/util/version.cpp +++ b/src/seafile/util/version.cpp @@ -7,6 +7,7 @@ #include #include #include +#include namespace seafile::util { Version::Version(const std::string &version) { @@ -43,23 +44,18 @@ namespace seafile::util { return result; } - bool Version::operator==(const Version &other) const { - return major_ == other.major_ - && minor().value_or(0) == other.minor().value_or(0) - && patch().value_or(0) == other.patch().value_or(0); - } - - - bool Version::operator<(const Version &other) const { - if (major_ != other.major_) { - return major_ < other.major_; - } - - if (minor().value_or(0) != other.minor().value_or(0)) { - return minor().value_or(0) < other.minor().value_or(0); - } - - return patch().value_or(0) < other.patch().value_or(0); + std::strong_ordering Version::operator<=>(const Version &other) const { + const auto lhs = std::tuple{ + major(), + minor().value_or(0), + patch().value_or(0) + }; + const auto rhs = std::tuple{ + other.major(), + other.minor().value_or(0), + other.patch().value_or(0) + }; + return lhs <=> rhs; }