Added Manager namespace
This commit is contained in:
@@ -26,7 +26,7 @@ public:
|
||||
{
|
||||
OATPP_LOGI("icarus", "logging in");
|
||||
|
||||
token_manager tok;
|
||||
Manager::token_manager tok;
|
||||
auto token = tok.retrieve_token(exe_path);
|
||||
|
||||
auto logRes = loginResultDto::createShared();
|
||||
|
||||
@@ -46,7 +46,7 @@ public:
|
||||
|
||||
auto auth = authHeader->std_str();
|
||||
|
||||
token_manager tok;
|
||||
Manager::token_manager tok;
|
||||
OATPP_ASSERT_HTTP(tok.is_token_valid(auth, Scope::upload), Status::CODE_403, "Not allowed");
|
||||
|
||||
auto mp = std::make_shared<oatpp::web::mime::multipart::Multipart>(request->getHeaders());
|
||||
@@ -69,7 +69,7 @@ public:
|
||||
Model::Song sng;
|
||||
sng.data = std::move(data);
|
||||
|
||||
song_manager s_mgr(m_exe_path);
|
||||
Manager::song_manager s_mgr(m_exe_path);
|
||||
s_mgr.saveSong(sng);
|
||||
|
||||
return createResponse(Status::CODE_200, "OK");
|
||||
@@ -159,7 +159,7 @@ public:
|
||||
Model::Song song;
|
||||
song.id = id;
|
||||
|
||||
song_manager sngMgr(m_exe_path);
|
||||
Manager::song_manager sngMgr(m_exe_path);
|
||||
sngMgr.deleteSong(song);
|
||||
|
||||
return createResponse(Status::CODE_200, "OK");
|
||||
|
||||
@@ -51,7 +51,7 @@ MYSQL_RES* base_repository::perform_mysql_query(MYSQL *conn, const std::string&
|
||||
|
||||
void base_repository::intitalizeDetails()
|
||||
{
|
||||
auto databaseConfig = directory_manager::databaseConfigContent(path);
|
||||
auto databaseConfig = Manager::directory_manager::databaseConfigContent(path);
|
||||
|
||||
details.database = databaseConfig["database"].get<std::string>();
|
||||
details.password = databaseConfig["password"].get<std::string>();
|
||||
|
||||
@@ -4,11 +4,11 @@
|
||||
#include "types/coverFilter.h"
|
||||
#include "utilities/metadata_retriever.h"
|
||||
|
||||
coverArtManager::coverArtManager(const std::string& configPath) : path(configPath)
|
||||
Manager::coverArtManager::coverArtManager(const std::string& configPath) : path(configPath)
|
||||
{ }
|
||||
|
||||
|
||||
Model::Cover coverArtManager::saveCover(const Model::Song& song, std::string& rootPath, const std::string& stockCoverPath)
|
||||
Model::Cover Manager::coverArtManager::saveCover(const Model::Song& song, std::string& rootPath, const std::string& stockCoverPath)
|
||||
{
|
||||
metadata_retriever meta;
|
||||
Model::Cover cov;
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
std::string directory_manager::create_directory_process(Model::Song song, const std::string& root_path)
|
||||
std::string Manager::directory_manager::create_directory_process(Model::Song song, const std::string& root_path)
|
||||
{
|
||||
auto curr_path = fs::path(root_path);
|
||||
|
||||
@@ -37,11 +37,11 @@ std::string directory_manager::create_directory_process(Model::Song song, const
|
||||
return alb_path.string() + "/";
|
||||
}
|
||||
|
||||
std::string directory_manager::configPath(std::string_view path)
|
||||
std::string Manager::directory_manager::configPath(std::string_view path)
|
||||
{
|
||||
return fs::canonical(path).parent_path().string();
|
||||
}
|
||||
std::string directory_manager::contentOfPath(std::string_view path)
|
||||
std::string Manager::directory_manager::contentOfPath(std::string_view path)
|
||||
{
|
||||
std::string configPath(path);
|
||||
std::fstream a(configPath, std::ios::in);
|
||||
@@ -52,21 +52,21 @@ std::string directory_manager::contentOfPath(std::string_view path)
|
||||
return s.str();
|
||||
}
|
||||
|
||||
nlohmann::json directory_manager::credentialConfigContent(const std::string& exe_path)
|
||||
nlohmann::json Manager::directory_manager::credentialConfigContent(const std::string& exe_path)
|
||||
{
|
||||
auto path = configPath(exe_path);
|
||||
path.append("/authcredentials.json");
|
||||
|
||||
return nlohmann::json::parse(contentOfPath(path));
|
||||
}
|
||||
nlohmann::json directory_manager::databaseConfigContent(const std::string& exe_path)
|
||||
nlohmann::json Manager::directory_manager::databaseConfigContent(const std::string& exe_path)
|
||||
{
|
||||
auto path = configPath(exe_path);
|
||||
path.append("/database.json");
|
||||
|
||||
return nlohmann::json::parse(contentOfPath(path));
|
||||
}
|
||||
nlohmann::json directory_manager::pathConfigContent(const std::string& exe_path)
|
||||
nlohmann::json Manager::directory_manager::pathConfigContent(const std::string& exe_path)
|
||||
{
|
||||
auto path = configPath(exe_path);
|
||||
path.append("/paths.json");
|
||||
@@ -74,7 +74,7 @@ nlohmann::json directory_manager::pathConfigContent(const std::string& exe_path)
|
||||
return nlohmann::json::parse(contentOfPath(path));
|
||||
}
|
||||
|
||||
void directory_manager::delete_cover_art_file(const std::string& cov_path, const std::string& stock_cover_path)
|
||||
void Manager::directory_manager::delete_cover_art_file(const std::string& cov_path, const std::string& stock_cover_path)
|
||||
{
|
||||
if (cov_path.compare(stock_cover_path) == 0) {
|
||||
std::cout << "cover has stock cover art, will not deleted" << std::endl;
|
||||
@@ -84,7 +84,7 @@ void directory_manager::delete_cover_art_file(const std::string& cov_path, const
|
||||
fs::remove(cov);
|
||||
}
|
||||
}
|
||||
void directory_manager::delete_directories(Model::Song song, const std::string& root_path)
|
||||
void Manager::directory_manager::delete_directories(Model::Song song, const std::string& root_path)
|
||||
{
|
||||
std::cout<<"checking to for empty directories to delete"<<std::endl;
|
||||
const std::string art{root_path + std::string{"/"} + song.artist};
|
||||
@@ -109,7 +109,7 @@ void directory_manager::delete_directories(Model::Song song, const std::string&
|
||||
|
||||
std::cout<<"deleted empty directory or directories"<<std::endl;
|
||||
}
|
||||
void directory_manager::delete_song(const Model::Song song)
|
||||
void Manager::directory_manager::delete_song(const Model::Song song)
|
||||
{
|
||||
std::cout<<"deleting song"<<std::endl;
|
||||
auto song_path = fs::path(song.songPath);
|
||||
|
||||
@@ -14,12 +14,12 @@
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
song_manager::song_manager(std::string& x_path)
|
||||
Manager::song_manager::song_manager(std::string& x_path)
|
||||
: exe_path(x_path)
|
||||
{ }
|
||||
|
||||
|
||||
void song_manager::saveSong(Model::Song& song)
|
||||
void Manager::song_manager::saveSong(Model::Song& song)
|
||||
{
|
||||
saveSongTemp(song);
|
||||
metadata_retriever meta;
|
||||
@@ -28,17 +28,17 @@ void song_manager::saveSong(Model::Song& song)
|
||||
song.data = std::move(data);
|
||||
|
||||
coverArtManager covMgr(exe_path);
|
||||
auto pathConfigContent = directory_manager::pathConfigContent(exe_path);
|
||||
auto pathConfigContent = Manager::directory_manager::pathConfigContent(exe_path);
|
||||
auto coverRootPath = pathConfigContent["cover_root_path"].get<std::string>();
|
||||
auto musicRootPath = pathConfigContent["root_music_path"].get<std::string>();
|
||||
|
||||
auto stockCoverPath = directory_manager::configPath(exe_path);
|
||||
auto stockCoverPath = Manager::directory_manager::configPath(exe_path);
|
||||
stockCoverPath.append("/CoverArt.png");
|
||||
|
||||
auto cov = covMgr.saveCover(song, coverRootPath, stockCoverPath);
|
||||
song.coverArtId = cov.id;
|
||||
|
||||
auto songPath = directory_manager::create_directory_process(song, musicRootPath);
|
||||
auto songPath = Manager::directory_manager::create_directory_process(song, musicRootPath);
|
||||
songPath.append(song.title);
|
||||
songPath.append(".mp3");
|
||||
std::cout << "\n\ntemp path: " << song.songPath << std::endl;
|
||||
@@ -53,7 +53,7 @@ void song_manager::saveSong(Model::Song& song)
|
||||
songRepo.saveRecord(song);
|
||||
}
|
||||
|
||||
void song_manager::deleteSong(Model::Song& song)
|
||||
void Manager::song_manager::deleteSong(Model::Song& song)
|
||||
{
|
||||
coverArtRepository covRepo(exe_path);
|
||||
songRepository songRepo(exe_path);
|
||||
@@ -66,7 +66,7 @@ void song_manager::deleteSong(Model::Song& song)
|
||||
cov = covRepo.retrieveRecord(cov, coverFilter::id);
|
||||
covRepo.deleteRecord(cov);
|
||||
|
||||
auto paths = directory_manager::pathConfigContent(exe_path);
|
||||
auto paths = Manager::directory_manager::pathConfigContent(exe_path);
|
||||
const auto coverArtPath = paths["cover_root_path"].get<std::string>();
|
||||
std::string stockCoverArtPath = coverArtPath;
|
||||
stockCoverArtPath.append("CoverArt.png");
|
||||
@@ -77,11 +77,11 @@ void song_manager::deleteSong(Model::Song& song)
|
||||
}
|
||||
fs::remove(song.songPath);
|
||||
|
||||
directory_manager::delete_directories(song, paths["root_music_path"].get<std::string>());
|
||||
directory_manager::delete_directories(song, coverArtPath);
|
||||
Manager::directory_manager::delete_directories(song, paths["root_music_path"].get<std::string>());
|
||||
Manager::directory_manager::delete_directories(song, coverArtPath);
|
||||
}
|
||||
|
||||
void song_manager::printSong(const Model::Song& song)
|
||||
void Manager::song_manager::printSong(const Model::Song& song)
|
||||
{
|
||||
std::cout << "\n\nsong" << std::endl;
|
||||
std::cout << "title: " << song.title << std::endl;
|
||||
@@ -98,9 +98,9 @@ void song_manager::printSong(const Model::Song& song)
|
||||
}
|
||||
}
|
||||
|
||||
void song_manager::saveSongTemp(Model::Song& song)
|
||||
void Manager::song_manager::saveSongTemp(Model::Song& song)
|
||||
{
|
||||
auto config = directory_manager::pathConfigContent(exe_path);
|
||||
auto config = Manager::directory_manager::pathConfigContent(exe_path);
|
||||
|
||||
auto tmp_song = config["temp_root_path"].get<std::string>();
|
||||
std::random_device dev;
|
||||
|
||||
@@ -17,11 +17,11 @@
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
|
||||
token_manager::token_manager()
|
||||
Manager::token_manager::token_manager()
|
||||
{
|
||||
}
|
||||
|
||||
Model::loginResult token_manager::retrieve_token()
|
||||
Model::loginResult Manager::token_manager::retrieve_token()
|
||||
{
|
||||
Model::loginResult lr;
|
||||
lr.access_token = "dsfdsf";
|
||||
@@ -29,7 +29,7 @@ Model::loginResult token_manager::retrieve_token()
|
||||
|
||||
return lr;
|
||||
}
|
||||
Model::loginResult token_manager::retrieve_token(std::string_view path)
|
||||
Model::loginResult Manager::token_manager::retrieve_token(std::string_view path)
|
||||
{
|
||||
auto cred = parse_auth_credentials(path);
|
||||
|
||||
@@ -58,7 +58,7 @@ Model::loginResult token_manager::retrieve_token(std::string_view path)
|
||||
return lr;
|
||||
}
|
||||
|
||||
bool token_manager::is_token_valid(std::string& auth, Scope scope)
|
||||
bool Manager::token_manager::is_token_valid(std::string& auth, Scope scope)
|
||||
{
|
||||
auto authPair = fetch_auth_header(auth);
|
||||
|
||||
@@ -87,12 +87,12 @@ bool token_manager::is_token_valid(std::string& auth, Scope scope)
|
||||
return false;
|
||||
}
|
||||
|
||||
Model::auth_credentials token_manager::parse_auth_credentials(std::string_view path)
|
||||
Model::auth_credentials Manager::token_manager::parse_auth_credentials(std::string_view path)
|
||||
{
|
||||
auto exe_path = directory_manager::configPath(path);
|
||||
auto exe_path = Manager::directory_manager::configPath(path);
|
||||
exe_path.append("/authcredentials.json");
|
||||
|
||||
auto con = directory_manager::credentialConfigContent(exe_path);
|
||||
auto con = Manager::directory_manager::credentialConfigContent(exe_path);
|
||||
|
||||
Model::auth_credentials auth;
|
||||
auth.uri = "https://";
|
||||
@@ -105,7 +105,7 @@ Model::auth_credentials token_manager::parse_auth_credentials(std::string_view p
|
||||
return auth;
|
||||
}
|
||||
|
||||
std::vector<std::string> token_manager::extract_scopes(const jwt::decoded_jwt&& decoded)
|
||||
std::vector<std::string> Manager::token_manager::extract_scopes(const jwt::decoded_jwt&& decoded)
|
||||
{
|
||||
std::vector<std::string> scopes;
|
||||
|
||||
@@ -123,7 +123,7 @@ std::vector<std::string> token_manager::extract_scopes(const jwt::decoded_jwt&&
|
||||
return scopes;
|
||||
}
|
||||
|
||||
std::pair<bool, std::vector<std::string>> token_manager::fetch_auth_header(const std::string& auth)
|
||||
std::pair<bool, std::vector<std::string>> Manager::token_manager::fetch_auth_header(const std::string& auth)
|
||||
{
|
||||
std::istringstream iss(auth);
|
||||
std::vector<std::string> authHeader{std::istream_iterator<std::string>(iss),
|
||||
@@ -142,7 +142,7 @@ std::pair<bool, std::vector<std::string>> token_manager::fetch_auth_header(const
|
||||
return std::make_pair(foundBearer, authHeader);
|
||||
}
|
||||
|
||||
bool token_manager::token_supports_scope(const std::vector<std::string> scopes, const std::string&& scope)
|
||||
bool Manager::token_manager::token_supports_scope(const std::vector<std::string> scopes, const std::string&& scope)
|
||||
{
|
||||
return std::any_of(scopes.begin(), scopes.end(),
|
||||
[&](std::string foundScope) {
|
||||
|
||||
@@ -76,8 +76,8 @@ Model::Cover metadata_retriever::update_cover_art(const Model::Song& song, Model
|
||||
} else {
|
||||
auto frame = dynamic_cast<TagLib::ID3v2::AttachedPictureFrame*>(
|
||||
frameList.front());
|
||||
directory_manager dir;
|
||||
auto img_path = dir.create_directory_process(song, cov.imagePath);
|
||||
|
||||
auto img_path = Manager::directory_manager::create_directory_process(song, cov.imagePath);
|
||||
img_path.append(song.title);
|
||||
img_path.append(".png");
|
||||
cov.imagePath = img_path;
|
||||
|
||||
Reference in New Issue
Block a user