Made some more changes
This commit is contained in:
+4
-6
@@ -5,6 +5,8 @@ project(icarus)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
|
||||
|
||||
set(SOURCES
|
||||
src/callback/StreamCallback.cpp
|
||||
src/database/AlbumRepository.cpp
|
||||
@@ -15,7 +17,6 @@ set(SOURCES
|
||||
src/database/SongRepository.cpp
|
||||
src/database/UserRepository.cpp
|
||||
src/database/YearRepository.cpp
|
||||
# src/dto/conversion/DtoConversions.cpp
|
||||
src/Main.cpp
|
||||
src/manager/AlbumManager.cpp
|
||||
src/manager/ArtistManager.cpp
|
||||
@@ -29,7 +30,6 @@ set(SOURCES
|
||||
src/utility/ImageFile.cpp
|
||||
src/utility/MetadataRetriever.cpp
|
||||
src/utility/PasswordEncryption.cpp
|
||||
src/verify/Initialization.cpp
|
||||
)
|
||||
|
||||
|
||||
@@ -46,7 +46,6 @@ set (BCRYPTLIB
|
||||
|
||||
include_directories(${ICARUS_INCLUDE_DIR} ${BCRYPTLIB})
|
||||
|
||||
# add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/oatpp)
|
||||
|
||||
add_library(bcrypt STATIC IMPORTED)
|
||||
|
||||
@@ -59,7 +58,6 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/authcredentials.json ${CMAKE_BINARY_D
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/database.json ${CMAKE_BINARY_DIR}/bin/database.json COPYONLY)
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/paths.json ${CMAKE_BINARY_DIR}/bin/paths.json COPYONLY)
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Images/Stock/CoverArt.png ${CMAKE_BINARY_DIR}/bin/CoverArt.png COPYONLY)
|
||||
# configure_file(${CMAKE_CURRENT_SOURCE_DIR}/build/icarus ${CMAKE_BINARY_DIR}/bin/icarus COPYONLY)
|
||||
|
||||
find_path(JWT_CPP_INCLUDE_DIRS "jwt-cpp/base.h")
|
||||
|
||||
@@ -67,10 +65,10 @@ find_package(nlohmann_json CONFIG REQUIRED)
|
||||
find_package(cpr CONFIG REQUIRED)
|
||||
find_package(oatpp CONFIG REQUIRED)
|
||||
|
||||
|
||||
|
||||
add_executable(icarus ${SOURCES})
|
||||
|
||||
|
||||
|
||||
|
||||
target_include_directories(icarus PRIVATE ${JWT_CPP_INCLUDE_DIRS})
|
||||
target_link_libraries(icarus PRIVATE "-lstdc++fs" oatpp::oatpp tag mariadb nlohmann_json nlohmann_json::nlohmann_json cpr bcrypt)
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
#include <memory>
|
||||
|
||||
#include "oatpp/core/macro/component.hpp"
|
||||
// #include "oatpp/network/server/SimpleTCPConnectionProvider.hpp"
|
||||
#include "oatpp/network/tcp/server/ConnectionProvider.hpp"
|
||||
#include "oatpp/parser/json/mapping/ObjectMapper.hpp"
|
||||
#include "oatpp/web/server/HttpConnectionHandler.hpp"
|
||||
@@ -15,8 +14,7 @@ namespace component {
|
||||
OATPP_CREATE_COMPONENT(std::shared_ptr<oatpp::network::ServerConnectionProvider>,
|
||||
serverConnectionProvider)([&]
|
||||
{
|
||||
// return oatpp::network::tcp::server::ConnectionProvider::createShared({"localhost", appPort(), oatpp::network::Address::IP_4});
|
||||
return oatpp::network::tcp::server::ConnectionProvider::createShared({"localhost", appPort<v_uint16>(), oatpp::network::Address::IP_4});
|
||||
return oatpp::network::tcp::server::ConnectionProvider::createShared({"127.0.0.1", appPort<v_uint16>(), oatpp::network::Address::IP_4});
|
||||
}());
|
||||
|
||||
OATPP_CREATE_COMPONENT(std::shared_ptr<oatpp::web::server::HttpRouter>, httpRouter)([]
|
||||
@@ -39,8 +37,7 @@ namespace component {
|
||||
}());
|
||||
private:
|
||||
template<typename Val>
|
||||
// constexpr Val appPort() noexcept
|
||||
Val appPort() noexcept
|
||||
constexpr Val appPort() noexcept
|
||||
{
|
||||
return 5002;
|
||||
}
|
||||
|
||||
@@ -48,8 +48,6 @@ namespace controller
|
||||
return createDtoResponse(Status::CODE_401, logRes);
|
||||
}
|
||||
|
||||
std::cout << "user exists\n";
|
||||
|
||||
manager::TokenManager tok;
|
||||
auto token = tok.retrieveToken(m_bConf);
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
#include "oatpp/core/macro/codegen.hpp"
|
||||
#include "oatpp/core/macro/component.hpp"
|
||||
#include "oatpp/core/Types.hpp"
|
||||
#include "oatpp/web/server/api/ApiController.hpp"
|
||||
|
||||
#include "dto/LoginResultDto.hpp"
|
||||
@@ -13,20 +14,30 @@
|
||||
#include "manager/UserManager.h"
|
||||
#include "model/Models.h"
|
||||
|
||||
namespace controller {
|
||||
class RegisterController : public oatpp::web::server::api::ApiController {
|
||||
using namespace dto;
|
||||
|
||||
namespace controller
|
||||
{
|
||||
class RegisterController : public oatpp::web::server::api::ApiController
|
||||
{
|
||||
public:
|
||||
RegisterController(const model::BinaryPath& bConf,
|
||||
OATPP_COMPONENT(std::shared_ptr<ObjectMapper>, objectMapper)) :
|
||||
oatpp::web::server::api::ApiController(objectMapper), m_bConf(bConf) { }
|
||||
oatpp::web::server::api::ApiController(objectMapper),
|
||||
m_bConf(bConf)
|
||||
{
|
||||
}
|
||||
|
||||
#include OATPP_CODEGEN_BEGIN(ApiController)
|
||||
|
||||
ENDPOINT("POST", "api/v1/register", registerUser,
|
||||
// BODY_DTO(dto::UserDto::ObjectWrapper, usr)) {
|
||||
BODY_DTO(oatpp::data::mapping::type::ObjectWrapper<dto::UserDto>, usr)) {
|
||||
BODY_DTO(oatpp::Object<UserDto>, usr))
|
||||
{
|
||||
manager::UserManager usrMgr(m_bConf);
|
||||
auto user = dto::conversion::DtoConversions::toUser(usr);
|
||||
auto user = conversion::DtoConversions::toUser(usr);
|
||||
|
||||
OATPP_LOGI("icarus", "Dto converted");
|
||||
|
||||
if (usrMgr.doesUserExist(user)) {
|
||||
return createResponse(Status::CODE_401, "user already exists");
|
||||
}
|
||||
|
||||
@@ -53,7 +53,6 @@ namespace controller
|
||||
|
||||
// endpoint for uploading a song
|
||||
ENDPOINT("POST", "/api/v1/song/data", songUpload,
|
||||
//AUTHORIZATION(std::shared_ptr<oatpp::web::server::handler::DefaultBearerAuthorizationObject>, authObject),
|
||||
REQUEST(std::shared_ptr<IncomingRequest>, request))
|
||||
{
|
||||
auto authHeader = request->getHeader("Authorization");
|
||||
@@ -69,13 +68,8 @@ namespace controller
|
||||
std::make_shared<oatpp::web::mime::multipart::PartList>
|
||||
(request->getHeaders());
|
||||
|
||||
// oatpp::web::mime::multipart::Reader mp_reader(mp.get());
|
||||
oatpp::web::mime::multipart::Reader mp_reader = mp.get();
|
||||
|
||||
/**
|
||||
mp_reader.setPartReader("file",
|
||||
oatpp::web::mime::multipart::createInMemoryPartReader(m_dataSize));
|
||||
*/
|
||||
mp_reader.setDefaultPartReader(
|
||||
oatpp::web::mime::multipart::createInMemoryPartReader(30 * 1024 * 1024));
|
||||
|
||||
@@ -83,7 +77,6 @@ namespace controller
|
||||
request->transferBody(&mp_reader);
|
||||
|
||||
auto file = mp->getNamedPart("file");
|
||||
// auto file = mp->readNextPartSimple();
|
||||
|
||||
OATPP_ASSERT_HTTP(file, Status::CODE_400, "file is null");
|
||||
|
||||
@@ -266,7 +259,7 @@ namespace controller
|
||||
|
||||
songDb = songRepo.retrieveRecord(songDb, type::SongFilter::id);
|
||||
|
||||
auto dSize = 1024;
|
||||
constexpr auto dSize = 1024;
|
||||
|
||||
auto callback = std::make_shared<callback::StreamCallback>(songDb.songPath);
|
||||
auto db = std::make_shared<oatpp::web::protocol::http::outgoing::StreamingBody>(
|
||||
|
||||
@@ -4,10 +4,12 @@
|
||||
#include <oatpp/core/Types.hpp>
|
||||
#include <oatpp/core/macro/codegen.hpp>
|
||||
|
||||
namespace dto {
|
||||
namespace dto
|
||||
{
|
||||
#include OATPP_CODEGEN_BEGIN(DTO)
|
||||
|
||||
class AlbumDto : public oatpp::DTO {
|
||||
class AlbumDto : public oatpp::DTO
|
||||
{
|
||||
DTO_INIT(AlbumDto, DTO)
|
||||
|
||||
DTO_FIELD(Int32, id);
|
||||
|
||||
@@ -5,10 +5,12 @@
|
||||
#include "oatpp/core/Types.hpp"
|
||||
#include "oatpp/core/macro/codegen.hpp"
|
||||
|
||||
namespace dto {
|
||||
namespace dto
|
||||
{
|
||||
#include OATPP_CODEGEN_BEGIN(DTO)
|
||||
|
||||
class ArtistDto : public oatpp::DTO {
|
||||
class ArtistDto : public oatpp::DTO
|
||||
{
|
||||
DTO_INIT(ArtistDto, DTO)
|
||||
|
||||
DTO_FIELD(Int32, id);
|
||||
|
||||
@@ -4,10 +4,12 @@
|
||||
#include "oatpp/core/macro/codegen.hpp"
|
||||
#include <oatpp/core/Types.hpp>
|
||||
|
||||
namespace dto {
|
||||
namespace dto
|
||||
{
|
||||
#include OATPP_CODEGEN_BEGIN(DTO)
|
||||
|
||||
class CoverArtDto : public oatpp::DTO {
|
||||
class CoverArtDto : public oatpp::DTO
|
||||
{
|
||||
DTO_INIT(CoverArtDto, DTO)
|
||||
|
||||
DTO_FIELD(Int32, id);
|
||||
|
||||
@@ -4,10 +4,12 @@
|
||||
#include "oatpp/core/macro/codegen.hpp"
|
||||
#include <oatpp/core/Types.hpp>
|
||||
|
||||
namespace dto {
|
||||
namespace dto
|
||||
{
|
||||
#include OATPP_CODEGEN_BEGIN(DTO)
|
||||
|
||||
class GenreDto : public oatpp::DTO {
|
||||
class GenreDto : public oatpp::DTO
|
||||
{
|
||||
DTO_INIT(GenreDto, DTO)
|
||||
|
||||
DTO_FIELD(Int32, id);
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
#ifndef LOGINRESULTDTO_H_
|
||||
#define LOGINRESULTDTO_H_
|
||||
|
||||
// #include <oatpp/core/data/mapping/type/Object.hpp>
|
||||
#include <oatpp/core/Types.hpp>
|
||||
#include <oatpp/core/macro/codegen.hpp>
|
||||
#include <oatpp/core/Types.hpp>
|
||||
|
||||
#include "model/Models.h"
|
||||
|
||||
namespace dto {
|
||||
namespace dto
|
||||
{
|
||||
#include OATPP_CODEGEN_BEGIN(DTO)
|
||||
|
||||
// class LoginResultDto : public oatpp::data::mapping::type::Object {
|
||||
class LoginResultDto : public oatpp::DTO {
|
||||
class LoginResultDto : public oatpp::DTO
|
||||
{
|
||||
DTO_INIT(LoginResultDto, DTO)
|
||||
|
||||
DTO_FIELD(oatpp::Int32, id);
|
||||
@@ -22,7 +22,8 @@ namespace dto {
|
||||
DTO_FIELD(oatpp::String, message);
|
||||
};
|
||||
|
||||
class RegisterResultDto : public oatpp::DTO {
|
||||
class RegisterResultDto : public oatpp::DTO
|
||||
{
|
||||
DTO_INIT(RegisterResultDto, DTO)
|
||||
|
||||
DTO_FIELD(oatpp::String, username);
|
||||
@@ -30,7 +31,8 @@ namespace dto {
|
||||
DTO_FIELD(oatpp::String, message);
|
||||
};
|
||||
|
||||
class UserDto : public oatpp::DTO {
|
||||
class UserDto : public oatpp::DTO
|
||||
{
|
||||
DTO_INIT(UserDto, DTO)
|
||||
|
||||
DTO_FIELD(oatpp::Int32, userId);
|
||||
|
||||
@@ -2,15 +2,16 @@
|
||||
#define SONGDTO_H_
|
||||
|
||||
#include <oatpp/core/Types.hpp>
|
||||
// #include <oatpp/core/data/mapping/type/Object.hpp>
|
||||
#include <oatpp/core/macro/codegen.hpp>
|
||||
|
||||
#include "model/Models.h"
|
||||
|
||||
namespace dto {
|
||||
namespace dto
|
||||
{
|
||||
#include OATPP_CODEGEN_BEGIN(DTO)
|
||||
|
||||
class SongDto : public oatpp::DTO {
|
||||
class SongDto : public oatpp::DTO
|
||||
{
|
||||
DTO_INIT(SongDto, DTO)
|
||||
|
||||
DTO_FIELD(oatpp::Int32, id);
|
||||
|
||||
@@ -4,10 +4,12 @@
|
||||
#include "oatpp/core/macro/codegen.hpp"
|
||||
#include <oatpp/core/Types.hpp>
|
||||
|
||||
namespace dto {
|
||||
namespace dto
|
||||
{
|
||||
#include OATPP_CODEGEN_BEGIN(DTO)
|
||||
|
||||
class YearDto : public oatpp::DTO {
|
||||
class YearDto : public oatpp::DTO
|
||||
{
|
||||
DTO_INIT(YearDto, DTO)
|
||||
|
||||
DTO_FIELD(Int32, id);
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
#ifndef DTOCONVERSIONS_H_
|
||||
#define DTOCONVERSIONS_H_
|
||||
|
||||
#include <iostream>
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
|
||||
#include <oatpp/core/data/mapping/ObjectMapper.hpp>
|
||||
#include <oatpp/core/data/mapping/type/Type.hpp>
|
||||
#include <oatpp/core/data/mapping/type/Object.hpp>
|
||||
@@ -18,8 +22,10 @@
|
||||
using namespace model;
|
||||
using namespace dto;
|
||||
|
||||
namespace dto { namespace conversion {
|
||||
class DtoConversions {
|
||||
namespace dto::conversion
|
||||
{
|
||||
class DtoConversions
|
||||
{
|
||||
public:
|
||||
template<typename D = oatpp::Object<LoginResultDto>>
|
||||
static D toLoginResultDto(const User &user, const Token &token)
|
||||
@@ -124,22 +130,18 @@ namespace dto { namespace conversion {
|
||||
static Song toSong(const D &songDto)
|
||||
{
|
||||
Song song;
|
||||
int id = songDto->id;
|
||||
song.id = (songDto->id.getPtr() == nullptr) ? 0 : id;
|
||||
auto title = songDto->title.get();
|
||||
/**
|
||||
song.title = (songDto->title == nullptr) ? "" : songDto->title;
|
||||
song.album = (songDto->album == nullptr) ? "" : songDto->album.c_str();
|
||||
song.artist = (songDto->artist == nullptr) ? "" : songDto->artist.c_str();
|
||||
song.id = (songDto->id.getPtr() == nullptr) ? 0 : *songDto->id;
|
||||
song.title = (songDto->title == nullptr) ? "" : songDto->title->c_str();
|
||||
song.album = (songDto->album == nullptr) ? "" : songDto->album->c_str();
|
||||
song.artist = (songDto->artist == nullptr) ? "" : songDto->artist->c_str();
|
||||
song.albumArtist = (songDto->album_artist == nullptr) ?
|
||||
"" : songDto->album_artist.c_str();
|
||||
song.genre = (songDto->genre == nullptr) ? "" : songDto->genre.c_str();
|
||||
song.year = (songDto->year.getPtr() == nullptr) ? 0 : songDto->year.getValue();
|
||||
song.track = (songDto->track.getPtr() == nullptr) ? 0 : songDto->track.getValue();
|
||||
song.disc = (songDto->disc.getPtr() == nullptr) ? 0 : songDto->disc.getValue();
|
||||
"" : songDto->album_artist->c_str();
|
||||
song.genre = (songDto->genre == nullptr) ? "" : songDto->genre->c_str();
|
||||
song.year = (songDto->year.getPtr() == nullptr) ? 0 : *songDto->year;
|
||||
song.track = (songDto->track.getPtr() == nullptr) ? 0 : *songDto->track;
|
||||
song.disc = (songDto->disc.getPtr() == nullptr) ? 0 : *songDto->disc;
|
||||
song.coverArtId = (songDto->coverart_id.getPtr() == nullptr) ?
|
||||
0 : songDto->coverart_id.getValue();
|
||||
*/
|
||||
0 : *songDto->coverart_id;
|
||||
|
||||
return song;
|
||||
|
||||
@@ -149,20 +151,20 @@ namespace dto { namespace conversion {
|
||||
static User toUser(const D &userDto)
|
||||
{
|
||||
User user;
|
||||
int id = userDto->userId;
|
||||
/**
|
||||
user.id = (userDto->userId.getPtr() == nullptr) ? 0 : userDto->userId.getValue();
|
||||
user.id = (userDto->userId.getPtr()) ? 0 : *userDto->userId;
|
||||
user.firstname = (userDto->firstname == nullptr) ? "" : userDto->firstname->c_str();
|
||||
user.lastname = (userDto->lastname == nullptr) ? "" : userDto->lastname->c_str();
|
||||
user.phone = (userDto->phone == nullptr) ? "" : userDto->phone->c_str();
|
||||
user.email = (userDto->email == nullptr) ? "" : userDto->email->c_str();
|
||||
user.username = (userDto->username == nullptr) ? "" : userDto->username->c_str();
|
||||
user.password = (userDto->password == nullptr) ? "" : userDto->password->c_str();
|
||||
*/
|
||||
|
||||
|
||||
std::cout << "Over\n";
|
||||
|
||||
return user;
|
||||
}
|
||||
};
|
||||
}}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,22 +1,114 @@
|
||||
#ifndef INITIALIZATION_H_
|
||||
#define INITIALIZATION_H_
|
||||
|
||||
#include <iostream>
|
||||
#include <filesystem>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <utility>
|
||||
|
||||
#include "database/BaseRepository.h"
|
||||
#include "manager/DirectoryManager.h"
|
||||
#include "manager/TokenManager.h"
|
||||
#include "model/Models.h"
|
||||
#include "type/PathType.h"
|
||||
|
||||
namespace verify {
|
||||
class Initialization {
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
namespace verify
|
||||
{
|
||||
template<typename Config = model::BinaryPath>
|
||||
class Initialization
|
||||
{
|
||||
public:
|
||||
static bool skipVerification(const std::string&);
|
||||
static bool skipVerification(const std::string &argument) noexcept
|
||||
{
|
||||
return argument.compare("--noverify") == 0;
|
||||
}
|
||||
|
||||
static void checkIcarus(const model::BinaryPath&);
|
||||
static void checkIcarus(const Config &bConf)
|
||||
{
|
||||
auto auth = confirmConfigAuth(bConf);
|
||||
auto database = confirmConfigDatabase(bConf);
|
||||
auto path = confirmConfigPaths(bConf);
|
||||
|
||||
if ((!auth) && (!database) && (!path)) {
|
||||
failedConfirmation();
|
||||
}
|
||||
|
||||
std::cout << "icarus check passed\n";
|
||||
}
|
||||
private:
|
||||
static bool confirmConfigAuth(const model::BinaryPath&);
|
||||
static bool confirmConfigDatabase(const model::BinaryPath&);
|
||||
static bool confirmConfigPaths(const model::BinaryPath&);
|
||||
static bool confirmConfigAuth(const Config &bConf)
|
||||
{
|
||||
manager::TokenManager tokMgr;
|
||||
|
||||
static void failedConfirmation();
|
||||
return tokMgr.testAuth(bConf);
|
||||
}
|
||||
|
||||
static bool confirmConfigDatabase(const Config &bConf)
|
||||
{
|
||||
database::BaseRepository baseRepo(bConf);
|
||||
|
||||
return baseRepo.testConnection();
|
||||
}
|
||||
static bool confirmConfigPaths(const Config &bConf)
|
||||
{
|
||||
using manager::DirectoryManager;
|
||||
using namespace type;
|
||||
|
||||
auto pathConfig = DirectoryManager::pathConfigContent(bConf);
|
||||
const auto musicType = PathType::music;
|
||||
const auto archiveType = PathType::archive;
|
||||
const auto tempRootType = PathType::temp;
|
||||
const auto coverArtType = PathType::coverArt;
|
||||
|
||||
auto rootMusicPath =
|
||||
pathConfig[DirectoryManager::retrievePathType(musicType)];
|
||||
auto archiveRootPath =
|
||||
pathConfig
|
||||
[DirectoryManager::retrievePathType(archiveType)];
|
||||
auto tempRootPath =
|
||||
pathConfig
|
||||
[DirectoryManager::retrievePathType(tempRootType)];
|
||||
|
||||
auto coverRootPath =
|
||||
pathConfig
|
||||
[DirectoryManager::retrievePathType(coverArtType)];
|
||||
|
||||
std::vector<std::string> paths;
|
||||
paths.reserve(4);
|
||||
paths.emplace_back(std::move(rootMusicPath));
|
||||
paths.emplace_back(std::move(archiveRootPath));
|
||||
paths.emplace_back(std::move(tempRootPath));
|
||||
paths.emplace_back(std::move(coverRootPath));
|
||||
|
||||
return confirmMultiplePaths(paths);
|
||||
}
|
||||
|
||||
static void failedConfirmation()
|
||||
{
|
||||
std::cout << "configuration confirmation failed. check your settings\n";
|
||||
std::exit(-1);
|
||||
}
|
||||
|
||||
template<typename Obj = std::string, typename Container = std::vector<Obj>>
|
||||
static bool confirmMultiplePaths(const Container &con)
|
||||
{
|
||||
auto result = true;
|
||||
|
||||
for (auto &path : con)
|
||||
{
|
||||
if (!fs::exists(path))
|
||||
{
|
||||
std::cout << path << " is not properly configured\n";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
+17
-19
@@ -1,19 +1,13 @@
|
||||
#include <exception>
|
||||
#include <iostream>
|
||||
#include <filesystem>
|
||||
#include <exception>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include <mysql/mysql.h>
|
||||
// #include <oatpp/network/server/Server.hpp>
|
||||
// #include "oatpp/network/server/SimpleTCPConnectionProvider.hpp"
|
||||
// #include "oatpp/web/server/HttpConnectionHandler.hpp"
|
||||
|
||||
#include <oatpp/web/server/HttpConnectionHandler.hpp>
|
||||
|
||||
// #include <oatpp/network/Server.hpp>
|
||||
#include <oatpp/network/Server.hpp>
|
||||
// #include <oatpp/network/server/SimpleTCPConnectionProvider.hpp>
|
||||
#include <oatpp/network/tcp/server/ConnectionProvider.hpp>
|
||||
|
||||
|
||||
@@ -29,12 +23,11 @@
|
||||
#include "model/Models.h"
|
||||
#include "verify/Initialization.h"
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
void run(const model::BinaryPath& bConf) {
|
||||
void run(const model::BinaryPath& bConf)
|
||||
{
|
||||
component::AppComponent component;
|
||||
|
||||
// OATPP_COMPONENT(std::shared_ptr<oatpp::web::server::HttpRouter>, router);
|
||||
auto router = oatpp::web::server::HttpRouter::createShared();
|
||||
|
||||
auto connectionHandler = oatpp::web::server::HttpConnectionHandler::createShared(router);
|
||||
@@ -57,8 +50,6 @@ void run(const model::BinaryPath& bConf) {
|
||||
sngController->addEndpointsToRouter(router);
|
||||
yearController->addEndpointsToRouter(router);
|
||||
|
||||
// OATPP_COMPONENT(std::shared_ptr<oatpp::network::server::ConnectionHandler>, connectionHandler);
|
||||
|
||||
OATPP_COMPONENT(std::shared_ptr<oatpp::network::ServerConnectionProvider>, connectionProvider);
|
||||
|
||||
oatpp::network::Server server(connectionProvider, connectionHandler);
|
||||
@@ -68,19 +59,26 @@ void run(const model::BinaryPath& bConf) {
|
||||
server.run();
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
oatpp::base::Environment::init();
|
||||
|
||||
model::BinaryPath bConf(std::move(argv[0]));
|
||||
|
||||
if (argc > 1) {
|
||||
if (!verify::Initialization::skipVerification(argv[1])) {
|
||||
verify::Initialization::checkIcarus(bConf);
|
||||
} else {
|
||||
if (argc > 1)
|
||||
{
|
||||
if (!verify::Initialization<>::skipVerification(argv[1]))
|
||||
{
|
||||
verify::Initialization<>::checkIcarus(bConf);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "skiping verifyication\n";
|
||||
}
|
||||
} else {
|
||||
verify::Initialization::checkIcarus(bConf);
|
||||
}
|
||||
else
|
||||
{
|
||||
verify::Initialization<>::checkIcarus(bConf);
|
||||
}
|
||||
|
||||
run(bConf);
|
||||
|
||||
@@ -1,101 +0,0 @@
|
||||
#include "dto/conversion/DtoConversions.h"
|
||||
|
||||
|
||||
namespace dto { namespace conversion {
|
||||
// LoginResultDto::ObjectWrapper DtoConversions::toLoginResultDto(const model::User& user,
|
||||
// dto::LoginResultDto DtoConversions::toLoginResultDto(const model::User& user,
|
||||
|
||||
/**
|
||||
oatpp::data::mapping::type::DTOWrapper<dto::LoginResultDto> DtoConversions::toLoginResultDto(const model::User& user,
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
// dto::RegisterResultDto::ObjectWrapper DtoConversions::toRegisterResultDto(
|
||||
/**
|
||||
dto::RegisterResultDto DtoConversions::toRegisterResultDto(
|
||||
const model::RegisterResult& regRes) {
|
||||
auto result = dto::RegisterResultDto::createShared();
|
||||
result->message = regRes.message.c_str();
|
||||
result->registered = regRes.registered;
|
||||
result->username = regRes.username.c_str();
|
||||
|
||||
return result;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
// dto::AlbumDto::ObjectWrapper DtoConversions::toAlbumDto(const model::Album& album) {
|
||||
/**
|
||||
dto::AlbumDto DtoConversions::toAlbumDto(const model::Album& album) {
|
||||
auto result = dto::AlbumDto::createShared();
|
||||
result->id = (album.id != 0) ? album.id : 0;
|
||||
result->title = (!album.title.empty()) ? album.title.c_str() : "";
|
||||
result->artist = (!album.artist.empty()) ? album.artist.c_str() : "";
|
||||
result->year = (album.year != 0) ? album.year : 0;
|
||||
|
||||
return result;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
// dto::SongDto::ObjectWrapper DtoConversions::toSongDto(const model::Song& song) {
|
||||
/**
|
||||
dto::SongDto DtoConversions::toSongDto(const model::Song& song) {
|
||||
auto result = dto::SongDto::createShared();
|
||||
result->id = (song.id != 0) ? song.id : 0;
|
||||
result->title = (!song.title.empty()) ? song.title.c_str() : "";
|
||||
result->album = (!song.album.empty()) ? song.album.c_str() : "";
|
||||
result->artist = (!song.artist.empty()) ? song.artist.c_str() : "";
|
||||
result->album_artist = (!song.albumArtist.empty()) ? song.albumArtist.c_str() : "";
|
||||
result->genre = (!song.genre.empty()) ? song.genre.c_str() : "";
|
||||
result->duration = (song.duration != 0) ? song.duration : 0;
|
||||
result->year = (song.year != 0) ? song.year : 0;
|
||||
result->track = (song.track != 0) ? song.track : 0;
|
||||
result->disc = (song.disc != 0) ? song.disc : 0;
|
||||
result->coverart_id = (song.coverArtId != 0) ? song.coverArtId : 0;
|
||||
|
||||
return result;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
// model::Song DtoConversions::toSong(dto::SongDto::ObjectWrapper& songDto) {
|
||||
/**
|
||||
model::Song DtoConversions::toSong(dto::SongDto *songDto) {
|
||||
model::Song song;
|
||||
song.id = (songDto->id.getPtr() == nullptr) ? 0 : songDto->id->getValue();
|
||||
song.title = (songDto->title == nullptr) ? "" : songDto->title.c_str();
|
||||
song.album = (songDto->album == nullptr) ? "" : songDto->album.c_str();
|
||||
song.artist = (songDto->artist == nullptr) ? "" : songDto->artist.c_str();
|
||||
song.albumArtist = (songDto->album_artist == nullptr) ?
|
||||
"" : songDto->album_artist.c_str();
|
||||
song.genre = (songDto->genre == nullptr) ? "" : songDto->genre.c_str();
|
||||
song.year = (songDto->year.getPtr() == nullptr) ? 0 : songDto->year.getValue();
|
||||
song.track = (songDto->track.getPtr() == nullptr) ? 0 : songDto->track.getValue();
|
||||
song.disc = (songDto->disc.getPtr() == nullptr) ? 0 : songDto->disc.getValue();
|
||||
song.coverArtId = (songDto->coverart_id.getPtr() == nullptr) ?
|
||||
0 : songDto->coverart_id.getValue();
|
||||
|
||||
return song;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
// model::User DtoConversions::toUser(dto::UserDto::ObjectWrapper& userDto) {
|
||||
model::User DtoConversions::toUser(dto::UserDto &userDto) {
|
||||
model::User user;
|
||||
// TODO: Can't leave it like this
|
||||
/**
|
||||
user.id = (userDto->userId.getPtr() == nullptr) ? 0 : userDto->userId->getValue();
|
||||
user.firstname = (userDto->firstname == nullptr) ? "" : userDto->firstname->c_str();
|
||||
user.lastname = (userDto->lastname == nullptr) ? "" : userDto->lastname->c_str();
|
||||
user.phone = (userDto->phone == nullptr) ? "" : userDto->phone->c_str();
|
||||
user.email = (userDto->email == nullptr) ? "" : userDto->email->c_str();
|
||||
user.username = (userDto->username == nullptr) ? "" : userDto->username->c_str();
|
||||
user.password = (userDto->password == nullptr) ? "" : userDto->password->c_str();
|
||||
*/
|
||||
|
||||
return user;
|
||||
}
|
||||
}}
|
||||
@@ -1,98 +0,0 @@
|
||||
#include "verify/Initialization.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <filesystem>
|
||||
|
||||
#include "database/BaseRepository.h"
|
||||
#include "manager/DirectoryManager.h"
|
||||
#include "manager/TokenManager.h"
|
||||
#include "type/PathType.h"
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
namespace verify {
|
||||
bool Initialization::skipVerification(const std::string& argument) {
|
||||
return argument.compare("--noverify") == 0;
|
||||
}
|
||||
|
||||
|
||||
// verifies if the configuration settings are valid
|
||||
void Initialization::checkIcarus(const model::BinaryPath& bConf) {
|
||||
auto auth = confirmConfigAuth(bConf);
|
||||
auto database = confirmConfigDatabase(bConf);
|
||||
auto path = confirmConfigPaths(bConf);
|
||||
|
||||
if ((!auth) && (!database) && (!path)) {
|
||||
failedConfirmation();
|
||||
}
|
||||
|
||||
std::cout << "icarus check passed\n";
|
||||
}
|
||||
|
||||
|
||||
// verifies that the authorization settings are not the default values
|
||||
bool Initialization::confirmConfigAuth(const model::BinaryPath& bConf) {
|
||||
manager::TokenManager tokMgr;
|
||||
|
||||
return tokMgr.testAuth(bConf);
|
||||
}
|
||||
|
||||
// verifies if database connectivity can be established
|
||||
bool Initialization::confirmConfigDatabase(const model::BinaryPath& bConf) {
|
||||
database::BaseRepository baseRepo(bConf);
|
||||
|
||||
return baseRepo.testConnection();
|
||||
}
|
||||
|
||||
// verifies if the paths found in the config files exists
|
||||
bool Initialization::confirmConfigPaths(const model::BinaryPath& bConf) {
|
||||
using manager::DirectoryManager;
|
||||
auto pathConfig = DirectoryManager::pathConfigContent(bConf);
|
||||
|
||||
const auto rootMusicPath =
|
||||
pathConfig
|
||||
[DirectoryManager::retrievePathType
|
||||
(type::PathType::music)].get<std::string>();
|
||||
const auto archiveRootPath =
|
||||
pathConfig
|
||||
[DirectoryManager::retrievePathType
|
||||
(type::PathType::archive)].get<std::string>();
|
||||
const auto tempRootPath =
|
||||
pathConfig
|
||||
[DirectoryManager::retrievePathType
|
||||
(type::PathType::temp)].get<std::string>();
|
||||
const auto coverRootPath =
|
||||
pathConfig
|
||||
[DirectoryManager::retrievePathType
|
||||
(type::PathType::coverArt)].get<std::string>();
|
||||
|
||||
if (!fs::exists(rootMusicPath)) {
|
||||
std::cout << "root music path is not properly configured\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!fs::exists(archiveRootPath)) {
|
||||
std::cout << "archive root path is not properly configured\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!fs::exists(tempRootPath)) {
|
||||
std::cout << "temp root path is not properly configured\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!fs::exists(coverRootPath)) {
|
||||
std::cout << "cover art root path is not properly configured\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// confirmation failed
|
||||
void Initialization::failedConfirmation() {
|
||||
std::cout << "configuration confirmation failed. check your settings\n";
|
||||
std::exit(-1);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user