2021-10-15 14:08:27 +00:00
|
|
|
from files.helpers.wrappers import *
|
|
|
|
from flask import *
|
|
|
|
from urllib.parse import quote, urlencode
|
|
|
|
import time
|
|
|
|
from files.__main__ import app, limiter
|
|
|
|
|
|
|
|
|
|
|
|
@app.errorhandler(400)
|
2022-01-09 15:15:02 +00:00
|
|
|
def error_400(e):
|
2021-10-15 14:08:27 +00:00
|
|
|
if request.headers.get("Authorization"): return {"error": "400 Bad Request"}, 400
|
2022-01-09 15:15:02 +00:00
|
|
|
else: return render_template('errors/400.html', error=True), 400
|
2021-10-15 14:08:27 +00:00
|
|
|
|
|
|
|
@app.errorhandler(401)
|
|
|
|
def error_401(e):
|
|
|
|
|
|
|
|
path = request.path
|
|
|
|
qs = urlencode(dict(request.values))
|
|
|
|
argval = quote(f"{path}?{qs}", safe='')
|
|
|
|
output = f"/login?redirect={argval}"
|
|
|
|
|
|
|
|
if request.headers.get("Authorization"): return {"error": "401 Not Authorized"}, 401
|
|
|
|
else: return redirect(output)
|
|
|
|
|
|
|
|
|
|
|
|
@app.errorhandler(403)
|
2022-01-09 15:15:02 +00:00
|
|
|
def error_403(e):
|
2021-10-15 14:08:27 +00:00
|
|
|
if request.headers.get("Authorization"): return {"error": "403 Forbidden"}, 403
|
2022-01-09 15:15:02 +00:00
|
|
|
else: return render_template('errors/403.html', error=True), 403
|
2021-10-15 14:08:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
@app.errorhandler(404)
|
2022-01-09 15:15:02 +00:00
|
|
|
def error_404(e):
|
2021-10-15 14:08:27 +00:00
|
|
|
if request.headers.get("Authorization"): return {"error": "404 Not Found"}, 404
|
2022-01-09 15:15:02 +00:00
|
|
|
else: return render_template('errors/404.html', error=True), 404
|
2021-10-15 14:08:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
@app.errorhandler(405)
|
2022-01-09 15:15:02 +00:00
|
|
|
def error_405(e):
|
2021-10-15 14:08:27 +00:00
|
|
|
if request.headers.get("Authorization"): return {"error": "405 Method Not Allowed"}, 405
|
2022-01-09 15:15:02 +00:00
|
|
|
else: return render_template('errors/405.html', error=True), 405
|
2021-10-15 14:08:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
@app.errorhandler(429)
|
2022-01-09 15:15:02 +00:00
|
|
|
def error_429(e):
|
2021-10-15 14:08:27 +00:00
|
|
|
if request.headers.get("Authorization"): return {"error": "429 Too Many Requests"}, 429
|
2022-01-09 15:15:02 +00:00
|
|
|
else: return render_template('errors/429.html', error=True), 429
|
2021-10-15 14:08:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
@app.errorhandler(500)
|
2022-01-09 15:15:02 +00:00
|
|
|
def error_500(e):
|
2021-10-15 14:08:27 +00:00
|
|
|
g.db.rollback()
|
|
|
|
|
|
|
|
if request.headers.get("Authorization"): return {"error": "500 Internal Server Error"}, 500
|
2022-01-09 15:15:02 +00:00
|
|
|
else: return render_template('errors/500.html', error=True), 500
|
2021-10-15 14:08:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
@app.post("/allow_nsfw")
|
2022-01-11 21:54:41 +00:00
|
|
|
@auth_required
|
2022-01-11 21:53:49 +00:00
|
|
|
def allow_nsfw(v):
|
2021-10-15 14:08:27 +00:00
|
|
|
session["over_18"] = int(time.time()) + 3600
|
2022-01-11 21:53:49 +00:00
|
|
|
return redirect(request.values.get("redir", "/"))
|