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"
|
self.controller.cached_login = "login_1.jpg"
|
||||||
return
|
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":
|
elif page == "update_server_dir":
|
||||||
if self.helper.dir_migration:
|
if self.helper.dir_migration:
|
||||||
return
|
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.config.index import ApiCraftyConfigIndexHandler
|
||||||
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
|
||||||
|
|
||||||
|
|
||||||
def api_handlers(handler_args):
|
def api_handlers(handler_args):
|
||||||
@ -147,6 +148,11 @@ def api_handlers(handler_args):
|
|||||||
ApiServersIndexHandler,
|
ApiServersIndexHandler,
|
||||||
handler_args,
|
handler_args,
|
||||||
),
|
),
|
||||||
|
(
|
||||||
|
r"/api/v2/crafty/exeCache/?",
|
||||||
|
ApiCraftyExeCacheIndexHandler,
|
||||||
|
handler_args,
|
||||||
|
),
|
||||||
(
|
(
|
||||||
r"/api/v2/servers/([0-9]+)/?",
|
r"/api/v2/servers/([0-9]+)/?",
|
||||||
ApiServersServerIndexHandler,
|
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() {
|
async function refreshCache() {
|
||||||
let token = getCookie("_xsrf")
|
|
||||||
document.getElementById("refresh-cache").classList.add("fa-spin")
|
document.getElementById("refresh-cache").classList.add("fa-spin")
|
||||||
$.ajax({
|
let token = getCookie("_xsrf")
|
||||||
type: "POST",
|
let res = await fetch(`/api/v2/crafty/exeCache`, {
|
||||||
headers: { 'X-XSRFToken': token },
|
method: 'GET',
|
||||||
url: '/ajax/jar_cache',
|
headers: {
|
||||||
success: function () {
|
'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-sync");
|
||||||
document.getElementById("refresh-cache").classList.remove("fa-spin");
|
document.getElementById("refresh-cache").classList.remove("fa-spin");
|
||||||
document.getElementById("refresh-cache").classList.add("fa-check");
|
document.getElementById("refresh-cache").classList.add("fa-check");
|
||||||
|
setTimeout(() => {
|
||||||
setTimeout(function () {
|
|
||||||
location.reload();
|
location.reload();
|
||||||
}, 2000);
|
}, 2000);
|
||||||
},
|
} else {
|
||||||
});
|
|
||||||
}
|
bootbox.alert({
|
||||||
|
title: responseData.error,
|
||||||
|
message: responseData.error
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$('#file').change(function () {
|
$('#file').change(function () {
|
||||||
console.log("File changed");
|
console.log("File changed");
|
||||||
|
Loading…
Reference in New Issue
Block a user