Added remove entry function
This commit is contained in:
parent
189dc71c32
commit
d9a012f974
@ -355,6 +355,60 @@ bool DownloadManager::ClearDownloadCache()
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool DownloadManager::RemoveFromCacheByID(std::string id)
|
||||||
|
{
|
||||||
|
bool removedAny = false;
|
||||||
|
std::string filePath = "";
|
||||||
|
bool wasFinished = false;
|
||||||
|
for (std::size_t i = 0; i < unfinishedCache.size(); i++)
|
||||||
|
{
|
||||||
|
if (unfinishedCache[i].tubio_id == id)
|
||||||
|
{
|
||||||
|
filePath = unfinishedCache[i].downloaded_filename;
|
||||||
|
removedAny = true;
|
||||||
|
// Edgecase
|
||||||
|
wasFinished = unfinishedCache[i].status == DOWNLOAD_STATUS::FINISHED;
|
||||||
|
unfinishedCache.erase(unfinishedCache.begin() + i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// It finds it either in the lower two for loops, or in the first one.
|
||||||
|
for (std::size_t i = 0; i < saveFileCache.Size(); i++)
|
||||||
|
{
|
||||||
|
if ((saveFileCache[i].GetDataType() == JDType::JSON) &&
|
||||||
|
(saveFileCache[i].AsJson.DoesExist("tubio_id")) &&
|
||||||
|
(saveFileCache[i]["tubio_id"].GetDataType() == JDType::STRING))
|
||||||
|
{
|
||||||
|
if (saveFileCache[i]["tubio_id"].AsString == id)
|
||||||
|
{
|
||||||
|
saveFileCache.RemoveAt(i);
|
||||||
|
removedAny = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (std::size_t i = 0; i < saveFileCache_Atomic.size(); i++)
|
||||||
|
{
|
||||||
|
if (saveFileCache_Atomic[i].tubio_id == id)
|
||||||
|
{
|
||||||
|
filePath = saveFileCache_Atomic[i].downloaded_filename;
|
||||||
|
removedAny = true;
|
||||||
|
wasFinished = saveFileCache_Atomic[i].status == DOWNLOAD_STATUS::FINISHED;
|
||||||
|
saveFileCache_Atomic.erase(saveFileCache_Atomic.begin() + i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((wasFinished) && (FileSystem::Exists(filePath)))
|
||||||
|
{
|
||||||
|
FileSystem::Delete(filePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
Save();
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void DownloadManager::Save()
|
void DownloadManager::Save()
|
||||||
{
|
{
|
||||||
log->cout << "Saving...";
|
log->cout << "Saving...";
|
||||||
|
@ -94,6 +94,12 @@ namespace Downloader
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
static bool ClearDownloadCache();
|
static bool ClearDownloadCache();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Will remove an individual download entry by its tubio id
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
static bool RemoveFromCacheByID(std::string id);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static void Save();
|
static void Save();
|
||||||
static void Load();
|
static void Load();
|
||||||
|
@ -41,6 +41,7 @@ bool RestQueryHandler::ProcessQuery(const std::string clientAdress, const Json&
|
|||||||
else if (requestName == "fetch_session_logs") return FetchSessionLogs(requestBody, responseBody, responseCode);
|
else if (requestName == "fetch_session_logs") return FetchSessionLogs(requestBody, responseBody, responseCode);
|
||||||
else if (requestName == "fetch_alltime_logs") return FetchAlltimeLogs(requestBody, responseBody, responseCode);
|
else if (requestName == "fetch_alltime_logs") return FetchAlltimeLogs(requestBody, responseBody, responseCode);
|
||||||
else if (requestName == "update_dep_youtubedl") return UpdateYoutubeDL(requestBody, responseBody, responseCode);
|
else if (requestName == "update_dep_youtubedl") return UpdateYoutubeDL(requestBody, responseBody, responseCode);
|
||||||
|
else if (requestName == "remove_download_entry") return RemoveDownloadEntry(requestBody, responseBody, responseCode);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -402,7 +403,34 @@ bool RestQueryHandler::UpdateYoutubeDL(const JsonBlock& request, JsonBlock& resp
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool RestQueryHandler::RemoveDownloadEntry(const JsonBlock& request, JsonBlock& responseBody, HTTP_STATUS_CODE& responseCode)
|
||||||
|
{
|
||||||
|
if (!ValidateField("id", JDType::STRING, request, responseBody))
|
||||||
|
{
|
||||||
|
responseCode = BAD_REQUEST;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
log->cout << "Removing download id " << request["id"].AsString << "...";
|
||||||
|
log->Flush();
|
||||||
|
|
||||||
|
bool didSucceed = Downloader::DownloadManager::RemoveFromCacheByID(request["id"].AsString);
|
||||||
|
|
||||||
|
if (didSucceed)
|
||||||
|
{
|
||||||
|
responseCode = OK;
|
||||||
|
responseBody.CloneFrom(RestResponseTemplates::GetByCode(OK));
|
||||||
|
responseBody.Set("message") = "Successfully removed.";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
responseCode = BAD_REQUEST;
|
||||||
|
responseBody.CloneFrom(RestResponseTemplates::GetByCode(BAD_REQUEST));
|
||||||
|
responseBody.Set("message") = "Failed.";
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -33,6 +33,7 @@ namespace Rest
|
|||||||
static bool FetchSessionLogs(const JasonPP::JsonBlock& request, JasonPP::JsonBlock& responseBody, HTTP_STATUS_CODE& responseCode);
|
static bool FetchSessionLogs(const JasonPP::JsonBlock& request, JasonPP::JsonBlock& responseBody, HTTP_STATUS_CODE& responseCode);
|
||||||
static bool GetDiskUsage(const JasonPP::JsonBlock& request, JasonPP::JsonBlock& responseBody, HTTP_STATUS_CODE& responseCode);
|
static bool GetDiskUsage(const JasonPP::JsonBlock& request, JasonPP::JsonBlock& responseBody, HTTP_STATUS_CODE& responseCode);
|
||||||
static bool UpdateYoutubeDL(const JasonPP::JsonBlock& request, JasonPP::JsonBlock& responseBody, HTTP_STATUS_CODE& responseCode);
|
static bool UpdateYoutubeDL(const JasonPP::JsonBlock& request, JasonPP::JsonBlock& responseBody, HTTP_STATUS_CODE& responseCode);
|
||||||
|
static bool RemoveDownloadEntry(const JasonPP::JsonBlock& request, JasonPP::JsonBlock& responseBody, HTTP_STATUS_CODE& responseCode);
|
||||||
|
|
||||||
static bool ValidateField(const std::string name, const JasonPP::JDType type, const JasonPP::Json& checkThat, JasonPP::JsonBlock& putErrorResponseHere);
|
static bool ValidateField(const std::string name, const JasonPP::JDType type, const JasonPP::Json& checkThat, JasonPP::JsonBlock& putErrorResponseHere);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user