Fix Refresh

This commit is contained in:
Andrew 2023-09-08 20:22:31 -04:00
parent ebc9f7d833
commit f2b906fe5c
3 changed files with 65 additions and 5 deletions

View File

@ -64,7 +64,10 @@ from app.classes.web.routes.api.crafty.config.server_dir import (
) )
from app.classes.web.routes.api.crafty.clogs.index import ApiCraftyLogIndexHandler from app.classes.web.routes.api.crafty.clogs.index import ApiCraftyLogIndexHandler
from app.classes.web.routes.api.crafty.imports.index import ApiImportFilesIndexHandler from app.classes.web.routes.api.crafty.imports.index import ApiImportFilesIndexHandler
from app.classes.web.routes.api.crafty.exe_cache import ApiCraftyExeCacheIndexHandler from app.classes.web.routes.api.crafty.exe_cache import (
ApiCraftyJarCacheIndexHandler,
ApiCraftySteamCacheIndexHandler,
)
def api_handlers(handler_args): def api_handlers(handler_args):
@ -173,8 +176,13 @@ def api_handlers(handler_args):
handler_args, handler_args,
), ),
( (
r"/api/v2/crafty/exeCache/?", r"/api/v2/crafty/JarCache/?",
ApiCraftyExeCacheIndexHandler, ApiCraftyJarCacheIndexHandler,
handler_args,
),
(
r"/api/v2/crafty/SteamCache/?",
ApiCraftySteamCacheIndexHandler,
handler_args, handler_args,
), ),
( (

View File

@ -1,7 +1,7 @@
from app.classes.web.base_api_handler import BaseApiHandler from app.classes.web.base_api_handler import BaseApiHandler
class ApiCraftyExeCacheIndexHandler(BaseApiHandler): class ApiCraftyJarCacheIndexHandler(BaseApiHandler):
def get(self): def get(self):
auth_data = self.authenticate_user() auth_data = self.authenticate_user()
if not auth_data: if not auth_data:
@ -22,6 +22,32 @@ class ApiCraftyExeCacheIndexHandler(BaseApiHandler):
200, 200,
{ {
"status": "ok", "status": "ok",
"data": self.controller.server_jars.get_serverjar_data(), "data": self.controller.server_jars.manual_refresh_cache(),
},
)
class ApiCraftySteamCacheIndexHandler(BaseApiHandler):
def get(self):
auth_data = self.authenticate_user()
if not auth_data:
return
(
_,
_,
_,
_,
_,
) = auth_data
if not auth_data[4]["superuser"]:
return self.finish_json(400, {"status": "error", "error": "NOT_AUTHORIZED"})
self.controller.server_jars.manual_refresh_cache()
self.finish_json(
200,
{
"status": "ok",
"data": self.controller.steam_apps.refresh_cache(),
}, },
) )

View File

@ -375,6 +375,32 @@
} }
} }
async function refreshCache() {
document.getElementById("refresh-cache").classList.add("fa-spin")
let token = getCookie("_xsrf")
let res = await fetch(`/api/v2/crafty/SteamCache/`, {
method: 'GET',
headers: {
'X-XSRFToken': token
},
});
let responseData = await res.json();
if (responseData.status === "ok") {
document.getElementById("refresh-cache").classList.remove("fa-sync");
document.getElementById("refresh-cache").classList.remove("fa-spin");
document.getElementById("refresh-cache").classList.add("fa-check");
setTimeout(() => {
location.reload();
}, 2000);
} else {
bootbox.alert({
title: responseData.error,
message: responseData.error
});
}
}
$("#server_creation").on("submit", async function (e) { $("#server_creation").on("submit", async function (e) {
wait_msg(); wait_msg();
e.preventDefault(); e.preventDefault();