Added option to allow localhost only, and added back button to settings page. scrapped account support

This commit is contained in:
Leon Etienne (ubuntu wsl) 2020-09-30 22:41:00 +02:00
parent 2f0935cddc
commit 66882b3b67
24 changed files with 170 additions and 109 deletions

View File

@ -160,6 +160,7 @@ void DownloadManager::DownloadNext()
ytdl_call_video_base = Internal::StringHelpers::Replace(ytdl_call_video_base, "$$DL_URL", entry->webpage_url);
ytdl_call_video_base = Internal::StringHelpers::Replace(ytdl_call_video_base, "$$DL_PROG_BUF_FILE", XGConfig::downloader.cachedir + "/dlprogbuf/" + entry->tubio_id + ".buf");
entry->downloaded_filename = XGConfig::downloader.cachedir + "/download/" + entry->tubio_id + ".mp4";
ss << ytdl_call_video_base;
}
@ -175,6 +176,7 @@ void DownloadManager::DownloadNext()
ytdl_call_audio_base = Internal::StringHelpers::Replace(ytdl_call_audio_base, "$$DL_URL", entry->webpage_url);
ytdl_call_audio_base = Internal::StringHelpers::Replace(ytdl_call_audio_base, "$$DL_PROG_BUF_FILE", XGConfig::downloader.cachedir + "/dlprogbuf/" + entry->tubio_id + ".buf");
entry->downloaded_filename = XGConfig::downloader.cachedir + "/download/" + entry->tubio_id + ".mp3";
ss << ytdl_call_audio_base;
}

View File

