Skip to content

Commit

Permalink
add captions
Browse files Browse the repository at this point in the history
  • Loading branch information
bakatrouble committed Apr 24, 2020
1 parent b4b6744 commit 1b3b5b5
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 1 deletion.
4 changes: 4 additions & 0 deletions config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
18 changes: 18 additions & 0 deletions src/config.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#include <iostream>
#include <inih.h>
#include <set>
#include <sstream>
#include "config.hpp"
#include "utils.hpp"

using namespace std;

Expand Down Expand Up @@ -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;
}

Expand All @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions src/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class Config {
bool refresh();

string getUrl(string &tid);
string getUrlParams();
bool uploadAllowed(string &tid, bool isMovie);

protected:
Expand All @@ -25,4 +26,5 @@ class Config {
map<string, string> m_titleSettings;
map<string, bool> m_titleScreenshots;
map<string, bool> m_titleMovies;
map<string, string> m_urlParams;
};
2 changes: 1 addition & 1 deletion src/upload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
21 changes: 21 additions & 0 deletions src/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
1 change: 1 addition & 0 deletions src/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ namespace fs = filesystem;

string getLastAlbumItem(Config &conf);
size_t filesize(string &path);
string url_encode(const string &value);

0 comments on commit 1b3b5b5

Please sign in to comment.