add endpoint to access and clear existing known instances cookie

This commit is contained in:
codl 2019-03-15 17:18:43 +01:00
parent b57f71ae58
commit 8cf12f31c8
No known key found for this signature in database
GPG Key ID: 6CD7C8891ED1233A
1 changed files with 16 additions and 1 deletions

View File

@ -1,6 +1,6 @@
from app import app, db from app import app, db
from libforget.auth import require_auth_api, get_viewer from libforget.auth import require_auth_api, get_viewer
from flask import jsonify, redirect, make_response, request from flask import jsonify, redirect, make_response, request, Response
from model import Account from model import Account
import libforget.settings import libforget.settings
import libforget.json import libforget.json
@ -59,3 +59,18 @@ def users_badge():
return redirect( return redirect(
"https://img.shields.io/badge/active%20users-{}-blue.svg" "https://img.shields.io/badge/active%20users-{}-blue.svg"
.format(count)) .format(count))
@app.route('/api/known_instances', methods=('GET', 'DELETE'))
def known_instances():
if request.method == 'GET':
known = request.cookies.get('forget_known_instances', '')
if not known:
return Response('[]', 404, mimetype='application/json')
return Response(known, mimetype='application/json')
elif request.method == 'DELETE':
resp = Response('', 204)
resp.set_cookie('forget_known_instances', '', max_age=0)
return resp