@ -82,11 +82,26 @@ void HttpServer::EventHandler(mg_connection* pNc, int ev, void* p)
http_message* hpm = (http_message*)p;
std::string requestedUri = FixUnterminatedString(hpm->uri.p, hpm->uri.len);
std::string peer_addr;
{
char buf[32];
mg_sock_addr_to_str(&pNc->sa, buf, sizeof(buf), MG_SOCK_STRINGIFY_IP);
peer_addr = buf;
}
if ((XGConfig::general.onlyAllowLocalhost) && (peer_addr != "127.0.0.1"))
{
Json j;
j.CloneFrom(RestResponseTemplates::GetByCode(UNAUTHORIZED, "Only localhost allowed!"));
ServeStringToConnection(pNc, j.Render(), UNAUTHORIZED);
}
else
{
try
{
if (requestedUri == "/api")
{
ProcessAPIRequest(pNc, ev, p);
ProcessAPIRequest(pNc, ev, p, peer_addr);
}
else if (requestedUri.substr(0, 9) == "/download")
{
@ -113,11 +128,12 @@ void HttpServer::EventHandler(mg_connection* pNc, int ev, void* p)
break;
}
}
return;
}
void HttpServer::ProcessAPIRequest(mg_connection* pNc, int ev, void* p)
void HttpServer::ProcessAPIRequest(mg_connection* pNc, int ev, void* p, std::string peerAddress)
{
// Get struct with http message informations
http_message* hpm = (http_message*)p;
@ -131,12 +147,11 @@ void HttpServer::ProcessAPIRequest(mg_connection* pNc, int ev, void* p)
Json requestBody;
requestBody.Parse(requestBodyRaw);
char peer_addr[32];
mg_sock_addr_to_str(&pNc->sa, peer_addr, sizeof(peer_addr), MG_SOCK_STRINGIFY_IP);
JsonBlock responseBody;
HTTP_STATUS_CODE returnCode;
RestQueryHandler::ProcessQuery(std::string(peer_addr), requestBody, responseBody, returnCode);
RestQueryHandler::ProcessQuery(peerAddress, requestBody, responseBody, returnCode);
Json response(responseBody);
ServeStringToConnection(pNc, response.Render(), returnCode);

View File

@ -22,7 +22,7 @@ namespace Rest
private:
bool InitWebServer();
static void ProcessAPIRequest(struct mg_connection* pNc, int ev, void* p);
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 EventHandler(struct mg_connection* pNc, int ev, void* p);

View File

@ -119,7 +119,11 @@ bool RestQueryHandler::FetchSessionCache(const JsonBlock& request, JsonBlock& re
// This way we can ensure that only entries of this SESSION will appear!
if (request["max_age"].AsInt >= 0)
{
#ifdef _WIN
max_age = min(request["max_age"].AsInt, max_age);
#else
max_age = std::min(request["max_age"].AsInt, max_age);
#endif
}
}
if (ValidateField("max_num", JDType::INT, request, dummy))
@ -234,7 +238,7 @@ bool RestQueryHandler::GetOSName(const JsonBlock& request, JsonBlock& responseBo
log->cout << "Asking for server OS name...";
log->Flush();
std::string osName = "other";
std::string osName = "Other";
#ifdef _WIN
osName = "Windows";
#elif __APPLE__ || __MACH__

View File

@ -16,7 +16,9 @@ JsonBlock Rest::RestResponseTemplates::GetByCode(HTTP_STATUS_CODE code, std::str
case HTTP_STATUS_CODE::BAD_REQUEST:
return BadRequest(message);
case HTTP_STATUS_CODE::FORBIDDEN:
return Forbidden((message.length() > 0) ? message : "Could be disabled in the config file!");
return Forbidden((message.length() > 0) ? message : "Forbidden!");
case HTTP_STATUS_CODE::UNAUTHORIZED:
return Unauthorized((message.length() > 0) ? message : "Unauthorized");
case HTTP_STATUS_CODE::NOT_FOUND:
return NotFound((message.length() > 0) ? message : "not found");
case HTTP_STATUS_CODE::INTERNAL_SERVER_ERROR:

View File

@ -44,12 +44,8 @@ void XGConfig::InitializeDefaultValues()
downloader.max_dlrate_per_thread = "100M";
downloader.num_threads = 1;
downloader.loginCredentials.use_account = false;
downloader.loginCredentials.username = "";
downloader.loginCredentials.password = "";
downloader.loginCredentials.twofactor = "";
general.show_console = true;
general.onlyAllowLocalhost = true;
return;
}
@ -103,27 +99,14 @@ void XGConfig::LoadFromJson(const JasonPP::JsonBlock& json)
downloader.max_dlrate_per_thread = json.ShorthandGet("downloader.max_dlrate_per_thread").AsString;
}
if (IsJsonFieldValid(json, "downloader.loginCredentials.use_account", JDType::BOOL))
{
downloader.loginCredentials.use_account = json.ShorthandGet("downloader.loginCredentials.use_account").AsBool;
}
if (IsJsonFieldValid(json, "downloader.loginCredentials.username", JDType::STRING))
{
downloader.loginCredentials.username = json.ShorthandGet("downloader.loginCredentials.username").AsString;
}
if (IsJsonFieldValid(json, "downloader.loginCredentials.password", JDType::STRING))
{
downloader.loginCredentials.password = json.ShorthandGet("downloader.loginCredentials.password").AsString;
}
if (IsJsonFieldValid(json, "downloader.loginCredentials.twofactor", JDType::STRING))
{
downloader.loginCredentials.twofactor = json.ShorthandGet("downloader.loginCredentials.twofactor").AsString;
}
if (IsJsonFieldValid(json, "general.show_console", JDType::BOOL))
{
general.show_console = json.ShorthandGet("general.show_console").AsBool;
}
if (IsJsonFieldValid(json, "general.onlyAllowLocalhost", JDType::BOOL))
{
general.onlyAllowLocalhost = json.ShorthandGet("general.onlyAllowLocalhost").AsBool;
}
return;
}
@ -145,15 +128,10 @@ JsonBlock XGConfig::CreateJson()
Ele("cachedir", downloader.cachedir),
Ele("max_dlrate_per_thread", downloader.max_dlrate_per_thread),
Ele("num_threads", downloader.num_threads),
Ele("login_credentials", JsonBlock({
Ele("use_account", downloader.loginCredentials.use_account),
Ele("username", downloader.loginCredentials.username),
Ele("password", downloader.loginCredentials.password),
Ele("twofactor", downloader.loginCredentials.twofactor)
}))
})),
Ele("general", JsonBlock({
Ele("show_console", general.show_console)
Ele("show_console", general.show_console),
Ele("onlyAllowLocalhost", general.onlyAllowLocalhost)
}))
});
}

View File

@ -23,23 +23,14 @@ public:
};
struct Downloader
{
struct LoginCredentials
{
bool use_account;
std::string username;
std::string password;
std::string twofactor;
};
std::string cachedir;
std::string max_dlrate_per_thread;
LoginCredentials loginCredentials;
int num_threads;
};
struct General
{
bool show_console;
bool onlyAllowLocalhost;
};
static void PreInit();

View File

@ -1,9 +1,9 @@
<!doctype html>
<html>
<head>
<title>Tubio - Video downloader</title><meta data-n-head="1" charset="utf-8"><meta data-n-head="1" name="viewport" content="width=device-width,initial-scale=1"><meta data-n-head="1" data-hid="description" name="description" content=""><link data-n-head="1" rel="icon" type="image/x-icon" href="/favicon.ico"><link rel="preload" href="/_nuxt/8c36d26.js" as="script"><link rel="preload" href="/_nuxt/7c07cac.js" as="script"><link rel="preload" href="/_nuxt/5c19fea.js" as="script"><link rel="preload" href="/_nuxt/7ae4872.js" as="script">
<title>Tubio - Video downloader</title><meta data-n-head="1" charset="utf-8"><meta data-n-head="1" name="viewport" content="width=device-width,initial-scale=1"><meta data-n-head="1" data-hid="description" name="description" content=""><link data-n-head="1" rel="icon" type="image/x-icon" href="/favicon.ico"><link rel="preload" href="/_nuxt/39f2f1c.js" as="script"><link rel="preload" href="/_nuxt/b2cccba.js" as="script"><link rel="preload" href="/_nuxt/d0a20ff.js" as="script"><link rel="preload" href="/_nuxt/ffabd53.js" as="script">
</head>
<body>
<div id="__nuxt"><style>#nuxt-loading{background:#fff;visibility:hidden;opacity:0;position:absolute;left:0;right:0;top:0;bottom:0;display:flex;justify-content:center;align-items:center;flex-direction:column;animation:nuxtLoadingIn 10s ease;-webkit-animation:nuxtLoadingIn 10s ease;animation-fill-mode:forwards;overflow:hidden}@keyframes nuxtLoadingIn{0%{visibility:hidden;opacity:0}20%{visibility:visible;opacity:0}100%{visibility:visible;opacity:1}}@-webkit-keyframes nuxtLoadingIn{0%{visibility:hidden;opacity:0}20%{visibility:visible;opacity:0}100%{visibility:visible;opacity:1}}#nuxt-loading>div,#nuxt-loading>div:after{border-radius:50%;width:5rem;height:5rem}#nuxt-loading>div{font-size:10px;position:relative;text-indent:-9999em;border:.5rem solid #f5f5f5;border-left:.5rem solid #000;-webkit-transform:translateZ(0);-ms-transform:translateZ(0);transform:translateZ(0);-webkit-animation:nuxtLoading 1.1s infinite linear;animation:nuxtLoading 1.1s infinite linear}#nuxt-loading.error>div{border-left:.5rem solid #ff4500;animation-duration:5s}@-webkit-keyframes nuxtLoading{0%{-webkit-transform:rotate(0);transform:rotate(0)}100%{-webkit-transform:rotate(360deg);transform:rotate(360deg)}}@keyframes nuxtLoading{0%{-webkit-transform:rotate(0);transform:rotate(0)}100%{-webkit-transform:rotate(360deg);transform:rotate(360deg)}}</style><script>window.addEventListener("error",function(){var e=document.getElementById("nuxt-loading");e&&(e.className+=" error")})</script><div id="nuxt-loading" aria-live="polite" role="status"><div>Loading...</div></div></div><script>window.__NUXT__={config:{},staticAssetsBase:"/_nuxt/static/1601494966"}</script>
<script src="/_nuxt/8c36d26.js"></script><script src="/_nuxt/7c07cac.js"></script><script src="/_nuxt/5c19fea.js"></script><script src="/_nuxt/7ae4872.js"></script></body>
<div id="__nuxt"><style>#nuxt-loading{background:#fff;visibility:hidden;opacity:0;position:absolute;left:0;right:0;top:0;bottom:0;display:flex;justify-content:center;align-items:center;flex-direction:column;animation:nuxtLoadingIn 10s ease;-webkit-animation:nuxtLoadingIn 10s ease;animation-fill-mode:forwards;overflow:hidden}@keyframes nuxtLoadingIn{0%{visibility:hidden;opacity:0}20%{visibility:visible;opacity:0}100%{visibility:visible;opacity:1}}@-webkit-keyframes nuxtLoadingIn{0%{visibility:hidden;opacity:0}20%{visibility:visible;opacity:0}100%{visibility:visible;opacity:1}}#nuxt-loading>div,#nuxt-loading>div:after{border-radius:50%;width:5rem;height:5rem}#nuxt-loading>div{font-size:10px;position:relative;text-indent:-9999em;border:.5rem solid #f5f5f5;border-left:.5rem solid #000;-webkit-transform:translateZ(0);-ms-transform:translateZ(0);transform:translateZ(0);-webkit-animation:nuxtLoading 1.1s infinite linear;animation:nuxtLoading 1.1s infinite linear}#nuxt-loading.error>div{border-left:.5rem solid #ff4500;animation-duration:5s}@-webkit-keyframes nuxtLoading{0%{-webkit-transform:rotate(0);transform:rotate(0)}100%{-webkit-transform:rotate(360deg);transform:rotate(360deg)}}@keyframes nuxtLoading{0%{-webkit-transform:rotate(0);transform:rotate(0)}100%{-webkit-transform:rotate(360deg);transform:rotate(360deg)}}</style><script>window.addEventListener("error",function(){var e=document.getElementById("nuxt-loading");e&&(e.className+=" error")})</script><div id="nuxt-loading" aria-live="polite" role="status"><div>Loading...</div></div></div><script>window.__NUXT__={config:{},staticAssetsBase:"/_nuxt/static/1601497777"}</script>
<script src="/_nuxt/39f2f1c.js"></script><script src="/_nuxt/b2cccba.js"></script><script src="/_nuxt/d0a20ff.js"></script><script src="/_nuxt/ffabd53.js"></script></body>
</html>

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1 @@
!function(e){function r(data){for(var r,n,f=data[0],l=data[1],d=data[2],i=0,h=[];i<f.length;i++)n=f[i],Object.prototype.hasOwnProperty.call(o,n)&&o[n]&&h.push(o[n][0]),o[n]=0;for(r in l)Object.prototype.hasOwnProperty.call(l,r)&&(e[r]=l[r]);for(v&&v(data);h.length;)h.shift()();return c.push.apply(c,d||[]),t()}function t(){for(var e,i=0;i<c.length;i++){for(var r=c[i],t=!0,n=1;n<r.length;n++){var l=r[n];0!==o[l]&&(t=!1)}t&&(c.splice(i--,1),e=f(f.s=r[0]))}return e}var n={},o={4:0},c=[];function f(r){if(n[r])return n[r].exports;var t=n[r]={i:r,l:!1,exports:{}};return e[r].call(t.exports,t,t.exports,f),t.l=!0,t.exports}f.e=function(e){var r=[],t=o[e];if(0!==t)if(t)r.push(t[2]);else{var n=new Promise((function(r,n){t=o[e]=[r,n]}));r.push(t[2]=n);var c,script=document.createElement("script");script.charset="utf-8",script.timeout=120,f.nc&&script.setAttribute("nonce",f.nc),script.src=function(e){return f.p+""+{2:"8f02b2f",3:"56889ef"}[e]+".js"}(e);var l=new Error;c=function(r){script.onerror=script.onload=null,clearTimeout(d);var t=o[e];if(0!==t){if(t){var n=r&&("load"===r.type?"missing":r.type),c=r&&r.target&&r.target.src;l.message="Loading chunk "+e+" failed.\n("+n+": "+c+")",l.name="ChunkLoadError",l.type=n,l.request=c,t[1](l)}o[e]=void 0}};var d=setTimeout((function(){c({type:"timeout",target:script})}),12e4);script.onerror=script.onload=c,document.head.appendChild(script)}return Promise.all(r)},f.m=e,f.c=n,f.d=function(e,r,t){f.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:t})},f.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},f.t=function(e,r){if(1&r&&(e=f(e)),8&r)return e;if(4&r&&"object"==typeof e&&e&&e.__esModule)return e;var t=Object.create(null);if(f.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var n in e)f.d(t,n,function(r){return e[r]}.bind(null,n));return t},f.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return f.d(r,"a",r),r},f.o=function(object,e){return Object.prototype.hasOwnProperty.call(object,e)},f.p="/_nuxt/",f.oe=function(e){throw console.error(e),e};var l=window.webpackJsonp=window.webpackJsonp||[],d=l.push.bind(l);l.push=r,l=l.slice();for(var i=0;i<l.length;i++)r(l[i]);var v=d;t()}([]);

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1 +0,0 @@
!function(e){function r(data){for(var r,n,l=data[0],f=data[1],d=data[2],i=0,h=[];i<l.length;i++)n=l[i],Object.prototype.hasOwnProperty.call(o,n)&&o[n]&&h.push(o[n][0]),o[n]=0;for(r in f)Object.prototype.hasOwnProperty.call(f,r)&&(e[r]=f[r]);for(v&&v(data);h.length;)h.shift()();return c.push.apply(c,d||[]),t()}function t(){for(var e,i=0;i<c.length;i++){for(var r=c[i],t=!0,n=1;n<r.length;n++){var f=r[n];0!==o[f]&&(t=!1)}t&&(c.splice(i--,1),e=l(l.s=r[0]))}return e}var n={},o={4:0},c=[];function l(r){if(n[r])return n[r].exports;var t=n[r]={i:r,l:!1,exports:{}};return e[r].call(t.exports,t,t.exports,l),t.l=!0,t.exports}l.e=function(e){var r=[],t=o[e];if(0!==t)if(t)r.push(t[2]);else{var n=new Promise((function(r,n){t=o[e]=[r,n]}));r.push(t[2]=n);var c,script=document.createElement("script");script.charset="utf-8",script.timeout=120,l.nc&&script.setAttribute("nonce",l.nc),script.src=function(e){return l.p+""+{2:"5a63703",3:"30c5ab9"}[e]+".js"}(e);var f=new Error;c=function(r){script.onerror=script.onload=null,clearTimeout(d);var t=o[e];if(0!==t){if(t){var n=r&&("load"===r.type?"missing":r.type),c=r&&r.target&&r.target.src;f.message="Loading chunk "+e+" failed.\n("+n+": "+c+")",f.name="ChunkLoadError",f.type=n,f.request=c,t[1](f)}o[e]=void 0}};var d=setTimeout((function(){c({type:"timeout",target:script})}),12e4);script.onerror=script.onload=c,document.head.appendChild(script)}return Promise.all(r)},l.m=e,l.c=n,l.d=function(e,r,t){l.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:t})},l.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},l.t=function(e,r){if(1&r&&(e=l(e)),8&r)return e;if(4&r&&"object"==typeof e&&e&&e.__esModule)return e;var t=Object.create(null);if(l.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var n in e)l.d(t,n,function(r){return e[r]}.bind(null,n));return t},l.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return l.d(r,"a",r),r},l.o=function(object,e){return Object.prototype.hasOwnProperty.call(object,e)},l.p="/_nuxt/",l.oe=function(e){throw console.error(e),e};var f=window.webpackJsonp=window.webpackJsonp||[],d=f.push.bind(f);f.push=r,f=f.slice();for(var i=0;i<f.length;i++)r(f[i]);var v=d;t()}([]);

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,5 +1,5 @@
<template>
<svg viewBox="0 0 16 16" class="bi bi-gear" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
<svg viewBox="-2 -2 20 20" class="bi bi-gear" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" d="M8.837 1.626c-.246-.835-1.428-.835-1.674 0l-.094.319A1.873 1.873 0 0 1 4.377 3.06l-.292-.16c-.764-.415-1.6.42-1.184 1.185l.159.292a1.873 1.873 0 0 1-1.115 2.692l-.319.094c-.835.246-.835 1.428 0 1.674l.319.094a1.873 1.873 0 0 1 1.115 2.693l-.16.291c-.415.764.42 1.6 1.185 1.184l.292-.159a1.873 1.873 0 0 1 2.692 1.116l.094.318c.246.835 1.428.835 1.674 0l.094-.319a1.873 1.873 0 0 1 2.693-1.115l.291.16c.764.415 1.6-.42 1.184-1.185l-.159-.291a1.873 1.873 0 0 1 1.116-2.693l.318-.094c.835-.246.835-1.428 0-1.674l-.319-.094a1.873 1.873 0 0 1-1.115-2.692l.16-.292c.415-.764-.42-1.6-1.185-1.184l-.291.159A1.873 1.873 0 0 1 8.93 1.945l-.094-.319zm-2.633-.283c.527-1.79 3.065-1.79 3.592 0l.094.319a.873.873 0 0 0 1.255.52l.292-.16c1.64-.892 3.434.901 2.54 2.541l-.159.292a.873.873 0 0 0 .52 1.255l.319.094c1.79.527 1.79 3.065 0 3.592l-.319.094a.873.873 0 0 0-.52 1.255l.16.292c.893 1.64-.902 3.434-2.541 2.54l-.292-.159a.873.873 0 0 0-1.255.52l-.094.319c-.527 1.79-3.065 1.79-3.592 0l-.094-.319a.873.873 0 0 0-1.255-.52l-.292.16c-1.64.893-3.433-.902-2.54-2.541l.159-.292a.873.873 0 0 0-.52-1.255l-.319-.094c-1.79-.527-1.79-3.065 0-3.592l.319-.094a.873.873 0 0 0 .52-1.255l-.16-.292c-.892-1.64.902-3.433 2.541-2.54l.292.159a.873.873 0 0 0 1.255-.52l.094-.319z"/>
<path fill-rule="evenodd" d="M8 5.754a2.246 2.246 0 1 0 0 4.492 2.246 2.246 0 0 0 0-4.492zM4.754 8a3.246 3.246 0 1 1 6.492 0 3.246 3.246 0 0 1-6.492 0z"/>
</svg>

