Added Controller namespace
This commit is contained in:
@@ -7,6 +7,9 @@
|
||||
Manager::coverArtManager::coverArtManager(const std::string& configPath) : path(configPath)
|
||||
{ }
|
||||
|
||||
Manager::coverArtManager::coverArtManager(const Model::BinaryPath& bConf) : m_bConf(bConf)
|
||||
{ }
|
||||
|
||||
|
||||
Model::Cover Manager::coverArtManager::saveCover(const Model::Song& song, std::string& rootPath, const std::string& stockCoverPath)
|
||||
{
|
||||
@@ -16,7 +19,7 @@ Model::Cover Manager::coverArtManager::saveCover(const Model::Song& song, std::s
|
||||
cov = meta.update_cover_art(song, cov, stockCoverPath);
|
||||
cov.songTitle = song.title;
|
||||
|
||||
Database::coverArtRepository covRepo(path);
|
||||
Database::coverArtRepository covRepo(m_bConf);
|
||||
std::cout << "saving record to the database" << std::endl;
|
||||
covRepo.saveRecord(cov);
|
||||
std::cout << "retrieving record from database" << std::endl;
|
||||
|
||||
@@ -41,10 +41,13 @@ std::string Manager::directory_manager::configPath(std::string_view path)
|
||||
{
|
||||
return fs::canonical(path).parent_path().string();
|
||||
}
|
||||
std::string Manager::directory_manager::contentOfPath(std::string_view path)
|
||||
std::string Manager::directory_manager::configPath(const Model::BinaryPath& bConf)
|
||||
{
|
||||
std::string configPath(path);
|
||||
std::fstream a(configPath, std::ios::in);
|
||||
return fs::canonical(bConf.path).parent_path().string();
|
||||
}
|
||||
std::string Manager::directory_manager::contentOfPath(const std::string& path)
|
||||
{
|
||||
std::fstream a(path, std::ios::in);
|
||||
std::stringstream s;
|
||||
s << a.rdbuf();
|
||||
a.close();
|
||||
@@ -59,6 +62,13 @@ nlohmann::json Manager::directory_manager::credentialConfigContent(const std::st
|
||||
|
||||
return nlohmann::json::parse(contentOfPath(path));
|
||||
}
|
||||
nlohmann::json Manager::directory_manager::credentialConfigContent(const Model::BinaryPath& bConf)
|
||||
{
|
||||
auto path = configPath(bConf);
|
||||
path.append("/authcredentials.json");
|
||||
|
||||
return nlohmann::json::parse(contentOfPath(path));
|
||||
}
|
||||
nlohmann::json Manager::directory_manager::databaseConfigContent(const std::string& exe_path)
|
||||
{
|
||||
auto path = configPath(exe_path);
|
||||
@@ -66,6 +76,13 @@ nlohmann::json Manager::directory_manager::databaseConfigContent(const std::stri
|
||||
|
||||
return nlohmann::json::parse(contentOfPath(path));
|
||||
}
|
||||
nlohmann::json Manager::directory_manager::databaseConfigContent(const Model::BinaryPath& bConf)
|
||||
{
|
||||
auto path = configPath(bConf);
|
||||
path.append("/database.json");
|
||||
|
||||
return nlohmann::json::parse(contentOfPath(path));
|
||||
}
|
||||
nlohmann::json Manager::directory_manager::pathConfigContent(const std::string& exe_path)
|
||||
{
|
||||
auto path = configPath(exe_path);
|
||||
@@ -73,6 +90,13 @@ nlohmann::json Manager::directory_manager::pathConfigContent(const std::string&
|
||||
|
||||
return nlohmann::json::parse(contentOfPath(path));
|
||||
}
|
||||
nlohmann::json Manager::directory_manager::pathConfigContent(const Model::BinaryPath& bConf)
|
||||
{
|
||||
auto path = configPath(bConf);
|
||||
path.append("/paths.json");
|
||||
|
||||
return nlohmann::json::parse(contentOfPath(path));
|
||||
}
|
||||
|
||||
void Manager::directory_manager::delete_cover_art_file(const std::string& cov_path, const std::string& stock_cover_path)
|
||||
{
|
||||
|
||||
@@ -18,6 +18,10 @@ Manager::song_manager::song_manager(std::string& x_path)
|
||||
: exe_path(x_path)
|
||||
{ }
|
||||
|
||||
Manager::song_manager::song_manager(const Model::BinaryPath& bConf)
|
||||
: m_bConf(bConf)
|
||||
{ }
|
||||
|
||||
|
||||
void Manager::song_manager::saveSong(Model::Song& song)
|
||||
{
|
||||
@@ -27,12 +31,12 @@ void Manager::song_manager::saveSong(Model::Song& song)
|
||||
song = meta.retrieve_metadata(song.songPath);
|
||||
song.data = std::move(data);
|
||||
|
||||
coverArtManager covMgr(exe_path);
|
||||
auto pathConfigContent = Manager::directory_manager::pathConfigContent(exe_path);
|
||||
coverArtManager covMgr(m_bConf);
|
||||
auto pathConfigContent = Manager::directory_manager::pathConfigContent(m_bConf);
|
||||
auto coverRootPath = pathConfigContent["cover_root_path"].get<std::string>();
|
||||
auto musicRootPath = pathConfigContent["root_music_path"].get<std::string>();
|
||||
|
||||
auto stockCoverPath = Manager::directory_manager::configPath(exe_path);
|
||||
auto stockCoverPath = Manager::directory_manager::configPath(m_bConf);
|
||||
stockCoverPath.append("/CoverArt.png");
|
||||
|
||||
auto cov = covMgr.saveCover(song, coverRootPath, stockCoverPath);
|
||||
@@ -49,14 +53,14 @@ void Manager::song_manager::saveSong(Model::Song& song)
|
||||
|
||||
printSong(song);
|
||||
|
||||
Database::songRepository songRepo(exe_path);
|
||||
Database::songRepository songRepo(m_bConf);
|
||||
songRepo.saveRecord(song);
|
||||
}
|
||||
|
||||
void Manager::song_manager::deleteSong(Model::Song& song)
|
||||
{
|
||||
Database::coverArtRepository covRepo(exe_path);
|
||||
Database::songRepository songRepo(exe_path);
|
||||
Database::coverArtRepository covRepo(m_bConf);
|
||||
Database::songRepository songRepo(m_bConf);
|
||||
|
||||
song = songRepo.retrieveRecord(song, songFilter::id);
|
||||
songRepo.deleteRecord(song);
|
||||
@@ -66,7 +70,7 @@ void Manager::song_manager::deleteSong(Model::Song& song)
|
||||
cov = covRepo.retrieveRecord(cov, coverFilter::id);
|
||||
covRepo.deleteRecord(cov);
|
||||
|
||||
auto paths = Manager::directory_manager::pathConfigContent(exe_path);
|
||||
auto paths = Manager::directory_manager::pathConfigContent(m_bConf);
|
||||
const auto coverArtPath = paths["cover_root_path"].get<std::string>();
|
||||
std::string stockCoverArtPath = coverArtPath;
|
||||
stockCoverArtPath.append("CoverArt.png");
|
||||
@@ -100,7 +104,7 @@ void Manager::song_manager::printSong(const Model::Song& song)
|
||||
|
||||
void Manager::song_manager::saveSongTemp(Model::Song& song)
|
||||
{
|
||||
auto config = Manager::directory_manager::pathConfigContent(exe_path);
|
||||
auto config = Manager::directory_manager::pathConfigContent(m_bConf);
|
||||
|
||||
auto tmp_song = config["temp_root_path"].get<std::string>();
|
||||
std::random_device dev;
|
||||
|
||||
@@ -57,6 +57,34 @@ Model::loginResult Manager::token_manager::retrieve_token(std::string_view path)
|
||||
|
||||
return lr;
|
||||
}
|
||||
Model::loginResult Manager::token_manager::retrieve_token(const Model::BinaryPath& bConf)
|
||||
{
|
||||
auto cred = parse_auth_credentials(bConf);
|
||||
|
||||
nlohmann::json reqObj;
|
||||
reqObj["client_id"] = cred.client_id;
|
||||
reqObj["client_secret"] = cred.client_secret;
|
||||
reqObj["audience"] = cred.api_identifier;
|
||||
reqObj["grant_type"] = "client_credentials";
|
||||
|
||||
std::string uri{cred.uri};
|
||||
uri.append("/");
|
||||
uri.append(cred.endpoint);
|
||||
|
||||
auto r = cpr::Post(cpr::Url{uri},
|
||||
cpr::Body{reqObj.dump()},
|
||||
cpr::Header{{"Content-Type", "application/json"},
|
||||
{"Connection", "keep-alive"}});
|
||||
|
||||
auto post_res = nlohmann::json::parse(r.text);
|
||||
|
||||
Model::loginResult lr;
|
||||
lr.access_token = post_res["access_token"].get<std::string>();
|
||||
lr.token_type = post_res["token_type"].get<std::string>();
|
||||
lr.expiration = post_res["expires_in"].get<int>();
|
||||
|
||||
return lr;
|
||||
}
|
||||
|
||||
bool Manager::token_manager::is_token_valid(std::string& auth, Scope scope)
|
||||
{
|
||||
@@ -104,10 +132,10 @@ Model::auth_credentials Manager::token_manager::parse_auth_credentials(std::stri
|
||||
|
||||
return auth;
|
||||
}
|
||||
Model::auth_credentials Manager::token_manager::parse_auth_credentials(const BinaryPath& bConf)
|
||||
Model::auth_credentials Manager::token_manager::parse_auth_credentials(const Model::BinaryPath& bConf)
|
||||
{
|
||||
auto exePath = Manager::directory_manager::configPath(bConf);
|
||||
exe_path.append("/auth_credentials.json");
|
||||
exePath.append("/auth_credentials.json");
|
||||
|
||||
auto con = Manager::directory_manager::credentialConfigContent(exePath);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user