aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/rclone_uploader.cpp33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/utils/rclone_uploader.cpp b/src/utils/rclone_uploader.cpp
new file mode 100644
index 0000000..5a02697
--- /dev/null
+++ b/src/utils/rclone_uploader.cpp
@@ -0,0 +1,33 @@
+#include <stdexcept>
+#include "rclone_uploader.hpp"
+
+RcloneUploader::~RcloneUploader() = default;
+
+RcloneUploader::RcloneUploader(const std::string& cdnEndpoint,
+ const std::string& sourceName)
+ : cdnEndpoint(cdnEndpoint), sourceName(sourceName)
+{
+ std::string rcloneInstalledCommand;
+ #ifdef _WIN32
+ rcloneInstalledCommand = "where rclone >nul 2>&1";
+ #else
+ rcloneInstalledCommand = "which rclone >/dev/null 2>&1";
+ #endif
+
+ int result = std::system(rcloneInstalledCommand.c_str());
+ if (result != 0) {
+ throw std::runtime_error("rclone is not installed or not in PATH");
+ }
+}
+
+bool RcloneUploader::uploadFile(const std::string& filepath, const std::string& remotePath=""){
+ std::string command = "rclone copy \"" + filepath + "\" " + sourceName + ":" + remotePath + " 2>/dev/null 1>/dev/null";
+ int result = std::system(command.c_str());
+ return result == 0;
+}
+
+bool RcloneUploader::testConnection(){
+ std::string command = "rclone ls " + sourceName + ": 2>/dev/null 1>/dev/null";
+ int result = std::system(command.c_str());
+ return result == 0;
+}
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage