重新组织项目结构
This commit is contained in:
1 parent
28206cd50e
commit
4d7dde104d
15 files changed
+43
-67
No files matched your search
+11
-11
@@ -37,17 +37,17 @@ set(WINFSP_LIB "winfsp-${WINFSP_PLATFORM}.lib")
|
||||
message(STATUS "WinFSP lib: ${WINFSP_LIB}")
|
||||
|
||||
add_executable(seadisk src/main.cpp
|
||||
include/seafile/seafile_api.hpp
|
||||
include/seafile/exception.hpp
|
||||
include/seafile/server_info.hpp
|
||||
include/seafile/auth_token.hpp
|
||||
include/seafile/default_repo.hpp
|
||||
include/seafile/token_type.hpp
|
||||
include/seafile/repo_info.hpp
|
||||
include/seafile/repo_entry.hpp
|
||||
include/seafile/account_info.hpp
|
||||
include/seafile/file_info.hpp
|
||||
include/seafile/dir_info.hpp
|
||||
include/seafile/api/seafile_api.hpp
|
||||
include/seafile/api/exception.hpp
|
||||
include/seafile/api/server_info.hpp
|
||||
include/seafile/api/auth_token.hpp
|
||||
include/seafile/api/default_repo.hpp
|
||||
include/seafile/api/token_type.hpp
|
||||
include/seafile/api/repo_info.hpp
|
||||
include/seafile/api/repo_entry.hpp
|
||||
include/seafile/api/account_info.hpp
|
||||
include/seafile/api/file_info.hpp
|
||||
include/seafile/api/dir_info.hpp
|
||||
include/seafile/fs/file_context.hpp
|
||||
include/seafile/fs/seafile_file_system.hpp
|
||||
src/seafile/fs/seafile_file_system.cpp
|
||||
|
||||
File renamed without changes.
@@ -4,6 +4,8 @@
|
||||
|
||||
#ifndef SEADISK_AUTH_TOKEN_HPP
|
||||
#define SEADISK_AUTH_TOKEN_HPP
|
||||
#include <string>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
namespace seafile {
|
||||
struct AuthToken final {
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -7,7 +7,6 @@
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <winfsp/fsctl.h>
|
||||
|
||||
namespace seafile
|
||||
{
|
||||
File renamed without changes.
@@ -23,10 +23,8 @@
|
||||
#include "server_info.hpp"
|
||||
#include "token_type.hpp"
|
||||
|
||||
namespace seafile
|
||||
{
|
||||
class SeaFileApi final
|
||||
{
|
||||
namespace seafile {
|
||||
class SeaFileApi final {
|
||||
//base url of the seafile api server
|
||||
std::string base_url;
|
||||
|
||||
@@ -35,8 +33,7 @@ namespace seafile
|
||||
* @param path url path
|
||||
* @return the whole url string
|
||||
*/
|
||||
[[nodiscard]] std::string makeUrl(const std::string& path) const
|
||||
{
|
||||
[[nodiscard]] std::string makeUrl(const std::string &path) const {
|
||||
auto url = ada::parse(this->base_url);
|
||||
url->set_pathname(path);
|
||||
return std::string(url->get_href());
|
||||
@@ -44,37 +41,30 @@ namespace seafile
|
||||
|
||||
template<typename T>
|
||||
static tl::expected<T, SeafileException>
|
||||
parseResponse(const cpr::Response& response)
|
||||
{
|
||||
if (response.error)
|
||||
{
|
||||
parseResponse(const cpr::Response &response) {
|
||||
if (response.error) {
|
||||
return tl::make_unexpected(
|
||||
SeafileException(
|
||||
response.error.message));
|
||||
}
|
||||
|
||||
if (response.status_code != 200 && response.status_code != 206)
|
||||
{
|
||||
if (response.status_code != 200 && response.status_code != 206) {
|
||||
return tl::make_unexpected(
|
||||
SeafileException(
|
||||
std::format("Http Error: {}",
|
||||
response.status_code)));
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
try {
|
||||
return nlohmann::json::parse(response.text)
|
||||
.get<T>();
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
} catch (const std::exception &e) {
|
||||
return tl::make_unexpected(
|
||||
SeafileException(e.what()));
|
||||
}
|
||||
}
|
||||
|
||||
static std::string makeAuthToken(const std::string& token, const TokenType& token_type)
|
||||
{
|
||||
static std::string makeAuthToken(const std::string &token, const TokenType &token_type) {
|
||||
return token_type == TokenType::BEARER
|
||||
? std::format("Bearer {}", token)
|
||||
: std::format("Token {}", token);
|
||||
@@ -88,8 +78,7 @@ namespace seafile
|
||||
* @return T if success else SeafileException
|
||||
*/
|
||||
template<typename T>
|
||||
tl::expected<T, SeafileException> post(const std::string& path, const nlohmann::json& body)
|
||||
{
|
||||
tl::expected<T, SeafileException> post(const std::string &path, const nlohmann::json &body) {
|
||||
const auto url = makeUrl(path);
|
||||
const auto response = cpr::Post(
|
||||
cpr::Url{url},
|
||||
@@ -105,8 +94,7 @@ namespace seafile
|
||||
* @brief primary constructor
|
||||
* @param base_url base url of seafile server
|
||||
*/
|
||||
explicit SeaFileApi(std::string base_url) : base_url(std::move(base_url))
|
||||
{
|
||||
explicit SeaFileApi(std::string base_url) : base_url(std::move(base_url)) {
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -116,8 +104,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) {
|
||||
const nlohmann::json body = {
|
||||
{"username", username},
|
||||
{"password", password}
|
||||
@@ -126,8 +113,7 @@ namespace seafile
|
||||
}
|
||||
|
||||
tl::expected<ServerInfo, SeafileException>
|
||||
serverInfo() const
|
||||
{
|
||||
serverInfo() const {
|
||||
const auto response = cpr::Get(
|
||||
cpr::Url{makeUrl("/api2/server-info/")},
|
||||
cpr::Header{
|
||||
@@ -144,8 +130,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 {
|
||||
const auto auth = makeAuthToken(token, token_type);
|
||||
const auto url = makeUrl("/api2/default-repo/");
|
||||
const auto response = cpr::Get(cpr::Url{url},
|
||||
@@ -157,8 +142,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 {
|
||||
const auto url = makeUrl(std::format("/api2/repos/{}/", repo_id));
|
||||
const auto auth = makeAuthToken(token, token_type);
|
||||
|
||||
@@ -180,8 +164,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 {
|
||||
const auto url = cpr::Url{makeUrl(std::format("/api2/repos/{}/dir/", repo_id))};
|
||||
const auto auth = makeAuthToken(token, token_type);
|
||||
|
||||
@@ -198,8 +181,7 @@ namespace seafile
|
||||
|
||||
tl::expected<AccountInfo, SeafileException>
|
||||
accountInfo(const std::string &token,
|
||||
const TokenType token_type) const
|
||||
{
|
||||
const TokenType token_type) const {
|
||||
const auto url = cpr::Url{makeUrl("/api2/account/info/")};
|
||||
const auto auth = makeAuthToken(token, token_type);
|
||||
|
||||
@@ -213,8 +195,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 {
|
||||
const auto url = cpr::Url{makeUrl(std::format("/api2/repos/{}/file/detail/", repo_id))};
|
||||
const auto auth = makeAuthToken(token, token_type);
|
||||
|
||||
@@ -230,8 +211,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 {
|
||||
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,
|
||||
@@ -251,10 +231,8 @@ namespace seafile
|
||||
const std::optional<size_t> start,
|
||||
const std::optional<size_t> end,
|
||||
const std::string &token,
|
||||
const TokenType token_type) const
|
||||
{
|
||||
if (auto download_url = downloadFileUrl(repo_id, path, token, token_type); download_url.has_value())
|
||||
{
|
||||
const TokenType token_type) const {
|
||||
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()};
|
||||
auto header = cpr::Header{
|
||||
@@ -265,22 +243,19 @@ namespace seafile
|
||||
start ? std::to_string(*start) : "",
|
||||
end ? std::to_string(*end) : "");
|
||||
header.emplace("range", range);
|
||||
const auto& response = cpr::Get(url, header);
|
||||
if (response.status_code != 200 && response.status_code != 206) {
|
||||
if (const auto &response = cpr::Get(url, header);
|
||||
response.error || (response.status_code != 200 && response.status_code != 206)) {
|
||||
return tl::make_unexpected(SeafileException{std::format("HTTP Error:{}", response.status_code)});
|
||||
} else {
|
||||
return response.text;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
return download_url;
|
||||
}
|
||||
}
|
||||
|
||||
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 {
|
||||
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{
|
||||
File renamed without changes.
File renamed without changes.
@@ -7,8 +7,8 @@
|
||||
#include <string>
|
||||
#include <winfsp/winfsp.h>
|
||||
|
||||
#include "seafile/seafile_api.hpp"
|
||||
#include "seafile/token_type.hpp"
|
||||
#include "../api/seafile_api.hpp"
|
||||
#include "../api/token_type.hpp"
|
||||
|
||||
namespace seafile::fs
|
||||
{
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
#include <winfsp/winfsp.h>
|
||||
#include "seafile/fs/winfsp_adapter.hpp"
|
||||
#include "seafile/seafile_api.hpp"
|
||||
#include "seafile/api/seafile_api.hpp"
|
||||
|
||||
using namespace seafile::fs;
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace seafile::fs {
|
||||
constexpr int64_t UNIX_EPOCH_AS_FILETIME = 116444736000000000LL;
|
||||
constexpr int64_t HUNDREDS_OF_NANOSECONDS_PER_SECOND = 10000000LL;
|
||||
|
||||
int64_t UnixTimeToFileTime(int64_t unix_time) {
|
||||
int64_t UnixTimeToFileTime(const int64_t unix_time) {
|
||||
return UNIX_EPOCH_AS_FILETIME + unix_time * HUNDREDS_OF_NANOSECONDS_PER_SECOND;
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace seafile::fs {
|
||||
return (static_cast<int64_t>(ft.dwHighDateTime) << 32) | ft.dwLowDateTime;
|
||||
}
|
||||
|
||||
void SetFileInfo(FSP_FSCTL_FILE_INFO *FileInfo, uint32_t attributes, uint64_t size, int64_t mtime) {
|
||||
void SetFileInfo(FSP_FSCTL_FILE_INFO *FileInfo, const uint32_t attributes, const uint64_t size,const int64_t mtime) {
|
||||
FileInfo->FileAttributes = attributes;
|
||||
FileInfo->AllocationSize = size;
|
||||
FileInfo->FileSize = size;
|
||||
|
||||
Reference in new issue
Block a user