|
|
|
@@ -31,7 +31,7 @@ class songController : public oatpp::web::server::api::ApiController
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
songController(std::string p, OATPP_COMPONENT(std::shared_ptr<ObjectMapper>, objectMapper))
|
|
|
|
|
: oatpp::web::server::api::ApiController(objectMapper), exe_path(p)
|
|
|
|
|
: oatpp::web::server::api::ApiController(objectMapper), m_exe_path(p)
|
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
#include OATPP_CODEGEN_BEGIN(ApiController)
|
|
|
|
@@ -53,7 +53,7 @@ public:
|
|
|
|
|
|
|
|
|
|
oatpp::web::mime::multipart::Reader mp_reader(mp.get());
|
|
|
|
|
|
|
|
|
|
mp_reader.setPartReader("file", oatpp::web::mime::multipart::createInMemoryPartReader(dataSize));
|
|
|
|
|
mp_reader.setPartReader("file", oatpp::web::mime::multipart::createInMemoryPartReader(m_dataSize));
|
|
|
|
|
|
|
|
|
|
request->transferBody(&mp_reader);
|
|
|
|
|
|
|
|
|
@@ -61,16 +61,15 @@ public:
|
|
|
|
|
|
|
|
|
|
OATPP_ASSERT_HTTP(file, Status::CODE_400, "file is null");
|
|
|
|
|
|
|
|
|
|
auto stream = file->getInputStream();
|
|
|
|
|
auto buff = std::unique_ptr<char>(new char[file->getKnownSize()]);
|
|
|
|
|
auto buffSize = stream->read(buff.get(), file->getKnownSize());
|
|
|
|
|
auto buffSize = file->getInputStream()->read(buff.get(), file->getKnownSize());
|
|
|
|
|
|
|
|
|
|
std::vector<unsigned char> data(buff.get(), buff.get() + buffSize);
|
|
|
|
|
|
|
|
|
|
Song sng;
|
|
|
|
|
sng.data = std::move(data);
|
|
|
|
|
|
|
|
|
|
song_manager s_mgr(exe_path);
|
|
|
|
|
song_manager s_mgr(m_exe_path);
|
|
|
|
|
s_mgr.saveSong(sng);
|
|
|
|
|
|
|
|
|
|
return createResponse(Status::CODE_200, "OK");
|
|
|
|
@@ -81,7 +80,7 @@ public:
|
|
|
|
|
REQUEST(std::shared_ptr<IncomingRequest>, request))
|
|
|
|
|
{
|
|
|
|
|
std::cout << "starting process of retrieving songs" << std::endl;
|
|
|
|
|
songRepository songRepo(exe_path);
|
|
|
|
|
songRepository songRepo(m_exe_path);
|
|
|
|
|
auto songsDb = songRepo.retrieveRecords();
|
|
|
|
|
auto songs = oatpp::data::mapping::type::List<songDto::ObjectWrapper>::createShared();
|
|
|
|
|
|
|
|
|
@@ -106,7 +105,7 @@ public:
|
|
|
|
|
ENDPOINT("GET", "/api/v1/song/{id}", songRecord,
|
|
|
|
|
PATH(Int32, id)) {
|
|
|
|
|
|
|
|
|
|
songRepository songRepo(exe_path);
|
|
|
|
|
songRepository songRepo(m_exe_path);
|
|
|
|
|
Song songDb;
|
|
|
|
|
songDb.id = id;
|
|
|
|
|
|
|
|
|
@@ -124,71 +123,26 @@ public:
|
|
|
|
|
return createDtoResponse(Status::CODE_200, song);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO: left off here
|
|
|
|
|
ENDPOINT("GET", "/api/v1/song/data/{id}", downloadSong,
|
|
|
|
|
PATH(Int32, id)) {
|
|
|
|
|
|
|
|
|
|
songRepository songRepo(exe_path);
|
|
|
|
|
songRepository songRepo(m_exe_path);
|
|
|
|
|
Song songDb;
|
|
|
|
|
songDb.id = id;
|
|
|
|
|
songDb = songRepo.retrieveRecord(songDb, songFilter::id);
|
|
|
|
|
|
|
|
|
|
std::cout << "song path " << songDb.songPath << std::endl;
|
|
|
|
|
|
|
|
|
|
std::ifstream fl(songDb.songPath.c_str(), std::ios::in | std::ios::binary | std::ios::ate);
|
|
|
|
|
|
|
|
|
|
//auto rawSong = oatpp::String((v_int32) fl.tellg());
|
|
|
|
|
fl.seekg(0);
|
|
|
|
|
//fl.read((char*)rawSong->getData(), rawSong->getSize());
|
|
|
|
|
|
|
|
|
|
std::stringstream buf;
|
|
|
|
|
std::copy(std::istreambuf_iterator<char>(fl),
|
|
|
|
|
std::istreambuf_iterator<char>(),
|
|
|
|
|
std::ostreambuf_iterator<char>(buf)
|
|
|
|
|
);
|
|
|
|
|
std::ostreambuf_iterator<char>(buf));
|
|
|
|
|
fl.close();
|
|
|
|
|
|
|
|
|
|
//std::cout << buf.str().c_str() << std::endl;
|
|
|
|
|
|
|
|
|
|
//auto raw = buf.str();
|
|
|
|
|
|
|
|
|
|
auto rawSong = std::make_shared<oatpp::String>(oatpp::String(buf.str().data(), (v_int32)buf.str().size(), true));
|
|
|
|
|
//std::cout << rawSong->c_str() << std::endl;
|
|
|
|
|
//std::cout << rawSong->std_str() << std::endl;
|
|
|
|
|
//std::shared_ptr<oatpp::String> rawSong = std::make_shared<oatpp::String>();
|
|
|
|
|
//rawSong->loadFromFile(songDb.songPath.c_str());
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
std::cout << "constructing FileInputStream" << std::endl;
|
|
|
|
|
oatpp::data::stream::FileInputStream file(songDb.songPath.c_str());
|
|
|
|
|
//oatpp::data::stream::FileOutputStream file(songDb.songPath.c_str());
|
|
|
|
|
auto songPath = fs::path(songDb.songPath);
|
|
|
|
|
auto songSize = fs::file_size(songPath);
|
|
|
|
|
std::cout << "prepping data" << std::endl;
|
|
|
|
|
std::cout << "byte size " << songSize << std::endl;
|
|
|
|
|
auto data = new char[songSize];
|
|
|
|
|
std::cout << "data will be loaded" << std::endl;
|
|
|
|
|
auto byteCount = file.read(&data, songSize);
|
|
|
|
|
//auto byteCount = file.write(&data, songSize);
|
|
|
|
|
|
|
|
|
|
std::cout << byteCount << " bytes read" << std::endl;
|
|
|
|
|
|
|
|
|
|
auto songData = oatpp::data::stream::ChunkedBuffer::createShared();
|
|
|
|
|
songData->write(data, byteCount);
|
|
|
|
|
|
|
|
|
|
delete[] data;
|
|
|
|
|
|
|
|
|
|
std::cout << "sending file" << std::endl;
|
|
|
|
|
*/
|
|
|
|
|
/**
|
|
|
|
|
auto songData = oatpp::data::stream::ChunkedBuffer::createShared();
|
|
|
|
|
songData->write(buf.str().data(), buf.str().size());
|
|
|
|
|
|
|
|
|
|
//auto response = createResponse(Status::CODE_200, songData);
|
|
|
|
|
*/
|
|
|
|
|
auto response = createResponse(Status::CODE_200, *rawSong);
|
|
|
|
|
response->putHeader("Accept-Ranges", "bytes");
|
|
|
|
|
response->putHeader(Header::CONNECTION, Header::Value::CONNECTION_KEEP_ALIVE);
|
|
|
|
|
response->putHeader(Header::CONTENT_TYPE, "audio/mpeg");
|
|
|
|
|
|
|
|
|
|
return response;
|
|
|
|
@@ -199,7 +153,7 @@ public:
|
|
|
|
|
Song song;
|
|
|
|
|
song.id = id;
|
|
|
|
|
|
|
|
|
|
song_manager sngMgr(exe_path);
|
|
|
|
|
song_manager sngMgr(m_exe_path);
|
|
|
|
|
sngMgr.deleteSong(song);
|
|
|
|
|
|
|
|
|
|
return createResponse(Status::CODE_200, "OK");
|
|
|
|
@@ -207,8 +161,8 @@ public:
|
|
|
|
|
|
|
|
|
|
#include OATPP_CODEGEN_END(ApiController)
|
|
|
|
|
private:
|
|
|
|
|
std::string exe_path;
|
|
|
|
|
const long dataSize = std::numeric_limits<long long int>::max();
|
|
|
|
|
std::string m_exe_path;
|
|
|
|
|
const long m_dataSize = std::numeric_limits<long long int>::max();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|