From 6dd4cfe59bdbc1f018098158b5fb0329badd87e8 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Fri, 22 Jul 2022 19:23:36 -0700 Subject: [PATCH] Add admin endpoint uncache. --- .../backend/endpoints/admin_endpoints.py | 12 ++++++++++++ frontends/etiquette_flask/static/js/api.js | 7 +++++++ frontends/etiquette_flask/templates/admin.html | 16 ++++++++++++++++ 3 files changed, 35 insertions(+) diff --git a/frontends/etiquette_flask/backend/endpoints/admin_endpoints.py b/frontends/etiquette_flask/backend/endpoints/admin_endpoints.py index 54f3b74..3bcb80c 100644 --- a/frontends/etiquette_flask/backend/endpoints/admin_endpoints.py +++ b/frontends/etiquette_flask/backend/endpoints/admin_endpoints.py @@ -41,3 +41,15 @@ def post_reload_config(): common.P.load_config() return flasktools.json_response({}) + +@site.route('/admin/uncache', methods=['POST']) +def post_uncache(): + if not request.is_localhost: + return flasktools.json_response({}, status=403) + + with common.P.transaction: + for cache in common.P.caches.values(): + print(cache) + cache.clear() + + return flasktools.json_response({}) diff --git a/frontends/etiquette_flask/static/js/api.js b/frontends/etiquette_flask/static/js/api.js index 4341196..d492f14 100644 --- a/frontends/etiquette_flask/static/js/api.js +++ b/frontends/etiquette_flask/static/js/api.js @@ -10,6 +10,13 @@ function reload_config(callback) return common.post(url, null, callback); } +api.admin.uncache = +function uncache(callback) +{ + const url = "/admin/uncache"; + return common.post(url, null, callback); +} + /**************************************************************************************************/ api.albums = {}; diff --git a/frontends/etiquette_flask/templates/admin.html b/frontends/etiquette_flask/templates/admin.html index 22564a5..00823f1 100644 --- a/frontends/etiquette_flask/templates/admin.html +++ b/frontends/etiquette_flask/templates/admin.html @@ -23,6 +23,7 @@

Admin tools

+

Download database file

@@ -44,5 +45,20 @@ function reload_config_form() } return api.admin.reload_config(callback); } + +function uncache_form() +{ + const uncache_button = document.getElementById("uncache_button"); + uncache_button.disabled = true; + function callback(response) + { + uncache_button.disabled = false; + if (response.meta.status !== 200) + { + alert(JSON.stringify(response)); + } + } + return api.admin.uncache(callback); +}