2.0.0-rc (#9)
Some checks failed
BlockStorage/repertory_osx/pipeline/head This commit looks good
BlockStorage/repertory_windows/pipeline/head This commit looks good
BlockStorage/repertory/pipeline/head There was a failure building this commit
BlockStorage/repertory_linux_builds/pipeline/head This commit looks good
BlockStorage/repertory_osx_builds/pipeline/head There was a failure building this commit
Some checks failed
BlockStorage/repertory_osx/pipeline/head This commit looks good
BlockStorage/repertory_windows/pipeline/head This commit looks good
BlockStorage/repertory/pipeline/head There was a failure building this commit
BlockStorage/repertory_linux_builds/pipeline/head This commit looks good
BlockStorage/repertory_osx_builds/pipeline/head There was a failure building this commit
### Issues * \#1 \[bug\] Unable to mount S3 due to 'item_not_found' exception * \#2 Require bucket name for S3 mounts * \#3 \[bug\] File size is not being updated in S3 mount * \#4 Upgrade to libfuse-3.x.x * \#5 Switch to renterd for Sia support * \#6 Switch to cpp-httplib to further reduce dependencies * \#7 Remove global_data and calculate used disk space per provider * \#8 Switch to libcurl for S3 mount support ### Changes from v1.x.x * Added read-only encrypt provider * Pass-through mount point that transparently encrypts source data using `XChaCha20-Poly1305` * Added S3 encryption support via `XChaCha20-Poly1305` * Added replay protection to remote mounts * Added support base64 writes in remote FUSE * Created static linked Linux binaries for `amd64` and `aarch64` using `musl-libc` * Removed legacy Sia renter support * Removed Skynet support * Fixed multiple remote mount WinFSP API issues on \*NIX servers * Implemented chunked read and write * Writes for non-cached files are performed in chunks of 8Mib * Removed `repertory-ui` support * Removed `FreeBSD` support * Switched to `libsodium` over `CryptoPP` * Switched to `XChaCha20-Poly1305` for remote mounts * Updated `GoogleTest` to v1.14.0 * Updated `JSON for Modern C++` to v3.11.2 * Updated `OpenSSL` to v1.1.1w * Updated `RocksDB` to v8.5.3 * Updated `WinFSP` to 2023 * Updated `boost` to v1.78.0 * Updated `cURL` to v8.3.0 * Updated `zlib` to v1.3 * Use `upload_manager` for all providers * Adds a delay to uploads to prevent excessive API calls * Supports re-upload after mount restart for incomplete uploads * NOTE: Uploads for all providers are full file (no resume support) * Multipart upload support is planned for S3 Reviewed-on: #9
This commit is contained in:
@@ -1,165 +1,204 @@
|
||||
/*
|
||||
Copyright <2018-2022> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2023> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
||||
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#include "rpc/server/full_server.hpp"
|
||||
|
||||
#include "app_config.hpp"
|
||||
#include "drives/directory_iterator.hpp"
|
||||
#include "drives/i_open_file_table.hpp"
|
||||
#include "file_manager/i_file_manager.hpp"
|
||||
#include "providers/i_provider.hpp"
|
||||
#include "providers/skynet/skynet_provider.hpp"
|
||||
#include "types/repertory.hpp"
|
||||
#include "types/rpc.hpp"
|
||||
#include "types/skynet.hpp"
|
||||
#include "utils/global_data.hpp"
|
||||
#include "utils/file_utils.hpp"
|
||||
#include "utils/path_utils.hpp"
|
||||
|
||||
namespace repertory {
|
||||
full_server::full_server(app_config &config, i_provider &provider, i_open_file_table &oft)
|
||||
: server(config), provider_(provider), oft_(oft) {}
|
||||
full_server::full_server(app_config &config, i_provider &provider,
|
||||
i_file_manager &fm)
|
||||
: server(config), provider_(provider), fm_(fm) {}
|
||||
|
||||
bool full_server::handle_request(jsonrpcpp::request_ptr &request,
|
||||
std::unique_ptr<jsonrpcpp::Response> &response) {
|
||||
auto handled = true;
|
||||
if (request->method == rpc_method::get_drive_information) {
|
||||
if (request->params.param_array.empty()) {
|
||||
response = std::make_unique<jsonrpcpp::Response>(
|
||||
*request, json({{"cache_space_used", global_data::instance().get_used_cache_space()},
|
||||
{"drive_space_total", provider_.get_total_drive_space()},
|
||||
{"drive_space_used", global_data::instance().get_used_drive_space()},
|
||||
{"item_count", provider_.get_total_item_count()}}));
|
||||
} else {
|
||||
throw jsonrpcpp::InvalidParamsException(*request);
|
||||
}
|
||||
} else if (request->method == rpc_method::get_pinned_files) {
|
||||
if (request->params.param_array.empty()) {
|
||||
response = std::make_unique<jsonrpcpp::Response>(*request, provider_.get_pinned_files());
|
||||
} else {
|
||||
throw jsonrpcpp::InvalidParamsException(*request);
|
||||
}
|
||||
} else if (request->method == rpc_method::get_directory_items) {
|
||||
if (request->params.param_array.size() == 1u) {
|
||||
const auto api_path = utils::path::create_api_path(request->params.param_array[0]);
|
||||
auto directoryItems = oft_.get_directory_items(api_path);
|
||||
std::vector<json> items;
|
||||
for (const auto &item : directoryItems) {
|
||||
items.emplace_back(item.to_json());
|
||||
}
|
||||
void full_server::handle_get_directory_items(const httplib::Request &req,
|
||||
httplib::Response &res) {
|
||||
const auto api_path =
|
||||
utils::path::create_api_path(req.get_param_value("api_path"));
|
||||
const auto list = fm_.get_directory_items(api_path);
|
||||
|
||||
response = std::make_unique<jsonrpcpp::Response>(*request, json({{"items", items}}));
|
||||
} else {
|
||||
throw jsonrpcpp::InvalidParamsException(*request);
|
||||
}
|
||||
} else if (request->method == rpc_method::pin_file) {
|
||||
if (request->params.param_array.size() == 1u) {
|
||||
const auto api_path = utils::path::create_api_path(request->params.param_array[0]);
|
||||
auto success = provider_.is_file(api_path);
|
||||
if (success) {
|
||||
success = api_error::success ==
|
||||
provider_.set_item_meta(api_path, META_PINNED, utils::string::from_bool(true));
|
||||
}
|
||||
|
||||
if (success) {
|
||||
event_system::instance().raise<file_pinned>(api_path);
|
||||
}
|
||||
|
||||
response = std::make_unique<jsonrpcpp::Response>(*request, json({{"success", success}}));
|
||||
} else {
|
||||
throw jsonrpcpp::InvalidParamsException(*request);
|
||||
}
|
||||
} else if (request->method == rpc_method::pinned_status) {
|
||||
if (request->params.param_array.size() == 1u) {
|
||||
const auto api_path = utils::path::create_api_path(request->params.param_array[0]);
|
||||
std::string pinned;
|
||||
const auto success =
|
||||
api_error::success == provider_.get_item_meta(api_path, META_PINNED, pinned);
|
||||
|
||||
response = std::make_unique<jsonrpcpp::Response>(
|
||||
*request, json({{"success", success},
|
||||
{"pinned", pinned.empty() ? false : utils::string::to_bool(pinned)}}));
|
||||
} else {
|
||||
throw jsonrpcpp::InvalidParamsException(*request);
|
||||
}
|
||||
} else if (request->method == rpc_method::unpin_file) {
|
||||
if (request->params.param_array.size() == 1u) {
|
||||
const auto api_path = utils::path::create_api_path(request->params.param_array[0]);
|
||||
auto success = provider_.is_file(api_path);
|
||||
if (success) {
|
||||
success = api_error::success ==
|
||||
provider_.set_item_meta(api_path, META_PINNED, utils::string::from_bool(false));
|
||||
}
|
||||
|
||||
if (success) {
|
||||
event_system::instance().raise<file_unpinned>(api_path);
|
||||
}
|
||||
|
||||
response = std::make_unique<jsonrpcpp::Response>(*request, json({{"success", success}}));
|
||||
} else {
|
||||
throw jsonrpcpp::InvalidParamsException(*request);
|
||||
}
|
||||
} else if (request->method == rpc_method::get_open_files) {
|
||||
if (request->params.param_array.empty()) {
|
||||
const auto list = oft_.get_open_files();
|
||||
json open_files = {{"file_list", std::vector<json>()}};
|
||||
for (const auto &kv : list) {
|
||||
open_files["file_list"].emplace_back(json({{"path", kv.first}, {"count", kv.second}}));
|
||||
}
|
||||
response = std::make_unique<jsonrpcpp::Response>(*request, open_files);
|
||||
} else {
|
||||
throw jsonrpcpp::InvalidParamsException(*request);
|
||||
}
|
||||
#if defined(REPERTORY_ENABLE_SKYNET)
|
||||
} else if (get_config().get_provider_type() == provider_type::skynet) {
|
||||
if (request->method == rpc_method::import) {
|
||||
if (request->params.param_array.size() == 1) {
|
||||
json results = {{"success", std::vector<json>()}, {"failed", std::vector<std::string>()}};
|
||||
for (const auto &link : request->params.param_array[0]) {
|
||||
const auto si = skylink_import::from_json(link);
|
||||
auto &provider = dynamic_cast<skynet_provider &>(provider_);
|
||||
const auto res = provider.import_skylink(si);
|
||||
if (res == api_error::success) {
|
||||
results["success"].emplace_back(link);
|
||||
} else {
|
||||
results["failed"].emplace_back(link["skylink"].get<std::string>());
|
||||
}
|
||||
}
|
||||
response = std::make_unique<jsonrpcpp::Response>(*request, results);
|
||||
} else {
|
||||
throw jsonrpcpp::InvalidParamsException(*request);
|
||||
}
|
||||
} else if (request->method == rpc_method::export_links) {
|
||||
if (request->params.param_array.empty()) {
|
||||
auto &provider = dynamic_cast<skynet_provider &>(provider_);
|
||||
response = std::make_unique<jsonrpcpp::Response>(*request, provider.export_all());
|
||||
} else if (request->params.param_array.size() == 1) {
|
||||
auto &provider = dynamic_cast<skynet_provider &>(provider_);
|
||||
response = std::make_unique<jsonrpcpp::Response>(
|
||||
*request,
|
||||
provider.export_list(request->params.param_array[0].get<std::vector<std::string>>()));
|
||||
} else {
|
||||
throw jsonrpcpp::InvalidParamsException(*request);
|
||||
}
|
||||
} else {
|
||||
handled = server::handle_request(request, response);
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
handled = server::handle_request(request, response);
|
||||
json items = {{"items", std::vector<json>()}};
|
||||
for (const auto &item : list) {
|
||||
items["items"].emplace_back(item.to_json());
|
||||
}
|
||||
return handled;
|
||||
res.set_content(items.dump(), "application/json");
|
||||
res.status = 200;
|
||||
}
|
||||
|
||||
void full_server::handle_get_drive_information(const httplib::Request & /*req*/,
|
||||
httplib::Response &res) {
|
||||
res.set_content(
|
||||
json({
|
||||
{"cache_space_used",
|
||||
utils::file::calculate_used_space(
|
||||
get_config().get_cache_directory(), false)},
|
||||
{"drive_space_total", provider_.get_total_drive_space()},
|
||||
{"drive_space_used", provider_.get_used_drive_space()},
|
||||
{"item_count", provider_.get_total_item_count()},
|
||||
})
|
||||
.dump(),
|
||||
"application/json");
|
||||
res.status = 200;
|
||||
}
|
||||
|
||||
void full_server::handle_get_open_files(const httplib::Request & /*req*/,
|
||||
httplib::Response &res) {
|
||||
const auto list = fm_.get_open_files();
|
||||
|
||||
json open_files = {{"items", std::vector<json>()}};
|
||||
for (const auto &kv : list) {
|
||||
open_files["items"].emplace_back(json({
|
||||
{"path", kv.first},
|
||||
{"count", kv.second},
|
||||
}));
|
||||
}
|
||||
res.set_content(open_files.dump(), "application/json");
|
||||
res.status = 200;
|
||||
}
|
||||
|
||||
void full_server::handle_get_pinned_files(const httplib::Request & /*req*/,
|
||||
httplib::Response &res) {
|
||||
res.set_content(json({{"items", provider_.get_pinned_files()}}).dump(),
|
||||
"application/json");
|
||||
res.status = 200;
|
||||
}
|
||||
|
||||
void full_server::handle_get_pinned_status(const httplib::Request &req,
|
||||
httplib::Response &res) {
|
||||
const auto api_path =
|
||||
utils::path::create_api_path(req.get_param_value("api_path"));
|
||||
|
||||
std::string pinned;
|
||||
const auto result = provider_.get_item_meta(api_path, META_PINNED, pinned);
|
||||
if (result != api_error::success) {
|
||||
utils::error::raise_api_path_error(__FUNCTION__, api_path, result,
|
||||
"failed to get pinned status");
|
||||
res.status = 500;
|
||||
return;
|
||||
}
|
||||
|
||||
res.set_content(
|
||||
json(
|
||||
{{"pinned", pinned.empty() ? false : utils::string::to_bool(pinned)}})
|
||||
.dump(),
|
||||
"application/json");
|
||||
res.status = 200;
|
||||
}
|
||||
|
||||
void full_server::handle_pin_file(const httplib::Request &req,
|
||||
httplib::Response &res) {
|
||||
const auto api_path =
|
||||
utils::path::create_api_path(req.get_param_value("api_path"));
|
||||
|
||||
bool exists{};
|
||||
auto result = provider_.is_file(api_path, exists);
|
||||
if (result != api_error::success) {
|
||||
utils::error::raise_api_path_error(__FUNCTION__, api_path, result,
|
||||
"failed to pin file");
|
||||
res.status = 500;
|
||||
return;
|
||||
}
|
||||
|
||||
if (exists) {
|
||||
exists = api_error::success ==
|
||||
provider_.set_item_meta(api_path, META_PINNED,
|
||||
utils::string::from_bool(true));
|
||||
}
|
||||
|
||||
if (exists) {
|
||||
event_system::instance().raise<file_pinned>(api_path);
|
||||
}
|
||||
|
||||
res.status = exists ? 200 : 404;
|
||||
}
|
||||
|
||||
void full_server::handle_unpin_file(const httplib::Request &req,
|
||||
httplib::Response &res) {
|
||||
const auto api_path =
|
||||
utils::path::create_api_path(req.get_param_value("api_path"));
|
||||
|
||||
bool exists{};
|
||||
auto result = provider_.is_file(api_path, exists);
|
||||
if (result != api_error::success) {
|
||||
utils::error::raise_api_path_error(__FUNCTION__, api_path, result,
|
||||
"failed to unpin file");
|
||||
res.status = 500;
|
||||
return;
|
||||
}
|
||||
|
||||
if (exists) {
|
||||
exists = api_error::success ==
|
||||
provider_.set_item_meta(api_path, META_PINNED,
|
||||
utils::string::from_bool(false));
|
||||
}
|
||||
|
||||
if (exists) {
|
||||
event_system::instance().raise<file_unpinned>(api_path);
|
||||
}
|
||||
|
||||
res.status = exists ? 200 : 404;
|
||||
}
|
||||
|
||||
void full_server::initialize(httplib::Server &inst) {
|
||||
server::initialize(inst);
|
||||
|
||||
inst.Get("/api/v1/" + rpc_method::get_directory_items,
|
||||
[this](auto &&req, auto &&res) {
|
||||
handle_get_directory_items(std::forward<decltype(req)>(req),
|
||||
std::forward<decltype(res)>(res));
|
||||
});
|
||||
inst.Get("/api/v1/" + rpc_method::get_drive_information,
|
||||
[this](auto &&req, auto &&res) {
|
||||
handle_get_drive_information(std::forward<decltype(req)>(req),
|
||||
std::forward<decltype(res)>(res));
|
||||
});
|
||||
inst.Get("/api/v1/" + rpc_method::get_open_files,
|
||||
[this](auto &&req, auto &&res) {
|
||||
handle_get_open_files(std::forward<decltype(req)>(req),
|
||||
std::forward<decltype(res)>(res));
|
||||
});
|
||||
inst.Get("/api/v1/" + rpc_method::get_pinned_files,
|
||||
[this](auto &&req, auto &&res) {
|
||||
handle_get_pinned_files(std::forward<decltype(req)>(req),
|
||||
std::forward<decltype(res)>(res));
|
||||
});
|
||||
inst.Get("/api/v1/" + rpc_method::pinned_status,
|
||||
[this](auto &&req, auto &&res) {
|
||||
handle_get_pinned_status(std::forward<decltype(req)>(req),
|
||||
std::forward<decltype(res)>(res));
|
||||
});
|
||||
inst.Post("/api/v1/" + rpc_method::pin_file, [this](auto &&req, auto &&res) {
|
||||
handle_pin_file(std::forward<decltype(req)>(req),
|
||||
std::forward<decltype(res)>(res));
|
||||
});
|
||||
inst.Post("/api/v1/" + rpc_method::unpin_file,
|
||||
[this](auto &&req, auto &&res) {
|
||||
handle_unpin_file(std::forward<decltype(req)>(req),
|
||||
std::forward<decltype(res)>(res));
|
||||
});
|
||||
}
|
||||
} // namespace repertory
|
||||
|
Reference in New Issue
Block a user