minor changes
This commit is contained in:
@@ -13,22 +13,18 @@ namespace Managers
|
|||||||
class ActionManager
|
class ActionManager
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ActionManager(char**);
|
ActionManager(char**, int);
|
||||||
|
|
||||||
Models::IcarusAction retrieveIcarusAction() const;
|
Models::IcarusAction retrieveIcarusAction() const;
|
||||||
std::vector<Models::Flags> retrieveFlags() const;
|
|
||||||
std::string retrieveAction() const;
|
|
||||||
private:
|
private:
|
||||||
bool isNumber(std::string);
|
bool isNumber(std::string);
|
||||||
|
|
||||||
void initialize();
|
void initialize();
|
||||||
void validateAction();
|
|
||||||
void validateFlags();
|
void validateFlags();
|
||||||
|
|
||||||
std::vector<std::string> parsedFlags();
|
std::vector<std::string> parsedFlags();
|
||||||
|
|
||||||
void printAction();
|
void printAction();
|
||||||
void printFlags(std::vector<std::string>);
|
|
||||||
void printFlags();
|
void printFlags();
|
||||||
|
|
||||||
std::string action;
|
std::string action;
|
||||||
@@ -41,6 +37,7 @@ namespace Managers
|
|||||||
};
|
};
|
||||||
std::vector<Models::Flags> flags;
|
std::vector<Models::Flags> flags;
|
||||||
char **params;
|
char **params;
|
||||||
|
int paramCount;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ namespace Managers
|
|||||||
class CommitManager
|
class CommitManager
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CommitManager(Models::IcarusAction);
|
CommitManager(Models::IcarusAction&);
|
||||||
|
|
||||||
void commitAction();
|
void commitAction();
|
||||||
|
|
||||||
@@ -25,7 +25,6 @@ namespace Managers
|
|||||||
private:
|
private:
|
||||||
Models::Token parseToken(Models::API);
|
Models::Token parseToken(Models::API);
|
||||||
|
|
||||||
void initializeMapActions();
|
|
||||||
void deleteSong();
|
void deleteSong();
|
||||||
void downloadSong();
|
void downloadSong();
|
||||||
void retrieveObjects();
|
void retrieveObjects();
|
||||||
@@ -39,7 +38,13 @@ namespace Managers
|
|||||||
uploadAct
|
uploadAct
|
||||||
};
|
};
|
||||||
|
|
||||||
std::map<std::string, ActionValues> mapActions;
|
std::map<std::string, ActionValues> mapActions =
|
||||||
|
std::map<std::string, ActionValues>{
|
||||||
|
{"delete", deleteAct}, {"download", downloadAct},
|
||||||
|
{"retrieve", retrieveAct},
|
||||||
|
{"upload", uploadAct}
|
||||||
|
};
|
||||||
|
|
||||||
Models::IcarusAction icaAction;
|
Models::IcarusAction icaAction;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ namespace Models
|
|||||||
std::string genre;
|
std::string genre;
|
||||||
int year;
|
int year;
|
||||||
int duration;
|
int duration;
|
||||||
char *songData;
|
|
||||||
std::string data;
|
std::string data;
|
||||||
std::string songPath;
|
std::string songPath;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ namespace Syncers
|
|||||||
Download(Models::API);
|
Download(Models::API);
|
||||||
Download(std::string);
|
Download(std::string);
|
||||||
|
|
||||||
void downloadSong(int);
|
|
||||||
void downloadSong(const Models::Token token, Models::Song);
|
void downloadSong(const Models::Token token, Models::Song);
|
||||||
private:
|
private:
|
||||||
std::string retrieveUrl(Models::Song);
|
std::string retrieveUrl(Models::Song);
|
||||||
|
|||||||
@@ -18,29 +18,18 @@ namespace Syncers
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Upload();
|
Upload();
|
||||||
Upload(std::string);
|
|
||||||
Upload(Models::API);
|
Upload(Models::API);
|
||||||
Upload(Models::UploadForm);
|
|
||||||
|
|
||||||
void uploadSong();
|
|
||||||
void uploadSong(const Models::Token, Models::Song);
|
void uploadSong(const Models::Token, Models::Song);
|
||||||
private:
|
private:
|
||||||
Managers::FileManager fMgr;
|
Managers::FileManager fMgr;
|
||||||
Models::API api;
|
Models::API api;
|
||||||
Models::Song song;
|
Models::Song song;
|
||||||
std::string apiUrl{""}; // Not being used
|
|
||||||
std::string apiEndPoint{""}; // Not being used
|
|
||||||
std::string songPath; // Not being used
|
|
||||||
std::string url; // Not being used
|
|
||||||
int port{9349}; // Not being used
|
|
||||||
|
|
||||||
std::string retrieveUrl();
|
std::string retrieveUrl();
|
||||||
|
|
||||||
void configureSongDemo();
|
|
||||||
void printSongDetails();
|
void printSongDetails();
|
||||||
void printJsonData(nlohmann::json);
|
void printJsonData(nlohmann::json);
|
||||||
|
|
||||||
nlohmann::json serializeObject(); // Not being used
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -20,7 +20,7 @@ int main(int argc, char** argv)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ActionManager actMgr{argv};
|
ActionManager actMgr{argv, argc};
|
||||||
auto chosenAction = actMgr.retrieveIcarusAction();
|
auto chosenAction = actMgr.retrieveIcarusAction();
|
||||||
|
|
||||||
CommitManager commitMgr{chosenAction};
|
CommitManager commitMgr{chosenAction};
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
#include<algorithm>
|
#include<algorithm>
|
||||||
#include<iostream>
|
#include<iostream>
|
||||||
#include<exception>
|
#include<utility>
|
||||||
#include<cstring>
|
#include<cstring>
|
||||||
|
|
||||||
using std::cout;
|
using std::cout;
|
||||||
@@ -16,10 +16,9 @@ using Models::IcarusAction;
|
|||||||
namespace Managers
|
namespace Managers
|
||||||
{
|
{
|
||||||
#pragma
|
#pragma
|
||||||
ActionManager::ActionManager(char **param)
|
ActionManager::ActionManager(char **param, int paramCount) :
|
||||||
|
params(std::move(param)), paramCount(paramCount)
|
||||||
{
|
{
|
||||||
this->params = param;
|
|
||||||
|
|
||||||
initialize();
|
initialize();
|
||||||
}
|
}
|
||||||
#pragma Constructors
|
#pragma Constructors
|
||||||
@@ -34,15 +33,6 @@ namespace Managers
|
|||||||
|
|
||||||
return icarusAction;
|
return icarusAction;
|
||||||
}
|
}
|
||||||
vector<Flags> ActionManager::retrieveFlags() const
|
|
||||||
{
|
|
||||||
return flags;
|
|
||||||
}
|
|
||||||
|
|
||||||
string ActionManager::retrieveAction() const
|
|
||||||
{
|
|
||||||
return action;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ActionManager::isNumber(string val)
|
bool ActionManager::isNumber(string val)
|
||||||
{
|
{
|
||||||
@@ -57,28 +47,10 @@ namespace Managers
|
|||||||
{
|
{
|
||||||
validateFlags();
|
validateFlags();
|
||||||
|
|
||||||
action = string{params[1]};
|
action = std::move(string{params[1]});
|
||||||
transform(action.begin(), action.end(),
|
transform(action.begin(), action.end(),
|
||||||
action.begin(), ::tolower);
|
action.begin(), ::tolower);
|
||||||
}
|
}
|
||||||
void ActionManager::validateAction()
|
|
||||||
{
|
|
||||||
cout<<"Validating action"<<endl;
|
|
||||||
|
|
||||||
if (std::any_of(supportedActions.begin(), supportedActions.end(),
|
|
||||||
[&](string val)
|
|
||||||
{
|
|
||||||
return !val.compare(action);
|
|
||||||
}))
|
|
||||||
{
|
|
||||||
//cout<<"Action: "<<action<<" is valid"<<endl;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
cout<<"Action is not valid"<<endl;
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
void ActionManager::validateFlags()
|
void ActionManager::validateFlags()
|
||||||
{
|
{
|
||||||
cout<<"Validating flags"<<endl;
|
cout<<"Validating flags"<<endl;
|
||||||
@@ -118,19 +90,10 @@ namespace Managers
|
|||||||
vector<string> ActionManager::parsedFlags()
|
vector<string> ActionManager::parsedFlags()
|
||||||
{
|
{
|
||||||
auto parsed = vector<string>{};
|
auto parsed = vector<string>{};
|
||||||
try
|
|
||||||
|
for (auto i = 2; i < paramCount; ++i)
|
||||||
{
|
{
|
||||||
for (auto i = 2; true; ++i)
|
parsed.push_back(std::move(*(params + i)));
|
||||||
{
|
|
||||||
string val{*(params + i)};
|
|
||||||
//cout<<"Parsed flag "<<val<<endl;
|
|
||||||
parsed.push_back(val);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (std::exception e)
|
|
||||||
{
|
|
||||||
auto msg = e.what();
|
|
||||||
cout<<"This happend: "<<msg<<endl<<endl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return parsed;
|
return parsed;
|
||||||
@@ -148,21 +111,6 @@ namespace Managers
|
|||||||
cout<<"Action is "<<action<<endl;
|
cout<<"Action is "<<action<<endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void ActionManager::printFlags(vector<string> flagVals)
|
|
||||||
{
|
|
||||||
if (flagVals.empty())
|
|
||||||
{
|
|
||||||
printf("Flags and values are empty\n");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("Printing flags and values..\n");
|
|
||||||
for (auto flgVal : flagVals)
|
|
||||||
{
|
|
||||||
cout<<flgVal<<endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
void ActionManager::printFlags()
|
void ActionManager::printFlags()
|
||||||
{
|
{
|
||||||
cout<<"\nPrinting flags..."<<endl;
|
cout<<"\nPrinting flags..."<<endl;
|
||||||
|
|||||||
@@ -34,11 +34,8 @@ using Syncers::Upload;
|
|||||||
namespace Managers
|
namespace Managers
|
||||||
{
|
{
|
||||||
#pragma
|
#pragma
|
||||||
CommitManager::CommitManager(IcarusAction icaAct)
|
CommitManager::CommitManager(IcarusAction& icaAct) : icaAction(std::move(icaAct))
|
||||||
{
|
{ }
|
||||||
icaAction = icaAct;
|
|
||||||
initializeMapActions();
|
|
||||||
}
|
|
||||||
#pragma Constructors;
|
#pragma Constructors;
|
||||||
|
|
||||||
|
|
||||||
@@ -46,7 +43,7 @@ namespace Managers
|
|||||||
void CommitManager::commitAction()
|
void CommitManager::commitAction()
|
||||||
{
|
{
|
||||||
auto action = icaAction.action;
|
auto action = icaAction.action;
|
||||||
cout<<"Commitning "<<action<<" action"<<endl;
|
cout<<"Commiting "<<action<<" action"<<endl;
|
||||||
switch (mapActions[action])
|
switch (mapActions[action])
|
||||||
{
|
{
|
||||||
case deleteAct:
|
case deleteAct:
|
||||||
@@ -55,7 +52,7 @@ namespace Managers
|
|||||||
case downloadAct:
|
case downloadAct:
|
||||||
downloadSong();
|
downloadSong();
|
||||||
break;
|
break;
|
||||||
case retrieveAct: // No plans to imeplement
|
case retrieveAct:
|
||||||
retrieveObjects();
|
retrieveObjects();
|
||||||
break;
|
break;
|
||||||
case uploadAct:
|
case uploadAct:
|
||||||
@@ -75,14 +72,6 @@ namespace Managers
|
|||||||
return tk.requestToken();
|
return tk.requestToken();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CommitManager::initializeMapActions()
|
|
||||||
{
|
|
||||||
mapActions = map<string, ActionValues>{
|
|
||||||
{"delete", deleteAct}, {"download", downloadAct},
|
|
||||||
{"retrieve", retrieveAct},
|
|
||||||
{"upload", uploadAct}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
void CommitManager::deleteSong()
|
void CommitManager::deleteSong()
|
||||||
{
|
{
|
||||||
APIParser apiPrs{icaAction};
|
APIParser apiPrs{icaAction};
|
||||||
|
|||||||
@@ -11,9 +11,8 @@ using Models::IcarusAction;
|
|||||||
namespace Parsers
|
namespace Parsers
|
||||||
{
|
{
|
||||||
#pragma
|
#pragma
|
||||||
APIParser::APIParser(IcarusAction icaAct)
|
APIParser::APIParser(IcarusAction icaAct) : icaAct(icaAct)
|
||||||
{
|
{
|
||||||
this->icaAct = icaAct;
|
|
||||||
api = API{};
|
api = API{};
|
||||||
parseAPI();
|
parseAPI();
|
||||||
}
|
}
|
||||||
@@ -38,7 +37,7 @@ namespace Parsers
|
|||||||
|
|
||||||
if (arg.compare("-h") == 0)
|
if (arg.compare("-h") == 0)
|
||||||
{
|
{
|
||||||
api.url = (value[value.size()-1 == '/']) ? value : value + "/";
|
api.url = (value[value.size()-1] == '/') ? value : value + "/";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -33,26 +33,6 @@ namespace Syncers
|
|||||||
|
|
||||||
|
|
||||||
#pragma
|
#pragma
|
||||||
void Download::downloadSong(const int id)
|
|
||||||
{
|
|
||||||
string urlRoot = "http://192.168.1.5";
|
|
||||||
int port = 9349;
|
|
||||||
string endpoint = "api/song/data/" + std::to_string(id);
|
|
||||||
string url = urlRoot + ":" + std::to_string(port) + "/" +
|
|
||||||
endpoint;
|
|
||||||
auto r = cpr::Get(cpr::Url{url});
|
|
||||||
const char* newBuff = r.text.c_str();
|
|
||||||
int bufferLength = r.text.size();
|
|
||||||
|
|
||||||
ofstream saveSong{downloadFilePath, ofstream::binary};
|
|
||||||
saveSong.write(newBuff, bufferLength);
|
|
||||||
|
|
||||||
cout<<"HTTP status code: "<<r.status_code<<endl;
|
|
||||||
cout<<"Header info: "<<r.header["content-type"]<<endl;
|
|
||||||
cout<<"Header info: "<<endl;
|
|
||||||
cout<<r.header["content-type"]<<endl;
|
|
||||||
cout<<r.header["content-disposition"]<<endl;
|
|
||||||
}
|
|
||||||
void Download::downloadSong(const Token token, Song song)
|
void Download::downloadSong(const Token token, Song song)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|||||||
@@ -6,6 +6,8 @@
|
|||||||
#include <cpr/cpr.h>
|
#include <cpr/cpr.h>
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
|
#include "Utilities/Conversions.h"
|
||||||
|
|
||||||
using std::cout;
|
using std::cout;
|
||||||
using std::endl;
|
using std::endl;
|
||||||
using std::ofstream;
|
using std::ofstream;
|
||||||
@@ -13,6 +15,7 @@ using std::ofstream;
|
|||||||
using Managers::CommitManager;
|
using Managers::CommitManager;
|
||||||
using Models::API;
|
using Models::API;
|
||||||
using Models::Token;
|
using Models::Token;
|
||||||
|
using Utilities::Conversions;
|
||||||
|
|
||||||
namespace Syncers
|
namespace Syncers
|
||||||
{
|
{
|
||||||
|
|||||||
+3
-68
@@ -24,41 +24,12 @@ using namespace cpr;
|
|||||||
namespace Syncers
|
namespace Syncers
|
||||||
{
|
{
|
||||||
Upload::Upload() { }
|
Upload::Upload() { }
|
||||||
Upload::Upload(string filePath)
|
Upload::Upload(API api) : api(api)
|
||||||
{
|
{
|
||||||
this->songPath = filePath;
|
|
||||||
this->fMgr = FileManager(songPath);
|
|
||||||
}
|
|
||||||
Upload::Upload(API api)
|
|
||||||
{
|
|
||||||
this->api = api;
|
|
||||||
this->api.endpoint = "song/data";
|
this->api.endpoint = "song/data";
|
||||||
}
|
}
|
||||||
Upload::Upload(UploadForm formData)
|
|
||||||
{
|
|
||||||
this->url = formData.url;
|
|
||||||
this->songPath = formData.filePath;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Upload::uploadSong()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
auto r = cpr::Post(cpr::Url{url},
|
|
||||||
cpr::Multipart{{"key", "small value"},
|
|
||||||
{"file", cpr::File{songPath}}});
|
|
||||||
cout << r.status_code<< std::endl;
|
|
||||||
|
|
||||||
cout<<"Success"<<endl;
|
|
||||||
}
|
|
||||||
catch(std::exception& e)
|
|
||||||
{
|
|
||||||
cout<<e.what()<<endl;
|
|
||||||
}
|
|
||||||
cout<<"Finished"<<endl;
|
|
||||||
|
|
||||||
}
|
|
||||||
void Upload::uploadSong(const Models::Token token, Song song)
|
void Upload::uploadSong(const Models::Token token, Song song)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@@ -86,33 +57,12 @@ namespace Syncers
|
|||||||
|
|
||||||
string Upload::retrieveUrl()
|
string Upload::retrieveUrl()
|
||||||
{
|
{
|
||||||
string url = api.url + "api/" + api.version + "/" +
|
const string url{api.url + "api/" + api.version + "/" +
|
||||||
api.endpoint;
|
api.endpoint};
|
||||||
|
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
#pragma
|
#pragma
|
||||||
void Upload::configureSongDemo()
|
|
||||||
{
|
|
||||||
int id = 0;
|
|
||||||
string title = "What of it?";
|
|
||||||
string artist = "Kuoth";
|
|
||||||
string album = "I";
|
|
||||||
string genre = "Untitled";
|
|
||||||
int year = 2019;
|
|
||||||
int duration = 260;
|
|
||||||
|
|
||||||
this->song = Models::Song{};
|
|
||||||
this->song.id = id;
|
|
||||||
this->song.title = title;
|
|
||||||
this->song.artist = artist;
|
|
||||||
this->song.album = album;
|
|
||||||
this->song.genre = genre;
|
|
||||||
this->song.year = year;
|
|
||||||
this->song.duration = duration;
|
|
||||||
this->song.songData = fMgr.retrieveFileBuffer();
|
|
||||||
cout<<*song.songData<<endl;
|
|
||||||
}
|
|
||||||
void Upload::printSongDetails()
|
void Upload::printSongDetails()
|
||||||
{
|
{
|
||||||
cout<<"Song details: "<<endl;
|
cout<<"Song details: "<<endl;
|
||||||
@@ -138,21 +88,6 @@ namespace Syncers
|
|||||||
|
|
||||||
cout<<endl<<endl;;
|
cout<<endl<<endl;;
|
||||||
}
|
}
|
||||||
|
|
||||||
json Upload::serializeObject()
|
|
||||||
{
|
|
||||||
json jObj{};
|
|
||||||
jObj["id"] = song.id;
|
|
||||||
jObj["title"] = song.title;
|
|
||||||
jObj["artist"] = song.artist;
|
|
||||||
jObj["album"] = song.album;
|
|
||||||
jObj["genre"] = song.genre;
|
|
||||||
jObj["year"] = song.year;
|
|
||||||
jObj["duration"] = song.duration;
|
|
||||||
jObj["song_data"] = *song.songData;
|
|
||||||
|
|
||||||
return jObj;
|
|
||||||
}
|
|
||||||
#pragma Testing
|
#pragma Testing
|
||||||
#pragma Functions
|
#pragma Functions
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user