2021-10-01 21:14:10 +00:00
|
|
|
import flask; from flask import request
|
|
|
|
|
2022-11-12 03:26:36 +00:00
|
|
|
from voussoirkit import dotdict
|
2021-10-01 21:14:10 +00:00
|
|
|
from voussoirkit import flasktools
|
2022-11-07 06:48:59 +00:00
|
|
|
from voussoirkit import timetools
|
2021-10-01 21:14:10 +00:00
|
|
|
|
2022-07-16 06:35:35 +00:00
|
|
|
import etiquette
|
|
|
|
|
2021-10-01 21:14:10 +00:00
|
|
|
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)
|
|
|
|
|
2022-11-12 03:26:36 +00:00
|
|
|
counts = dotdict.DotDict({
|
|
|
|
'albums': common.P.get_album_count(),
|
|
|
|
'bookmarks': common.P.get_bookmark_count(),
|
|
|
|
'photos': common.P.get_photo_count(),
|
|
|
|
'tags': common.P.get_tag_count(),
|
|
|
|
'users': common.P.get_user_count(),
|
|
|
|
})
|
|
|
|
return common.render_template(request, 'admin.html', counts=counts)
|
2021-10-01 21:14:10 +00:00
|
|
|
|
2022-07-16 06:35:35 +00:00
|
|
|
@site.route('/admin/dbdownload')
|
|
|
|
def get_dbdump():
|
|
|
|
if not request.is_localhost:
|
|
|
|
flask.abort(403)
|
|
|
|
|
|
|
|
with common.P.transaction:
|
|
|
|
binary = common.P.database_filepath.read('rb')
|
|
|
|
|
2022-11-07 06:48:59 +00:00
|
|
|
now = timetools.now().strftime('%Y-%m-%d_%H-%M-%S')
|
2022-07-16 06:35:35 +00:00
|
|
|
download_as = f'etiquette {now}.db'
|
|
|
|
outgoing_headers = {
|
|
|
|
'Content-Type': 'application/octet-stream',
|
|
|
|
'Content-Disposition': f'attachment; filename*=UTF-8\'\'{download_as}',
|
|
|
|
}
|
|
|
|
return flask.Response(binary, headers=outgoing_headers)
|
2022-07-22 23:43:29 +00:00
|
|
|
|
2022-11-08 01:51:02 +00:00
|
|
|
@site.route('/admin/clear_sessions', methods=['POST'])
|
|
|
|
def post_clear_sessions():
|
|
|
|
if not request.is_localhost:
|
|
|
|
return flasktools.json_response({}, status=403)
|
|
|
|
|
|
|
|
session_manager.clear()
|
|
|
|
return flasktools.json_response({})
|
|
|
|
|
2022-07-22 23:43:29 +00:00
|
|
|
@site.route('/admin/reload_config', methods=['POST'])
|
|
|
|
def post_reload_config():
|
|
|
|
if not request.is_localhost:
|
|
|
|
return flasktools.json_response({}, status=403)
|
|
|
|
|
|
|
|
common.P.load_config()
|
|
|
|
return flasktools.json_response({})
|
2022-07-23 02:23:36 +00:00
|
|
|
|
|
|
|
@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({})
|