diff --git a/app/classes/web/routes/api/api_handlers.py b/app/classes/web/routes/api/api_handlers.py index 0c50614d..5d3aa9f5 100644 --- a/app/classes/web/routes/api/api_handlers.py +++ b/app/classes/web/routes/api/api_handlers.py @@ -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.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): @@ -173,8 +176,13 @@ def api_handlers(handler_args): handler_args, ), ( - r"/api/v2/crafty/exeCache/?", - ApiCraftyExeCacheIndexHandler, + r"/api/v2/crafty/JarCache/?", + ApiCraftyJarCacheIndexHandler, + handler_args, + ), + ( + r"/api/v2/crafty/SteamCache/?", + ApiCraftySteamCacheIndexHandler, handler_args, ), ( diff --git a/app/classes/web/routes/api/crafty/exe_cache.py b/app/classes/web/routes/api/crafty/exe_cache.py index a779195d..f4dcc154 100644 --- a/app/classes/web/routes/api/crafty/exe_cache.py +++ b/app/classes/web/routes/api/crafty/exe_cache.py @@ -1,7 +1,7 @@ from app.classes.web.base_api_handler import BaseApiHandler -class ApiCraftyExeCacheIndexHandler(BaseApiHandler): +class ApiCraftyJarCacheIndexHandler(BaseApiHandler): def get(self): auth_data = self.authenticate_user() if not auth_data: @@ -22,6 +22,32 @@ class ApiCraftyExeCacheIndexHandler(BaseApiHandler): 200, { "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(), }, ) diff --git a/app/frontend/templates/server/steam_wizard.html b/app/frontend/templates/server/steam_wizard.html index a82ba6ac..fe7c1cbb 100644 --- a/app/frontend/templates/server/steam_wizard.html +++ b/app/frontend/templates/server/steam_wizard.html @@ -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) { wait_msg(); e.preventDefault();