mirror of
https://gitlab.com/crafty-controller/crafty-4.git
synced 2024-08-30 18:23:09 +00:00
Add cache refresh to api v2
This commit is contained in:
parent
db20d5ea7f
commit
153781c78e
@ -128,14 +128,6 @@ class AjaxHandler(BaseHandler):
|
||||
self.controller.cached_login = "login_1.jpg"
|
||||
return
|
||||
|
||||
elif page == "jar_cache":
|
||||
if not superuser:
|
||||
self.redirect("/panel/error?error=Not a super user")
|
||||
return
|
||||
|
||||
self.controller.server_jars.manual_refresh_cache()
|
||||
return
|
||||
|
||||
elif page == "update_server_dir":
|
||||
if self.helper.dir_migration:
|
||||
return
|
||||
|
@ -55,6 +55,7 @@ from app.classes.web.routes.api.users.user.public import ApiUsersUserPublicHandl
|
||||
from app.classes.web.routes.api.crafty.config.index import ApiCraftyConfigIndexHandler
|
||||
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
|
||||
|
||||
|
||||
def api_handlers(handler_args):
|
||||
@ -147,6 +148,11 @@ def api_handlers(handler_args):
|
||||
ApiServersIndexHandler,
|
||||
handler_args,
|
||||
),
|
||||
(
|
||||
r"/api/v2/crafty/exeCache/?",
|
||||
ApiCraftyExeCacheIndexHandler,
|
||||
handler_args,
|
||||
),
|
||||
(
|
||||
r"/api/v2/servers/([0-9]+)/?",
|
||||
ApiServersServerIndexHandler,
|
||||
|
27
app/classes/web/routes/api/crafty/exe_cache.py
Normal file
27
app/classes/web/routes/api/crafty/exe_cache.py
Normal file
@ -0,0 +1,27 @@
|
||||
from app.classes.web.base_api_handler import BaseApiHandler
|
||||
|
||||
|
||||
class ApiCraftyExeCacheIndexHandler(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.server_jars.get_serverjar_data(),
|
||||
},
|
||||
)
|
@ -1104,24 +1104,31 @@
|
||||
}
|
||||
}
|
||||
|
||||
function refreshCache() {
|
||||
let token = getCookie("_xsrf")
|
||||
async function refreshCache() {
|
||||
document.getElementById("refresh-cache").classList.add("fa-spin")
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
headers: { 'X-XSRFToken': token },
|
||||
url: '/ajax/jar_cache',
|
||||
success: function () {
|
||||
let token = getCookie("_xsrf")
|
||||
let res = await fetch(`/api/v2/crafty/exeCache`, {
|
||||
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(function () {
|
||||
setTimeout(() => {
|
||||
location.reload();
|
||||
}, 2000);
|
||||
},
|
||||
});
|
||||
}
|
||||
} else {
|
||||
|
||||
bootbox.alert({
|
||||
title: responseData.error,
|
||||
message: responseData.error
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
$('#file').change(function () {
|
||||
console.log("File changed");
|
||||
|
Loading…
Reference in New Issue
Block a user