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):
|
2022-01-16 06:06:16 +00:00
|
|
|
if request.headers.get("Authorization") or request.headers.get("xhr"): return {"error": "400 Bad Request"}, 400
|
2022-01-16 01:47:21 +00:00
|
|
|
else: return render_template('errors/400.html', err=True), 400
|
2021-10-15 14:08:27 +00:00
|
|
|
|
|
|
|
@app.errorhandler(401)
|
|
|
|
def error_401(e):
|
|
|
|
|
2022-01-16 06:06:16 +00:00
|
|
|
if request.headers.get("Authorization") or request.headers.get("xhr"): return {"error": "401 Not Authorized"}, 401
|
2022-01-17 11:06:12 +00:00
|
|
|
else:
|
|
|
|
path = request.path
|
|
|
|
qs = urlencode(dict(request.values))
|
|
|
|
argval = quote(f"{path}?{qs}", safe='')
|
2022-01-24 20:26:15 +00:00
|
|
|
return redirect(f"{SITE_FULL}/login?redirect={argval}")
|
2021-10-15 14:08:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
@app.errorhandler(403)
|
2022-01-09 15:15:02 +00:00
|
|
|
def error_403(e):
|
2022-01-16 06:06:16 +00:00
|
|
|
if request.headers.get("Authorization") or request.headers.get("xhr"): return {"error": "403 Forbidden"}, 403
|
2022-01-16 01:47:21 +00:00
|
|
|
else: return render_template('errors/403.html', err=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):
|
2022-01-16 06:06:16 +00:00
|
|
|
if request.headers.get("Authorization") or request.headers.get("xhr"): return {"error": "404 Not Found"}, 404
|
2022-01-16 01:47:21 +00:00
|
|
|
else: return render_template('errors/404.html', err=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):
|
2022-01-16 06:06:16 +00:00
|
|
|
if request.headers.get("Authorization") or request.headers.get("xhr"): return {"error": "405 Method Not Allowed"}, 405
|
2022-01-16 01:47:21 +00:00
|
|
|
else: return render_template('errors/405.html', err=True), 405
|
2021-10-15 14:08:27 +00:00
|
|
|
|
|
|
|
|
2022-01-16 05:53:32 +00:00
|
|
|
@app.errorhandler(413)
|
|
|
|
def error_413(e):
|
|
|
|
return {"error": "Max file size is 4 MB (8 MB for paypigs)"}, 413
|
|
|
|
|
2021-10-15 14:08:27 +00:00
|
|
|
@app.errorhandler(429)
|
2022-01-09 15:15:02 +00:00
|
|
|
def error_429(e):
|
2022-01-16 06:06:16 +00:00
|
|
|
if request.headers.get("Authorization") or request.headers.get("xhr"): return {"error": "429 Too Many Requests"}, 429
|
2022-01-16 01:47:21 +00:00
|
|
|
else: return render_template('errors/429.html', err=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()
|
|
|
|
|
2022-01-16 06:06:16 +00:00
|
|
|
if request.headers.get("Authorization") or request.headers.get("xhr"): return {"error": "500 Internal Server Error"}, 500
|
2022-01-16 01:47:21 +00:00
|
|
|
else: return render_template('errors/500.html', err=True), 500
|
2021-10-15 14:08:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
@app.post("/allow_nsfw")
|
2022-01-11 22:05:27 +00:00
|
|
|
def allow_nsfw():
|
2021-10-15 14:08:27 +00:00
|
|
|
session["over_18"] = int(time.time()) + 3600
|
2022-01-17 11:06:12 +00:00
|
|
|
redir = request.values.get("redir")
|
2022-01-24 17:37:37 +00:00
|
|
|
if redir and redir.startswith(SITE_FULL) or redir.startswith('/'): return redirect(redir)
|
2022-01-24 20:26:15 +00:00
|
|
|
return redirect(f'{SITE_FULL}/')
|