mirror of
https://github.com/codl/forget
synced 2024-12-14 01:14:34 +01:00
58 lines
1.4 KiB
Python
58 lines
1.4 KiB
Python
from app import app, db
|
|
from libforget.auth import require_auth_api, get_viewer
|
|
from flask import jsonify, redirect, make_response, request
|
|
from model import Account
|
|
import libforget.settings
|
|
import libforget.json
|
|
|
|
@app.route('/api/health_check')
|
|
def health_check():
|
|
try:
|
|
db.session.execute('SELECT 1')
|
|
return 'ok'
|
|
except Exception:
|
|
return ('bad', 500)
|
|
|
|
|
|
@app.route('/api/settings', methods=('PUT',))
|
|
@require_auth_api
|
|
def api_settings_put():
|
|
viewer = get_viewer()
|
|
data = request.json
|
|
updated = dict()
|
|
for key in libforget.settings.attrs:
|
|
if key in data:
|
|
setattr(viewer, key, data[key])
|
|
updated[key] = data[key]
|
|
db.session.commit()
|
|
return jsonify(status='success', updated=updated)
|
|
|
|
|
|
@app.route('/api/viewer')
|
|
@require_auth_api
|
|
def api_viewer():
|
|
viewer = get_viewer()
|
|
resp = make_response(libforget.json.account(viewer))
|
|
resp.headers.set('content-type', 'application/json')
|
|
return resp
|
|
|
|
|
|
@app.route('/api/reason', methods={'DELETE'})
|
|
@require_auth_api
|
|
def delete_reason():
|
|
get_viewer().reason = None
|
|
db.session.commit()
|
|
return jsonify(status='success')
|
|
|
|
|
|
@app.route('/api/badge/users')
|
|
def users_badge():
|
|
count = (
|
|
Account.query.filter(Account.policy_enabled)
|
|
.filter(~Account.dormant)
|
|
.count()
|
|
)
|
|
return redirect(
|
|
"https://img.shields.io/badge/active%20users-{}-blue.svg"
|
|
.format(count))
|