From 1b3b5b50fcce5bdcf9784d2785cd152d7867e4f1 Mon Sep 17 00:00:00 2001 From: bakatrouble Date: Sat, 25 Apr 2020 01:20:56 +0300 Subject: [PATCH] add captions --- config.ini | 4 ++++ src/config.cpp | 18 ++++++++++++++++++ src/config.hpp | 2 ++ src/upload.cpp | 2 +- src/utils.cpp | 21 +++++++++++++++++++++ src/utils.hpp | 1 + 6 files changed, 47 insertions(+), 1 deletion(-) diff --git a/config.ini b/config.ini index c849565..23b2400 100644 --- a/config.ini +++ b/config.ini @@ -23,3 +23,7 @@ upload_movies = true [destinations] default = 2574edc6-f3ac-4f49-8d8e-35657ac0fce4 + +[url_params] +; uncomment the following line to add a caption for your uploaded media +; caption = here goes the caption diff --git a/src/config.cpp b/src/config.cpp index 9ef8442..7082952 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -1,7 +1,9 @@ #include #include #include +#include #include "config.hpp" +#include "utils.hpp" using namespace std; @@ -56,6 +58,12 @@ bool Config::refresh() { m_url = reader.Get("server", "url", "https://screenuploader.bakatrouble.me/upload/" + URLplaceholder + "/"); + if (reader.Sections().count("url_params") > 0) { + for (auto &key : reader.Fields("url_params")) { + m_urlParams[key] = reader.Get("url_params", key, ""); + } + } + return true; } @@ -72,6 +80,16 @@ string Config::getUrl(string &tid) { return url; } +string Config::getUrlParams() { + if (m_urlParams.empty()) + return ""; + stringstream ss; + for (auto &urlParam : m_urlParams) { + ss << "&" << url_encode(urlParam.first) << "=" << url_encode(urlParam.second); + } + return ss.str(); +} + bool Config::uploadAllowed(string &tid, bool isMovie) { if (isMovie) { if (m_titleMovies.count(tid) > 0) diff --git a/src/config.hpp b/src/config.hpp index c23adc2..43296e3 100644 --- a/src/config.hpp +++ b/src/config.hpp @@ -15,6 +15,7 @@ class Config { bool refresh(); string getUrl(string &tid); + string getUrlParams(); bool uploadAllowed(string &tid, bool isMovie); protected: @@ -25,4 +26,5 @@ class Config { map m_titleSettings; map m_titleScreenshots; map m_titleMovies; + map m_urlParams; }; diff --git a/src/upload.cpp b/src/upload.cpp index a25ed4e..0f69a27 100644 --- a/src/upload.cpp +++ b/src/upload.cpp @@ -50,7 +50,7 @@ bool sendFileToServer(Config &conf, string &path, size_t size) { CURL *curl = curl_easy_init(); if (curl) { stringstream url; - url << conf.getUrl(tid) << "?filename=" << fpath.filename().string(); + url << conf.getUrl(tid) << "?filename=" << fpath.filename().string() << conf.getUrlParams() ; cout << "Upload URL: " << url.str() << endl; curl_easy_setopt(curl, CURLOPT_URL, url.str().c_str()); curl_easy_setopt(curl, CURLOPT_POST, 1L); diff --git a/src/utils.cpp b/src/utils.cpp index 316fcdc..d41b6ca 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -56,3 +56,24 @@ size_t filesize(string &path) { f.close(); return end - begin; } + +string url_encode(const string &value) { + ostringstream escaped; + escaped.fill('0'); + escaped << hex; + + for (char c : value) { + // Keep alphanumeric and other accepted characters intact + if (isalnum(c) || c == '-' || c == '_' || c == '.' || c == '~') { + escaped << c; + continue; + } + + // Any other characters are percent-encoded + escaped << uppercase; + escaped << '%' << setw(2) << int((unsigned char) c); + escaped << nouppercase; + } + + return escaped.str(); +} diff --git a/src/utils.hpp b/src/utils.hpp index 23b1df3..7e7ef95 100644 --- a/src/utils.hpp +++ b/src/utils.hpp @@ -9,3 +9,4 @@ namespace fs = filesystem; string getLastAlbumItem(Config &conf); size_t filesize(string &path); +string url_encode(const string &value);