2017-09-16 12:22:17 +02:00
|
|
|
from app import app, db, sentry
|
2021-03-12 11:37:13 +01:00
|
|
|
from flask import g, render_template, make_response, redirect, request
|
2017-09-16 12:22:17 +02:00
|
|
|
import version
|
2017-09-20 23:02:36 +02:00
|
|
|
import libforget.version
|
|
|
|
from libforget.auth import get_viewer_session, set_session_cookie
|
2017-09-16 12:22:17 +02:00
|
|
|
|
|
|
|
|
|
|
|
@app.before_request
|
|
|
|
def load_viewer():
|
|
|
|
g.viewer = get_viewer_session()
|
|
|
|
if g.viewer and sentry:
|
|
|
|
sentry.user_context({
|
|
|
|
'id': g.viewer.account.id,
|
|
|
|
'username': g.viewer.account.screen_name,
|
|
|
|
'service': g.viewer.account.service
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
@app.context_processor
|
|
|
|
def inject_version():
|
2018-01-31 23:11:12 +01:00
|
|
|
v = version.get_versions()
|
2017-09-16 12:22:17 +02:00
|
|
|
return dict(
|
2018-01-31 23:11:12 +01:00
|
|
|
version=v['version'],
|
|
|
|
repo_url=libforget.version.url_for_version(v),
|
2017-09-16 12:22:17 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@app.context_processor
|
|
|
|
def inject_sentry():
|
|
|
|
if sentry:
|
|
|
|
return dict(sentry=True)
|
|
|
|
return dict()
|
|
|
|
|
|
|
|
|
|
|
|
@app.after_request
|
|
|
|
def touch_viewer(resp):
|
|
|
|
if 'viewer' in g and g.viewer:
|
|
|
|
set_session_cookie(g.viewer, resp, app.config.get('HTTPS'))
|
|
|
|
g.viewer.touch()
|
|
|
|
db.session.commit()
|
|
|
|
return resp
|
|
|
|
|
|
|
|
|
|
|
|
@app.errorhandler(404)
|
|
|
|
def not_found(e):
|
|
|
|
return (render_template('404.html', e=e), 404)
|
|
|
|
|
|
|
|
|
|
|
|
@app.errorhandler(500)
|
|
|
|
def internal_server_error(e):
|
2021-03-12 11:37:13 +01:00
|
|
|
if request.endpoint and request.endpoint.startswith('api_'):
|
|
|
|
return e.get_response()
|
2017-09-16 12:22:17 +02:00
|
|
|
return (render_template('500.html', e=e), 500)
|
|
|
|
|
|
|
|
|
|
|
|
@app.route('/robots.txt')
|
|
|
|
def robotstxt():
|
|
|
|
resp = make_response('')
|
|
|
|
resp.headers.set('content-type', 'text/plain')
|
|
|
|
return resp
|
|
|
|
|
|
|
|
|
|
|
|
@app.route('/humans.txt')
|
|
|
|
def humanstxt():
|
|
|
|
return redirect('https://github.com/codl/forget/graph/contributors')
|