Skip to content
This repository has been archived by the owner on Apr 1, 2024. It is now read-only.

Commit

Permalink
added: file info API
Browse files Browse the repository at this point in the history
  • Loading branch information
nexan-pro committed Mar 9, 2019
1 parent f8a2e02 commit e67f5ef
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 8 deletions.
3 changes: 2 additions & 1 deletion json_handler/JHandler.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "JHandler.h"

JHandler::JHandler(std::string &cfg){
JHandler::JHandler(std::string &cfg) {
status = false;
pjson::document doc;
try {
if (doc.deserialize_in_place(const_cast<char*>(cfg.c_str()))) {
Expand Down
3 changes: 0 additions & 3 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ int main(int argc, char** argv) {
std::string id = static_cast<std::string>(argv[2]);
SendReceiver ctrl;
ctrl.getInfoReq(id);

}
else if (argc == 2) {
strcpy(filename, argv[1]);
Expand All @@ -29,8 +28,6 @@ int main(int argc, char** argv) {
<< "File path must be without spaces.\n";
return -1;
}


std::cout << "Press ENTER to exit.\n";
std::cin.get();
return 0;
Expand Down
35 changes: 32 additions & 3 deletions sendReceiver/sendReceiver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,43 @@ bool SendReceiver::uploadFile(char*& pathToFile) {
return status;
}

bool SendReceiver::getInfoReq(std::string& id) {
std::string SendReceiver::sendInfoRequest(std::string& id) {
std::string data;
std::string link = "https://anonfile.com/api/v2/file/" + static_cast<std::string>(id) + "/info";
CURL* curl = curl_easy_init();
CURLcode res;
if (curl) {
curl_easy_setopt(curl, CURLOPT_URL, link.c_str());
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &writeCallback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &data);

res = curl_easy_perform(curl);
if (res != CURLE_OK)
std::cout << "Error, check your internet connection!\n";
}
curl_easy_cleanup(curl);
return data;
}

bool SendReceiver::getInfoReq(std::string& id) {
try {
(id.empty() || id.size() == 0) ? throw std::string("Error, NULLPTR exception!") : 0;
std::string request_data = sendInfoRequest(id);
#ifdef DEBUG
std::cout << "[DEBUG|getInfoReq] : request_data is: " << request_data << std::endl;
#endif
SendReceiver handler(request_data);
handler.printRequestData();
} catch (const std::string str) {
std::cout << str << std::endl;
}
return true;
}

void SendReceiver::printRequestData() {
if (status) {
std::cout << "File was uploaded successfully!\n"
<< "Full url to file: " << url_ptr->str_full
std::cout << "Full url to file: " << url_ptr->str_full
<< "\nShort url to file: " << url_ptr->str_short
<< "\nFile id: " << MD_ptr->id
<< "\nFilename: " << MD_ptr->name
Expand Down
3 changes: 2 additions & 1 deletion sendReceiver/sendReceiver.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
#define ANONFILE_SENDER_H

#define LINUX
#define DEBUG
//#define DEBUG

#include "../helpers/helpers.h"
#include "../json_handler/JHandler.h"

class SendReceiver : protected Helpers, protected JHandler {
private:
static size_t writeCallback(char* buf, size_t size, size_t nmemb, void* up);
std::string sendInfoRequest(std::string& id);
void printRequestData();
public:
explicit SendReceiver(std::string cfg) : JHandler(cfg) { }
Expand Down

0 comments on commit e67f5ef

Please sign in to comment.