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
2022-02-06 16:51:52 +00:00
2021-10-15 14:08:27 +00:00
@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-04-02 17:11:35 +00:00
return redirect ( f " /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-04-18 18:25:14 +00:00
description = e . description
if description == " You don ' t have the permission to access the requested resource. It is either read-protected or not readable by the server. " : description = ' '
if request . headers . get ( " Authorization " ) or request . headers . get ( " xhr " ) :
if not description : description = " 403 Forbidden "
return { " error " : description } , 403
else :
if not description : description = " YOU AREN ' T WELCOME HERE GO AWAY "
return render_template ( ' errors/403.html ' , description = description , 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 ) :
2022-04-26 13:01:05 +00:00
return { " error " : " Max file size is 8 MB (16 MB for paypigs) " } , 413
2022-05-01 21:44:38 +00:00
if request . headers . get ( " Authorization " ) or request . headers . get ( " xhr " ) :
2022-05-01 21:48:53 +00:00
return { " error " : " Max file size is 8 MB (16 MB for paypigs) " } , 413
2022-05-01 21:44:38 +00:00
else : return render_template ( ' errors/413.html ' , err = True ) , 413
2022-01-16 05:53:32 +00:00
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-28 20:02:35 +00:00
if redir :
2022-04-17 21:46:29 +00:00
if redir . startswith ( f ' { SITE_FULL } / ' ) : return redirect ( redir )
2022-01-28 20:02:35 +00:00
if redir . startswith ( ' / ' ) : return redirect ( f ' { SITE_FULL } { redir } ' )
2022-04-02 17:11:35 +00:00
return redirect ( ' / ' )