Prompt user when uploading songs from a directory

This commit is contained in:
kdeng00
2019-11-11 22:54:53 -05:00
parent 9d8122df5c
commit 996b84c25c
2 changed files with 37 additions and 1 deletions
+7
View File
@@ -14,6 +14,13 @@ namespace Syncers
const int OK = 200; const int OK = 200;
const int UNAUTHORIZED = 401; const int UNAUTHORIZED = 401;
const int NOTFOUND = 404; const int NOTFOUND = 404;
enum class Result
{
OK = 200,
UNAUTHORIZED = 401,
NOTFOUND = 404
};
}; };
} }
+30 -1
View File
@@ -8,6 +8,7 @@
#include"Syncers/Upload.h" #include"Syncers/Upload.h"
using std::cout; using std::cout;
using std::cin;
using std::endl; using std::endl;
using std::exception; using std::exception;
using std::string; using std::string;
@@ -46,6 +47,7 @@ namespace Syncers
); );
cout << "status code: " << r.status_code<< std::endl; cout << "status code: " << r.status_code<< std::endl;
cout << r.text << endl;
auto result = nlohmann::json::parse(r.text); auto result = nlohmann::json::parse(r.text);
cout<<"Finished"<<endl; cout<<"Finished"<<endl;
song.id = result["id"].get<int>(); song.id = result["id"].get<int>();
@@ -59,7 +61,7 @@ namespace Syncers
return song; return song;
} }
catch (exception e) catch (exception& e)
{ {
auto msg = e.what(); auto msg = e.what();
cout<<msg<<endl; cout<<msg<<endl;
@@ -75,6 +77,33 @@ namespace Syncers
try try
{ {
auto songs = retrieveAllSongsFromDirectory(directory, recursive); auto songs = retrieveAllSongsFromDirectory(directory, recursive);
auto confirmUpload = false;
while (true)
{
auto answer = 'a';
cout << "are you sure you want to upload " << songs.size() << " songs? [y/n]";
cin >> answer;
if (answer == 'y' || answer == 'Y')
{
confirmUpload = true;
break;
}
else if (answer == 'n' || answer == 'N')
{
confirmUpload = false;
break;
}
}
if (!confirmUpload)
{
cout << "exiting...\n";
std::exit(-1);
}
cout << "uploading songs\n";
for (auto& song: songs) for (auto& song: songs)
{ {
song = uploadSong(token, song); song = uploadSong(token, song);