Left some TODO's. Next thing is to check if the token is valid

This commit is contained in:
kdeng00
2019-08-19 22:19:47 -04:00
parent 4072526d35
commit 3e94e0e22e
7 changed files with 59 additions and 27 deletions
+19 -22
View File
@@ -15,6 +15,8 @@
#include "managers/song_manager.h"
#include "models.h"
#include "token_manager.h"
#include "types/scopes.h"
class songController : public oatpp::web::server::api::ApiController
{
@@ -30,6 +32,20 @@ public:
ENDPOINT("POST", "/api/v1/song/data", songUpload,
REQUEST(std::shared_ptr<IncomingRequest>, request))
{
auto authHeader = request->getHeader("Authorization");
OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope");
auto auth = authHeader->std_str();
std::cout << "auth " << auth << std::endl;
token_manager tok;
if (!tok.is_token_valid(auth, Scope::upload)) {
// TODO: prevent user from moving forward
// token did not have the specified scope (permission)
}
auto mp = std::make_shared<oatpp::web::mime::multipart::Multipart>(request->getHeaders());
oatpp::web::mime::multipart::Reader mp_reader(mp.get());
@@ -43,35 +59,16 @@ public:
OATPP_ASSERT_HTTP(file, Status::CODE_400, "file is null");
auto stream = file->getInputStream();
//char *buff = new char[file->getKnownSize()];
auto buff = std::unique_ptr<char>(new char[file->getKnownSize()]);
//std::vector<unsigned char> buff;
//buff.reserve(file->getKnownSize());
//std::string buff;
//std::vector<unsigned char> buff;
auto buffSize = stream->read(buff.get(), file->getKnownSize()-1);
//auto buffSize = stream->read(&buff[0], file->getKnownSize()-1);
std::cout << "buff size " << buffSize << std::endl;
/**
std::cout << "buff " << buff << std::endl;
//std::cout << stream.get() << std::endl;
*/
auto buffSize = stream->read(buff.get(), file->getKnownSize());
std::vector<unsigned char> data(buff.get(), buff.get() + buffSize);
std::cout << "size of data " << data.size() << std::endl;
Song sng;
sng.data = std::move(data);
//sng.data = std::move(buff);
//std::cout << "data buff " << sng.data << std::endl;
std::cout << "data size " << sng.data.size() << std::endl;
song_manager s_mgr(exe_path);
s_mgr.saveSong(sng);
/* */
//std::string fileStr = file->getInMemoryData()->c_str();
//std::cout << fileStr << std::endl;
//std::cout << "known size " << file->getKnownSize() << std::endl;
//std::cout << "size " << fileStr.size() << std::endl;
return createResponse(Status::CODE_200, "OK");
}