clean seafile api

This commit is contained in:
shell committed 2026-07-21 22:49:56 +08:00
1 parent 3e4694ceb5
commit f0c5de374e
4 files changed
+30 -38

No files matched your search

-4
View File
@@ -22,10 +22,6 @@ namespace seafile::fs
Type type; Type type;
uint64_t size{}; uint64_t size{};
std::string download_url;
}; };
} }
+14 -13
View File
@@ -6,10 +6,9 @@
#define SEADISK_VERSION_HPP #define SEADISK_VERSION_HPP
#include <string> #include <string>
#include <optional> #include <optional>
#include <compare>
namespace seafile::util namespace seafile::util {
{
/** /**
* @brief Semantic version parser. * @brief Semantic version parser.
* *
@@ -18,12 +17,19 @@ namespace seafile::util
* 10.0 * 10.0
* 10.0.2 * 10.0.2
*/ */
class Version final class Version final {
{
public: public:
Version() = default; 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]] [[nodiscard]]
int major() const noexcept; int major() const noexcept;
@@ -37,19 +43,14 @@ namespace seafile::util
[[nodiscard]] [[nodiscard]]
std::string toString() const; std::string toString() const;
bool operator==(const Version& other) const; std::strong_ordering operator<=>(const Version &other) const;
bool operator<(const Version& other) const;
private: private:
void parse(const std::string& version); void parse(const std::string &version);
private:
int major_{0}; int major_{0};
std::optional<int> minor_; std::optional<int> minor_;
std::optional<int> patch_; std::optional<int> patch_;
}; };
} }
#endif //SEADISK_VERSION_HPP #endif //SEADISK_VERSION_HPP
+3 -4
View File
@@ -54,7 +54,6 @@ namespace seafile::fs
const auto authToken = api->auth(username, password); const auto authToken = api->auth(username, password);
if (authToken.has_value()) if (authToken.has_value())
{ {
this->token = authToken.value().token;
if (const auto repo = api->defaultRepo(); repo.has_value()) if (const auto repo = api->defaultRepo(); repo.has_value())
{ {
this->repo_id = repo.value().repo_id.value_or(""); this->repo_id = repo.value().repo_id.value_or("");
@@ -140,7 +139,7 @@ namespace seafile::fs
auto repo = api->repoInfo(repo_id); auto repo = api->repoInfo(repo_id);
if (!repo.has_value()) if (!repo.has_value())
return STATUS_OBJECT_NAME_NOT_FOUND; 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; *PFileContext = ctx;
SetFileInfo(FileInfo, FILE_ATTRIBUTE_DIRECTORY, repo->size, repo->mtime); SetFileInfo(FileInfo, FILE_ATTRIBUTE_DIRECTORY, repo->size, repo->mtime);
spdlog::info(std::format("open directory {} success", path)); 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()) if (const auto dirInfo = api->dirDetail(repo_id, path); dirInfo.has_value())
{ {
const auto& info = dirInfo.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; *PFileContext = ctx;
SetFileInfo(FileInfo,FILE_ATTRIBUTE_DIRECTORY, 0, 0); SetFileInfo(FileInfo,FILE_ATTRIBUTE_DIRECTORY, 0, 0);
spdlog::info(std::format("open directory {} success", path)); 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()) if (const auto fileInfo = api->fileDetail(repo_id, path); fileInfo.has_value())
{ {
const auto& info = fileInfo.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; *PFileContext = ctx;
SetFileInfo(FileInfo,FILE_ATTRIBUTE_ARCHIVE, info.size, 0); SetFileInfo(FileInfo,FILE_ATTRIBUTE_ARCHIVE, info.size, 0);
spdlog::info(std::format("open file {} success", path)); spdlog::info(std::format("open file {} success", path));
+13 -17
View File
@@ -7,6 +7,7 @@
#include <vector> #include <vector>
#include <stdexcept> #include <stdexcept>
#include <seafile/util/version.hpp> #include <seafile/util/version.hpp>
#include <tuple>
namespace seafile::util { namespace seafile::util {
Version::Version(const std::string &version) { Version::Version(const std::string &version) {
@@ -43,23 +44,18 @@ namespace seafile::util {
return result; return result;
} }
bool Version::operator==(const Version &other) const { std::strong_ordering Version::operator<=>(const Version &other) const {
return major_ == other.major_ const auto lhs = std::tuple{
&& minor().value_or(0) == other.minor().value_or(0) major(),
&& patch().value_or(0) == other.patch().value_or(0); minor().value_or(0),
} patch().value_or(0)
};
const auto rhs = std::tuple{
bool Version::operator<(const Version &other) const { other.major(),
if (major_ != other.major_) { other.minor().value_or(0),
return major_ < other.major_; other.patch().value_or(0)
} };
return lhs <=> rhs;
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);
} }