aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils/rclone_uploader.cpp
blob: 5a02697a3e08774a7607d64c99dd99d38708a954 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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