From 57f76ee4a46481f488dba36b55918e9a016679dd Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Sat, 1 Feb 2020 20:58:48 -0500 Subject: [PATCH] api is functional after the dependency updates --- include/callback/StreamCallback.h | 4 +++- include/controller/SongController.hpp | 31 ++++++--------------------- src/callback/StreamCallback.cpp | 4 +++- 3 files changed, 12 insertions(+), 27 deletions(-) diff --git a/include/callback/StreamCallback.h b/include/callback/StreamCallback.h index 2e216a5..a9cc314 100644 --- a/include/callback/StreamCallback.h +++ b/include/callback/StreamCallback.h @@ -4,6 +4,8 @@ #include #include "oatpp/core/data/stream/FileStream.hpp" +#include "oatpp/core/data/stream/Stream.hpp" +#include "oatpp/core/async/Coroutine.hpp" //#include "oatpp/web/protocol/http/outgoing/ChunkedBody.hpp" namespace callback { @@ -12,7 +14,7 @@ namespace callback { StreamCallback(); StreamCallback(const std::string&); - oatpp::v_io_size read(void*, oatpp::v_io_size); + oatpp::v_io_size read(void*, v_buff_size, oatpp::async::Action&); private: std::string m_songPath; diff --git a/include/controller/SongController.hpp b/include/controller/SongController.hpp index dd93ceb..3a315cc 100644 --- a/include/controller/SongController.hpp +++ b/include/controller/SongController.hpp @@ -12,11 +12,11 @@ #include #include "oatpp/core/data/stream/ChunkedBuffer.hpp" #include "oatpp/core/data/stream/FileStream.hpp" +#include "oatpp/core/base/StrBuffer.hpp" #include "oatpp/core/macro/codegen.hpp" #include "oatpp/core/macro/component.hpp" #include "oatpp/web/mime/multipart/InMemoryPartReader.hpp" #include "oatpp/web/mime/multipart/Reader.hpp" -//#include "oatpp/web/protocol/http/outgoing/ChunkedBody.hpp" #include "oatpp/web/protocol/http/outgoing/StreamingBody.hpp" #include "oatpp/web/server/api/ApiController.hpp" @@ -43,10 +43,12 @@ namespace controller { // endpoint for uploading a song ENDPOINT("POST", "/api/v1/song/data", songUpload, + AUTHORIZATION(std::shared_ptr, authObject), REQUEST(std::shared_ptr, request)) { auto authHeader = request->getHeader("Authorization"); OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope"); auto auth = authHeader->std_str(); + manager::TokenManager tok; OATPP_ASSERT_HTTP(tok.isTokenValid(auth, type::Scope::upload), Status::CODE_403, "Not allowed"); @@ -225,37 +227,16 @@ namespace controller { auto dSize = 1024; - /** - auto buff = std::make_unique(file->getInMemoryData()->c_str()); - auto buffSize = file->getKnownSize(); - - std::vector data(*buff, *buff + buffSize); - */ - - /** - auto db = std::make_shared( - std::make_shared(songDb.songPath), - nullptr, dSize); - */ - - /** - auto db = std::make_shared( - std::make_shared(songDb.songPath) - ); - */ - + auto callback = std::make_shared(songDb.songPath); auto db = std::make_shared( - std::make_shared(songDb.songPath), - dSize); + callback + ); - /** auto response = OutgoingResponse::createShared(Status::CODE_200, db); response->putHeader(Header::CONNECTION, Header::Value::CONNECTION_KEEP_ALIVE); response->putHeader(Header::CONTENT_TYPE, "audio/mpeg"); return response; - */ - return createResponse(Status::CODE_200, "Aye okay"); } #include OATPP_CODEGEN_END(ApiController) diff --git a/src/callback/StreamCallback.cpp b/src/callback/StreamCallback.cpp index 9c70f79..a27c2b4 100644 --- a/src/callback/StreamCallback.cpp +++ b/src/callback/StreamCallback.cpp @@ -18,7 +18,9 @@ namespace callback { } - oatpp::v_io_size StreamCallback::read(void *buff, oatpp::v_io_size count) { + + oatpp::v_io_size StreamCallback::read(void *buff, v_buff_size count, + oatpp::async::Action& action) { if (m_counter >= m_fileSize) { std::cout << "done streaming song\n"; return 0;