Server backend now implements a request to get the raw download log for

a given download-entity
This commit is contained in:
Leon Etienne 2022-04-18 14:36:26 +02:00
parent 97289fec3f
commit b6863ac2e7
3 changed files with 31 additions and 1 deletions

View File

@ -102,6 +102,10 @@ void HttpServer::EventHandler(mg_connection* pNc, int ev, void* p)
{
ProcessAPIRequest(pNc, ev, p, peer_addr);
}
else if (requestedUri.substr(0, 12) == "/downloadlog")
{
ServeDownloadLog(pNc, ev, p, requestedUri);
}
else if (requestedUri.substr(0, 9) == "/download")
{
ServeDownloadeableResource(pNc, ev, p, requestedUri);
@ -216,6 +220,31 @@ void HttpServer::ServeDownloadeableResource(mg_connection* pNc, int ev, void* p,
return;
}
void HttpServer::ServeDownloadLog(mg_connection* pNc, int ev, void* p, std::string uri)
{
std::string fileId = uri.substr(13, uri.length() - 13);
if (Downloader::DownloadManager::DoesTubioIDExist(fileId))
{
Downloader::DownloadEntry& entry = Downloader::DownloadManager::GetDownloadEntryByTubioID(fileId);
std::stringstream ss;
std::string logFilename = std::string("./dlcache/dlprogbuf/") + fileId + ".buf";
ss << "Access-Control-Allow-Origin: *\nContent-Type: text/plain; Cache-Control: must-revalidate, post-check=0, pre-check=0";
mg_http_serve_file(pNc, (http_message*)p, logFilename.c_str(), mg_mk_str("text/plain"), mg_mk_str(ss.str().c_str()));
}
else
{
Json j;
std::stringstream ss;
j.CloneFrom(RestResponseTemplates::GetByCode(HTTP_STATUS_CODE::BAD_REQUEST, "Invalid tubio id!"));
ServeStringToConnection(pNc, j.Render(), (int)HTTP_STATUS_CODE::BAD_REQUEST);
}
return;
}
bool HttpServer::IsConnectionAllowed(std::string peer_address, std::string& denialReason)
{
// Localhost is always allowed!

View File

@ -24,6 +24,7 @@ namespace Rest
bool InitWebServer();
static void ProcessAPIRequest(struct mg_connection* pNc, int ev, void* p, std::string peerAddress);
static void ServeDownloadeableResource(struct mg_connection* pNc, int ev, void* p, std::string uri);
static void ServeDownloadLog(struct mg_connection* pNc, int ev, void* p, std::string uri);
static void EventHandler(struct mg_connection* pNc, int ev, void* p);
static void ServeStringToConnection(struct mg_connection* c, std::string str, int httpStatusCode = 200);

View File

@ -1,2 +1,2 @@
#pragma once
#define TUBIO_SERVER_VERSION (0.65)
#define TUBIO_SERVER_VERSION (0.66)