View File

@ -9,26 +9,11 @@
<div class="w-full lg:w-1/2 border-right lg:pr-3">
<div class="option toggle flex justify-between items-center">
<div v-if="serverOs === 'Windows'" class="option toggle flex justify-between items-center">
<p>Show console</p>
<Toggle :isOn="false"/>
</div>
<div class="option toggle flex justify-between items-center">
<p>Use account</p>
<Toggle :isOn="false"/>
</div>
<div class="option text flex justify-between w-full items-center">
<p class="mr-3">Username</p>
<input type="text" id="username" name="username">
</div>
<div class="option text flex justify-between w-full items-center">
<p class="mr-3">Password</p>
<input type="password" id="password" name="password">
</div>
<div class="option toggle flex justify-between items-center">
<p>Limit speed</p>
<Toggle :isOn="false"/>
@ -75,8 +60,16 @@
<Spacer height="50px"/>
<div class="flex">
<div class="flex flex-col mr-1">
<div class="button" v-on:click="clearDLCache">Clear downloads</div>
<div class="button mt-2" v-on:click="clearLogs">Clear logs</div>
<div class="button mt-2" v-if="serverOs === 'Windows'" v-on:click="updateYtdl">Update ytdl</div>
</div>
<div class="flex flex-col ml-1">
<div class="button" v-on:click="killServer">Kill server</div>
</div>
</div>
</div>
@ -90,6 +83,12 @@
</div>
</div>
<div class="go-back hidden md:block">
<nuxt-link exact to="/">
&lt;&lt;&nbsp;Back
</nuxt-link>
</div>
</div>
</template>
@ -110,12 +109,14 @@ export default {
computed: {
diskUsage: function() {
return this.$store.state.diskUsage.usage;
},
serverOs: function() {
return this.$store.state.serverOs.os_name;
}
},
methods: {
clearDLCache: function() {
const that = this;
axios.post("/api", {
request: "clear_download_cache",
@ -128,7 +129,6 @@ export default {
},
clearLogs: function() {
const that = this;
axios.post("/api", {
request: "clear_logs",
@ -139,10 +139,35 @@ export default {
});
return;
},
updateYtdl: function() {
const that = this;
axios.post("/api", {
request: "update_dep_youtubedl",
}).then(function(response){
if (response.data.status === "OK") {
that.$store.dispatch("logs/update", that);
}
});
return;
},
killServer: function() {
const that = this;
axios.post("/api", {
request: "kill_yourself",
}).then(function(response){
if (response.data.status === "OK") {
window.close();
}
});
return;
},
},
mounted() {
this.$store.dispatch("diskUsage/update", this);
this.$store.dispatch("serverOs/update", this);
return;
}
};
@ -215,7 +240,7 @@ h2 {
font-family: ZillaSlab, serif;
font-size: 18pt;
transition: background-color 0.2s;
max-width: 200px;
width: 200px;
&:hover {
background-color: theme("colors.text-error-1");
@ -226,4 +251,22 @@ hr {
border: none;
border-bottom: 2px solid theme("colors.gray-1");
}
@keyframes goback-floating {
0% { left: 1em; }
50% { left: 1.2em; }
0% { left: 1em; }
}
.go-back {
position: absolute;
left: 1em;
top: 1em;
font-size: 34pt;
font-family: ZillaSlab, serif;
color: theme("colors.purple-3-1");
user-select: none;
cursor: pointer;
animation: goback-floating 1s infinite;
}
</style>

View File

@ -0,0 +1,24 @@
import axios from 'axios';
export const state = () => ({
os_name: ""
});
export const mutations = {
update(state, data) {
state.os_name = data;
},
};
export const actions = {
update(context, instance) {
axios.post("/api", {
request: "get_os_name"
})
.then(function(response) {
if (response.data.status === "OK") {
instance.$store.commit("serverOs/update", response.data.os_name);
}
});
},
};