Add admin endpoints.

This commit is contained in:
voussoir 2021-10-01 14:14:10 -07:00
parent 920a3d6450
commit fd42ef16e1
No known key found for this signature in database
GPG key ID: 5F7554F8C26DACCB
4 changed files with 82 additions and 0 deletions

View file

@ -1,3 +1,4 @@
from . import admin_endpoints
from . import album_endpoints
from . import basic_endpoints
from . import bookmark_endpoints
@ -6,6 +7,7 @@ from . import tag_endpoints
from . import user_endpoints
__all__ = [
'admin_endpoints',
'album_endpoints',
'basic_endpoints',
'bookmark_endpoints',

View file

@ -0,0 +1,25 @@
import flask; from flask import request
from voussoirkit import flasktools
from .. import common
site = common.site
session_manager = common.session_manager
####################################################################################################
@site.route('/admin')
def get_admin():
if not request.is_localhost:
flask.abort(403)
return common.render_template(request, 'admin.html')
@site.route('/admin/reload_config', methods=['POST'])
def post_reload_config():
if not request.is_localhost:
return flasktools.make_json_response({}, status=403)
common.P.load_config()
return flasktools.make_json_response({})

View file

@ -1,5 +1,15 @@
const api = {};
/**************************************************************************************************/
api.admin = {};
api.admin.reload_config =
function reload_config(callback)
{
const url = "/admin/reload_config";
return common.post(url, null, callback);
}
/**************************************************************************************************/
api.albums = {};

View file

@ -0,0 +1,45 @@
<!DOCTYPE html>
<html>
<head>
{% import "header.html" as header %}
<title>Admin control</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<link rel="stylesheet" href="/static/css/common.css">
<link rel="stylesheet" href="/static/css/etiquette.css">
{% if theme %}<link rel="stylesheet" href="/static/css/theme_{{theme}}.css">{% endif %}
<script src="/static/js/common.js"></script>
<script src="/static/js/api.js"></script>
<style>
</style>
</head>
<body>
{{header.make_header(session=session)}}
<div id="content_body">
<div class="panel">
<button id="reload_config_button" class="green_button" onclick="return reload_config_form();">Reload config file</button>
</div>
</div>
</body>
<script type="text/javascript">
function reload_config_form()
{
const reload_config_button = document.getElementById("reload_config_button");
reload_config_button.disabled = true;
function callback(response)
{
reload_config_button.disabled = false;
if (response.meta.status !== 200)
{
alert(JSON.stringify(response));
}
}
return api.admin.reload_config(callback);
}
</script>
</html>