refactor
This commit is contained in:
parent
c421e84854
commit
60b06790a3
@ -251,23 +251,6 @@ struct directory_item final {
|
|||||||
std::uint64_t size{};
|
std::uint64_t size{};
|
||||||
api_meta_map meta;
|
api_meta_map meta;
|
||||||
bool resolved{false};
|
bool resolved{false};
|
||||||
|
|
||||||
[[nodiscard]] static auto from_json(const json &item) -> directory_item {
|
|
||||||
directory_item ret{};
|
|
||||||
ret.api_path = item["path"].get<std::string>();
|
|
||||||
ret.api_parent = item["parent"].get<std::string>();
|
|
||||||
ret.directory = item["directory"].get<bool>();
|
|
||||||
ret.size = item["size"].get<std::uint64_t>();
|
|
||||||
ret.meta = item["meta"].get<api_meta_map>();
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] auto to_json() const -> json {
|
|
||||||
return {
|
|
||||||
{"path", api_path}, {"parent", api_parent}, {"size", size},
|
|
||||||
{"directory", directory}, {"meta", meta},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct encrypt_config final {
|
struct encrypt_config final {
|
||||||
@ -390,9 +373,30 @@ using meta_provider_callback = std::function<void(directory_item &)>;
|
|||||||
} // namespace repertory
|
} // namespace repertory
|
||||||
|
|
||||||
NLOHMANN_JSON_NAMESPACE_BEGIN
|
NLOHMANN_JSON_NAMESPACE_BEGIN
|
||||||
|
|
||||||
|
template <> struct adl_serializer<repertory::directory_item> {
|
||||||
|
static void to_json(json &data, const repertory::directory_item &value) {
|
||||||
|
data = {
|
||||||
|
{"ApiParent", value.api_parent},
|
||||||
|
{"ApiPath", value.api_path},
|
||||||
|
{"Directory", value.directory},
|
||||||
|
{"Meta", value.meta},
|
||||||
|
{"Size", value.size},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
static void from_json(const json &data, repertory::directory_item &value) {
|
||||||
|
data.at("ApiParent").get_to<std::string>(value.api_parent);
|
||||||
|
data.at("ApiPath").get_to<std::string>(value.api_path);
|
||||||
|
data.at("Directory").get_to<bool>(value.directory);
|
||||||
|
data.at("Meta").get_to<repertory::api_meta_map>(value.meta);
|
||||||
|
data.at("Size").get_to<std::uint64_t>(value.size);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
template <> struct adl_serializer<repertory::encrypt_config> {
|
template <> struct adl_serializer<repertory::encrypt_config> {
|
||||||
static void to_json(json &data, const repertory::encrypt_config &value) {
|
static void to_json(json &data, const repertory::encrypt_config &value) {
|
||||||
data = json{
|
data = {
|
||||||
{"EncryptionToken", value.encryption_token},
|
{"EncryptionToken", value.encryption_token},
|
||||||
{"Path", value.path},
|
{"Path", value.path},
|
||||||
};
|
};
|
||||||
@ -406,7 +410,7 @@ template <> struct adl_serializer<repertory::encrypt_config> {
|
|||||||
|
|
||||||
template <> struct adl_serializer<repertory::host_config> {
|
template <> struct adl_serializer<repertory::host_config> {
|
||||||
static void to_json(json &data, const repertory::host_config &value) {
|
static void to_json(json &data, const repertory::host_config &value) {
|
||||||
data = json{
|
data = {
|
||||||
{"AgentString", value.agent_string},
|
{"AgentString", value.agent_string},
|
||||||
{"ApiPassword", value.api_password},
|
{"ApiPassword", value.api_password},
|
||||||
{"ApiPort", value.api_port},
|
{"ApiPort", value.api_port},
|
||||||
@ -432,7 +436,7 @@ template <> struct adl_serializer<repertory::host_config> {
|
|||||||
|
|
||||||
template <> struct adl_serializer<repertory::s3_config> {
|
template <> struct adl_serializer<repertory::s3_config> {
|
||||||
static void to_json(json &data, const repertory::s3_config &value) {
|
static void to_json(json &data, const repertory::s3_config &value) {
|
||||||
data = json{
|
data = {
|
||||||
{"AccessKey", value.access_key},
|
{"AccessKey", value.access_key},
|
||||||
{"Bucket", value.bucket},
|
{"Bucket", value.bucket},
|
||||||
{"EncryptionToken", value.encryption_token},
|
{"EncryptionToken", value.encryption_token},
|
||||||
@ -460,7 +464,7 @@ template <> struct adl_serializer<repertory::s3_config> {
|
|||||||
|
|
||||||
template <> struct adl_serializer<repertory::sia_config> {
|
template <> struct adl_serializer<repertory::sia_config> {
|
||||||
static void to_json(json &data, const repertory::sia_config &value) {
|
static void to_json(json &data, const repertory::sia_config &value) {
|
||||||
data = json{
|
data = {
|
||||||
{"Bucket", value.bucket},
|
{"Bucket", value.bucket},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -115,7 +115,7 @@ auto directory_iterator::get_directory_item(const std::string &api_path,
|
|||||||
|
|
||||||
auto directory_iterator::get_json(std::size_t offset, json &item) -> int {
|
auto directory_iterator::get_json(std::size_t offset, json &item) -> int {
|
||||||
if (offset < items_.size()) {
|
if (offset < items_.size()) {
|
||||||
item = items_[offset].to_json();
|
item = json(items_.at(offset));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -302,27 +302,27 @@ auto remote_winfsp_drive::Overwrite(PVOID /*file_node*/, PVOID file_desc,
|
|||||||
BOOLEAN replace_attributes,
|
BOOLEAN replace_attributes,
|
||||||
UINT64 allocation_size, FileInfo *file_info)
|
UINT64 allocation_size, FileInfo *file_info)
|
||||||
-> NTSTATUS {
|
-> NTSTATUS {
|
||||||
remote::file_info fi{};
|
remote::file_info info{};
|
||||||
auto ret = remote_instance_->winfsp_overwrite(
|
auto ret = remote_instance_->winfsp_overwrite(
|
||||||
file_desc, attributes, replace_attributes, allocation_size, &fi);
|
file_desc, attributes, replace_attributes, allocation_size, &info);
|
||||||
set_file_info(*file_info, fi);
|
set_file_info(*file_info, info);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void remote_winfsp_drive::populate_file_info(const json &item,
|
void remote_winfsp_drive::populate_file_info(const json &item,
|
||||||
FSP_FSCTL_FILE_INFO &file_info) {
|
FSP_FSCTL_FILE_INFO &file_info) {
|
||||||
auto di = directory_item::from_json(item);
|
auto dir_item = item.get<directory_item>();
|
||||||
file_info.FileSize = di.directory ? 0 : di.size;
|
file_info.FileSize = dir_item.directory ? 0 : dir_item.size;
|
||||||
file_info.AllocationSize =
|
file_info.AllocationSize =
|
||||||
utils::divide_with_ceiling(file_info.FileSize, WINFSP_ALLOCATION_UNIT) *
|
utils::divide_with_ceiling(file_info.FileSize, WINFSP_ALLOCATION_UNIT) *
|
||||||
WINFSP_ALLOCATION_UNIT;
|
WINFSP_ALLOCATION_UNIT;
|
||||||
file_info.ChangeTime = utils::get_changed_time_from_meta(di.meta);
|
file_info.ChangeTime = utils::get_changed_time_from_meta(dir_item.meta);
|
||||||
file_info.CreationTime = utils::get_creation_time_from_meta(di.meta);
|
file_info.CreationTime = utils::get_creation_time_from_meta(dir_item.meta);
|
||||||
file_info.FileAttributes = utils::get_attributes_from_meta(di.meta);
|
file_info.FileAttributes = utils::get_attributes_from_meta(dir_item.meta);
|
||||||
file_info.HardLinks = 0;
|
file_info.HardLinks = 0;
|
||||||
file_info.IndexNumber = 0;
|
file_info.IndexNumber = 0;
|
||||||
file_info.LastAccessTime = utils::get_accessed_time_from_meta(di.meta);
|
file_info.LastAccessTime = utils::get_accessed_time_from_meta(dir_item.meta);
|
||||||
file_info.LastWriteTime = utils::get_written_time_from_meta(di.meta);
|
file_info.LastWriteTime = utils::get_written_time_from_meta(dir_item.meta);
|
||||||
file_info.ReparseTag = 0;
|
file_info.ReparseTag = 0;
|
||||||
file_info.EaSize = 0;
|
file_info.EaSize = 0;
|
||||||
}
|
}
|
||||||
|
@ -36,15 +36,12 @@ full_server::full_server(app_config &config, i_provider &provider,
|
|||||||
|
|
||||||
void full_server::handle_get_directory_items(const httplib::Request &req,
|
void full_server::handle_get_directory_items(const httplib::Request &req,
|
||||||
httplib::Response &res) {
|
httplib::Response &res) {
|
||||||
const auto api_path =
|
auto api_path = utils::path::create_api_path(req.get_param_value("api_path"));
|
||||||
utils::path::create_api_path(req.get_param_value("api_path"));
|
res.set_content(json({
|
||||||
const auto list = fm_.get_directory_items(api_path);
|
{"items", fm_.get_directory_items(api_path)},
|
||||||
|
})
|
||||||
json items = {{"items", std::vector<json>()}};
|
.dump(),
|
||||||
for (const auto &item : list) {
|
"application/json");
|
||||||
items["items"].emplace_back(item.to_json());
|
|
||||||
}
|
|
||||||
res.set_content(items.dump(), "application/json");
|
|
||||||
res.status = 200;
|
res.status = 200;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,9 +63,9 @@ void full_server::handle_get_drive_information(const httplib::Request & /*req*/,
|
|||||||
|
|
||||||
void full_server::handle_get_open_files(const httplib::Request & /*req*/,
|
void full_server::handle_get_open_files(const httplib::Request & /*req*/,
|
||||||
httplib::Response &res) {
|
httplib::Response &res) {
|
||||||
const auto list = fm_.get_open_files();
|
auto list = fm_.get_open_files();
|
||||||
|
|
||||||
json open_files = {{"items", std::vector<json>()}};
|
json open_files;
|
||||||
for (const auto &kv : list) {
|
for (const auto &kv : list) {
|
||||||
open_files["items"].emplace_back(json({
|
open_files["items"].emplace_back(json({
|
||||||
{"path", kv.first},
|
{"path", kv.first},
|
||||||
@ -81,7 +78,10 @@ void full_server::handle_get_open_files(const httplib::Request & /*req*/,
|
|||||||
|
|
||||||
void full_server::handle_get_pinned_files(const httplib::Request & /*req*/,
|
void full_server::handle_get_pinned_files(const httplib::Request & /*req*/,
|
||||||
httplib::Response &res) {
|
httplib::Response &res) {
|
||||||
res.set_content(json({{"items", provider_.get_pinned_files()}}).dump(),
|
res.set_content(json({
|
||||||
|
{"items", provider_.get_pinned_files()},
|
||||||
|
})
|
||||||
|
.dump(),
|
||||||
"application/json");
|
"application/json");
|
||||||
res.status = 200;
|
res.status = 200;
|
||||||
}
|
}
|
||||||
@ -90,11 +90,10 @@ void full_server::handle_get_pinned_status(const httplib::Request &req,
|
|||||||
httplib::Response &res) {
|
httplib::Response &res) {
|
||||||
REPERTORY_USES_FUNCTION_NAME();
|
REPERTORY_USES_FUNCTION_NAME();
|
||||||
|
|
||||||
const auto api_path =
|
auto api_path = utils::path::create_api_path(req.get_param_value("api_path"));
|
||||||
utils::path::create_api_path(req.get_param_value("api_path"));
|
|
||||||
|
|
||||||
std::string pinned;
|
std::string pinned;
|
||||||
const auto result = provider_.get_item_meta(api_path, META_PINNED, pinned);
|
auto result = provider_.get_item_meta(api_path, META_PINNED, pinned);
|
||||||
if (result != api_error::success) {
|
if (result != api_error::success) {
|
||||||
utils::error::raise_api_path_error(function_name, api_path, result,
|
utils::error::raise_api_path_error(function_name, api_path, result,
|
||||||
"failed to get pinned status");
|
"failed to get pinned status");
|
||||||
@ -103,8 +102,10 @@ void full_server::handle_get_pinned_status(const httplib::Request &req,
|
|||||||
}
|
}
|
||||||
|
|
||||||
res.set_content(
|
res.set_content(
|
||||||
json(
|
json({
|
||||||
{{"pinned", pinned.empty() ? false : utils::string::to_bool(pinned)}})
|
{"pinned",
|
||||||
|
pinned.empty() ? false : utils::string::to_bool(pinned)},
|
||||||
|
})
|
||||||
.dump(),
|
.dump(),
|
||||||
"application/json");
|
"application/json");
|
||||||
res.status = 200;
|
res.status = 200;
|
||||||
@ -114,8 +115,7 @@ void full_server::handle_pin_file(const httplib::Request &req,
|
|||||||
httplib::Response &res) {
|
httplib::Response &res) {
|
||||||
REPERTORY_USES_FUNCTION_NAME();
|
REPERTORY_USES_FUNCTION_NAME();
|
||||||
|
|
||||||
const auto api_path =
|
auto api_path = utils::path::create_api_path(req.get_param_value("api_path"));
|
||||||
utils::path::create_api_path(req.get_param_value("api_path"));
|
|
||||||
|
|
||||||
bool exists{};
|
bool exists{};
|
||||||
auto result = provider_.is_file(api_path, exists);
|
auto result = provider_.is_file(api_path, exists);
|
||||||
@ -143,8 +143,7 @@ void full_server::handle_unpin_file(const httplib::Request &req,
|
|||||||
httplib::Response &res) {
|
httplib::Response &res) {
|
||||||
REPERTORY_USES_FUNCTION_NAME();
|
REPERTORY_USES_FUNCTION_NAME();
|
||||||
|
|
||||||
const auto api_path =
|
auto api_path = utils::path::create_api_path(req.get_param_value("api_path"));
|
||||||
utils::path::create_api_path(req.get_param_value("api_path"));
|
|
||||||
|
|
||||||
bool exists{};
|
bool exists{};
|
||||||
auto result = provider_.is_file(api_path, exists);
|
auto result = provider_.is_file(api_path, exists);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user