Add admin endpoint uncache.

This commit is contained in:
voussoir 2022-07-22 19:23:36 -07:00
parent d61f504d60
commit 6dd4cfe59b
No known key found for this signature in database
GPG key ID: 5F7554F8C26DACCB
3 changed files with 35 additions and 0 deletions

View file

@ -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({})

View file

@ -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 = {};

View file

@ -23,6 +23,7 @@
<div class="panel">
<h1>Admin tools</h1>
<p><button id="reload_config_button" class="green_button" onclick="return reload_config_form();">Reload config file</button></p>
<p><button id="uncache_button" class="green_button" onclick="return uncache_form();">Uncache objects</button></p>
<p><a href="/admin/dbdownload">Download database file</a></p>
</div>
</div>
@ -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);
}
</script>
</html>