重新组织项目结构
This commit is contained in:
1 parent
28206cd50e
commit
4d7dde104d
15 files changed
+55
-79
No files matched your search
+11
-11
@@ -37,17 +37,17 @@ set(WINFSP_LIB "winfsp-${WINFSP_PLATFORM}.lib")
|
|||||||
message(STATUS "WinFSP lib: ${WINFSP_LIB}")
|
message(STATUS "WinFSP lib: ${WINFSP_LIB}")
|
||||||
|
|
||||||
add_executable(seadisk src/main.cpp
|
add_executable(seadisk src/main.cpp
|
||||||
include/seafile/seafile_api.hpp
|
include/seafile/api/seafile_api.hpp
|
||||||
include/seafile/exception.hpp
|
include/seafile/api/exception.hpp
|
||||||
include/seafile/server_info.hpp
|
include/seafile/api/server_info.hpp
|
||||||
include/seafile/auth_token.hpp
|
include/seafile/api/auth_token.hpp
|
||||||
include/seafile/default_repo.hpp
|
include/seafile/api/default_repo.hpp
|
||||||
include/seafile/token_type.hpp
|
include/seafile/api/token_type.hpp
|
||||||
include/seafile/repo_info.hpp
|
include/seafile/api/repo_info.hpp
|
||||||
include/seafile/repo_entry.hpp
|
include/seafile/api/repo_entry.hpp
|
||||||
include/seafile/account_info.hpp
|
include/seafile/api/account_info.hpp
|
||||||
include/seafile/file_info.hpp
|
include/seafile/api/file_info.hpp
|
||||||
include/seafile/dir_info.hpp
|
include/seafile/api/dir_info.hpp
|
||||||
include/seafile/fs/file_context.hpp
|
include/seafile/fs/file_context.hpp
|
||||||
include/seafile/fs/seafile_file_system.hpp
|
include/seafile/fs/seafile_file_system.hpp
|
||||||
src/seafile/fs/seafile_file_system.cpp
|
src/seafile/fs/seafile_file_system.cpp
|
||||||
|
|||||||
File renamed without changes.
@@ -4,6 +4,8 @@
|
|||||||
|
|
||||||
#ifndef SEADISK_AUTH_TOKEN_HPP
|
#ifndef SEADISK_AUTH_TOKEN_HPP
|
||||||
#define SEADISK_AUTH_TOKEN_HPP
|
#define SEADISK_AUTH_TOKEN_HPP
|
||||||
|
#include <string>
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
namespace seafile {
|
namespace seafile {
|
||||||
struct AuthToken final {
|
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 <optional>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
#include <winfsp/fsctl.h>
|
|
||||||
|
|
||||||
namespace seafile
|
namespace seafile
|
||||||
{
|
{
|
||||||
File renamed without changes.
@@ -23,10 +23,8 @@
|
|||||||
#include "server_info.hpp"
|
#include "server_info.hpp"
|
||||||
#include "token_type.hpp"
|
#include "token_type.hpp"
|
||||||
|
|
||||||
namespace seafile
|
namespace seafile {
|
||||||
{
|
class SeaFileApi final {
|
||||||
class SeaFileApi final
|
|
||||||
{
|
|
||||||
//base url of the seafile api server
|
//base url of the seafile api server
|
||||||
std::string base_url;
|
std::string base_url;
|
||||||
|
|
||||||
@@ -35,46 +33,38 @@ namespace seafile
|
|||||||
* @param path url path
|
* @param path url path
|
||||||
* @return the whole url string
|
* @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);
|
auto url = ada::parse(this->base_url);
|
||||||
url->set_pathname(path);
|
url->set_pathname(path);
|
||||||
return std::string(url->get_href());
|
return std::string(url->get_href());
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
static tl::expected<T, SeafileException>
|
static tl::expected<T, SeafileException>
|
||||||
parseResponse(const cpr::Response& response)
|
parseResponse(const cpr::Response &response) {
|
||||||
{
|
if (response.error) {
|
||||||
if (response.error)
|
|
||||||
{
|
|
||||||
return tl::make_unexpected(
|
return tl::make_unexpected(
|
||||||
SeafileException(
|
SeafileException(
|
||||||
response.error.message));
|
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(
|
return tl::make_unexpected(
|
||||||
SeafileException(
|
SeafileException(
|
||||||
std::format("Http Error: {}",
|
std::format("Http Error: {}",
|
||||||
response.status_code)));
|
response.status_code)));
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
return nlohmann::json::parse(response.text)
|
return nlohmann::json::parse(response.text)
|
||||||
.get<T>();
|
.get<T>();
|
||||||
}
|
} catch (const std::exception &e) {
|
||||||
catch (const std::exception& e)
|
|
||||||
{
|
|
||||||
return tl::make_unexpected(
|
return tl::make_unexpected(
|
||||||
SeafileException(e.what()));
|
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
|
return token_type == TokenType::BEARER
|
||||||
? std::format("Bearer {}", token)
|
? std::format("Bearer {}", token)
|
||||||
: std::format("Token {}", token);
|
: std::format("Token {}", token);
|
||||||
@@ -87,9 +77,8 @@ namespace seafile
|
|||||||
* @param body post body data
|
* @param body post body data
|
||||||
* @return T if success else SeafileException
|
* @return T if success else SeafileException
|
||||||
*/
|
*/
|
||||||
template <typename T>
|
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 url = makeUrl(path);
|
||||||
const auto response = cpr::Post(
|
const auto response = cpr::Post(
|
||||||
cpr::Url{url},
|
cpr::Url{url},
|
||||||
@@ -105,8 +94,7 @@ namespace seafile
|
|||||||
* @brief primary constructor
|
* @brief primary constructor
|
||||||
* @param base_url base url of seafile server
|
* @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
|
* @return token when success else SeafileException
|
||||||
*/
|
*/
|
||||||
tl::expected<AuthToken, 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 = {
|
const nlohmann::json body = {
|
||||||
{"username", username},
|
{"username", username},
|
||||||
{"password", password}
|
{"password", password}
|
||||||
@@ -126,8 +113,7 @@ namespace seafile
|
|||||||
}
|
}
|
||||||
|
|
||||||
tl::expected<ServerInfo, SeafileException>
|
tl::expected<ServerInfo, SeafileException>
|
||||||
serverInfo() const
|
serverInfo() const {
|
||||||
{
|
|
||||||
const auto response = cpr::Get(
|
const auto response = cpr::Get(
|
||||||
cpr::Url{makeUrl("/api2/server-info/")},
|
cpr::Url{makeUrl("/api2/server-info/")},
|
||||||
cpr::Header{
|
cpr::Header{
|
||||||
@@ -144,8 +130,7 @@ namespace seafile
|
|||||||
* @return default repo info
|
* @return default repo info
|
||||||
*/
|
*/
|
||||||
tl::expected<DefaultRepo, SeafileException>
|
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 auth = makeAuthToken(token, token_type);
|
||||||
const auto url = makeUrl("/api2/default-repo/");
|
const auto url = makeUrl("/api2/default-repo/");
|
||||||
const auto response = cpr::Get(cpr::Url{url},
|
const auto response = cpr::Get(cpr::Url{url},
|
||||||
@@ -157,8 +142,7 @@ namespace seafile
|
|||||||
}
|
}
|
||||||
|
|
||||||
tl::expected<RepoInfo, SeafileException>
|
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 url = makeUrl(std::format("/api2/repos/{}/", repo_id));
|
||||||
const auto auth = makeAuthToken(token, token_type);
|
const auto auth = makeAuthToken(token, token_type);
|
||||||
|
|
||||||
@@ -179,9 +163,8 @@ namespace seafile
|
|||||||
* @return repo entries
|
* @return repo entries
|
||||||
*/
|
*/
|
||||||
tl::expected<std::vector<RepoEntry>, SeafileException>
|
tl::expected<std::vector<RepoEntry>, SeafileException>
|
||||||
repoDir(const std::string& repo_id, const std::string& path, const std::string& token,
|
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 url = cpr::Url{makeUrl(std::format("/api2/repos/{}/dir/", repo_id))};
|
||||||
const auto auth = makeAuthToken(token, token_type);
|
const auto auth = makeAuthToken(token, token_type);
|
||||||
|
|
||||||
@@ -193,13 +176,12 @@ namespace seafile
|
|||||||
cpr::Parameters{
|
cpr::Parameters{
|
||||||
{"p", path}
|
{"p", path}
|
||||||
});
|
});
|
||||||
return parseResponse<std::vector<RepoEntry>>(response);
|
return parseResponse<std::vector<RepoEntry> >(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
tl::expected<AccountInfo, SeafileException>
|
tl::expected<AccountInfo, SeafileException>
|
||||||
accountInfo(const std::string& token,
|
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 url = cpr::Url{makeUrl("/api2/account/info/")};
|
||||||
const auto auth = makeAuthToken(token, token_type);
|
const auto auth = makeAuthToken(token, token_type);
|
||||||
|
|
||||||
@@ -212,9 +194,8 @@ namespace seafile
|
|||||||
}
|
}
|
||||||
|
|
||||||
tl::expected<FileInfo, SeafileException>
|
tl::expected<FileInfo, SeafileException>
|
||||||
fileDetail(const std::string& repo_id, const std::string& path, const std::string& token,
|
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 url = cpr::Url{makeUrl(std::format("/api2/repos/{}/file/detail/", repo_id))};
|
||||||
const auto auth = makeAuthToken(token, token_type);
|
const auto auth = makeAuthToken(token, token_type);
|
||||||
|
|
||||||
@@ -229,9 +210,8 @@ namespace seafile
|
|||||||
}
|
}
|
||||||
|
|
||||||
tl::expected<std::string, SeafileException>
|
tl::expected<std::string, SeafileException>
|
||||||
downloadFileUrl(const std::string& repo_id, const std::string& path, const std::string& token,
|
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 auth = makeAuthToken(token, token_type);
|
||||||
const auto url = cpr::Url{makeUrl(std::format("/api2/repos/{}/file/", repo_id))};
|
const auto url = cpr::Url{makeUrl(std::format("/api2/repos/{}/file/", repo_id))};
|
||||||
const auto response = cpr::Get(url,
|
const auto response = cpr::Get(url,
|
||||||
@@ -246,15 +226,13 @@ namespace seafile
|
|||||||
|
|
||||||
|
|
||||||
tl::expected<std::string, SeafileException>
|
tl::expected<std::string, SeafileException>
|
||||||
downloadFile(const std::string& repo_id,
|
downloadFile(const std::string &repo_id,
|
||||||
const std::string& path,
|
const std::string &path,
|
||||||
const std::optional<size_t> start,
|
const std::optional<size_t> start,
|
||||||
const std::optional<size_t> end,
|
const std::optional<size_t> end,
|
||||||
const std::string& token,
|
const std::string &token,
|
||||||
const TokenType token_type) const
|
const TokenType token_type) const {
|
||||||
{
|
if (auto download_url = downloadFileUrl(repo_id, path, token, token_type); download_url.has_value()) {
|
||||||
if (auto download_url = downloadFileUrl(repo_id, path, token, token_type); download_url.has_value())
|
|
||||||
{
|
|
||||||
const auto auth = makeAuthToken(token, token_type);
|
const auto auth = makeAuthToken(token, token_type);
|
||||||
const auto url = cpr::Url{download_url.value()};
|
const auto url = cpr::Url{download_url.value()};
|
||||||
auto header = cpr::Header{
|
auto header = cpr::Header{
|
||||||
@@ -265,22 +243,19 @@ namespace seafile
|
|||||||
start ? std::to_string(*start) : "",
|
start ? std::to_string(*start) : "",
|
||||||
end ? std::to_string(*end) : "");
|
end ? std::to_string(*end) : "");
|
||||||
header.emplace("range", range);
|
header.emplace("range", range);
|
||||||
const auto& response = cpr::Get(url, header);
|
if (const auto &response = cpr::Get(url, header);
|
||||||
if (response.status_code != 200 && response.status_code != 206) {
|
response.error || (response.status_code != 200 && response.status_code != 206)) {
|
||||||
return tl::make_unexpected(SeafileException{std::format("HTTP Error:{}", response.status_code)});
|
return tl::make_unexpected(SeafileException{std::format("HTTP Error:{}", response.status_code)});
|
||||||
}else {
|
} else {
|
||||||
return response.text;
|
return response.text;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
return download_url;
|
return download_url;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tl::expected<DirInfo, SeafileException> dirDetail(const std::string& repo_id, const std::string& path,
|
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 auth = makeAuthToken(token, token_type);
|
||||||
const auto url = cpr::Url{makeUrl(std::format("/api/v2.1/repos/{}/dir/detail/", repo_id))};
|
const auto url = cpr::Url{makeUrl(std::format("/api/v2.1/repos/{}/dir/detail/", repo_id))};
|
||||||
const auto response = cpr::Get(url, cpr::Header{
|
const auto response = cpr::Get(url, cpr::Header{
|
||||||
File renamed without changes.
File renamed without changes.
@@ -7,8 +7,8 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <winfsp/winfsp.h>
|
#include <winfsp/winfsp.h>
|
||||||
|
|
||||||
#include "seafile/seafile_api.hpp"
|
#include "../api/seafile_api.hpp"
|
||||||
#include "seafile/token_type.hpp"
|
#include "../api/token_type.hpp"
|
||||||
|
|
||||||
namespace seafile::fs
|
namespace seafile::fs
|
||||||
{
|
{
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
#include <winfsp/winfsp.h>
|
#include <winfsp/winfsp.h>
|
||||||
#include "seafile/fs/winfsp_adapter.hpp"
|
#include "seafile/fs/winfsp_adapter.hpp"
|
||||||
#include "seafile/seafile_api.hpp"
|
#include "seafile/api/seafile_api.hpp"
|
||||||
|
|
||||||
using namespace seafile::fs;
|
using namespace seafile::fs;
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ namespace seafile::fs {
|
|||||||
constexpr int64_t UNIX_EPOCH_AS_FILETIME = 116444736000000000LL;
|
constexpr int64_t UNIX_EPOCH_AS_FILETIME = 116444736000000000LL;
|
||||||
constexpr int64_t HUNDREDS_OF_NANOSECONDS_PER_SECOND = 10000000LL;
|
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;
|
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;
|
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->FileAttributes = attributes;
|
||||||
FileInfo->AllocationSize = size;
|
FileInfo->AllocationSize = size;
|
||||||
FileInfo->FileSize = size;
|
FileInfo->FileSize = size;
|
||||||
|
|||||||
Reference in new issue
Block a user