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