2022-05-04 23:09:46 +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 )
def error_400 ( e ) :
if request . headers . get ( " Authorization " ) or request . headers . get ( " xhr " ) : return { " error " : " 400 Bad Request " } , 400
else : return render_template ( ' errors/400.html ' , err = True ) , 400
@app.errorhandler ( 401 )
def error_401 ( e ) :
if request . headers . get ( " Authorization " ) or request . headers . get ( " xhr " ) : return { " error " : " 401 Not Authorized " } , 401
else :
path = request . path
qs = urlencode ( dict ( request . values ) )
2022-09-01 19:24:06 +00:00
argval = quote ( f " { path } ? { qs } " , safe = ' ' ) . replace ( ' /logged_out ' , ' ' )
if not argval : argval = ' / '
2022-08-24 22:43:44 +00:00
if session . get ( " history " ) : return redirect ( f " /login?redirect= { argval } " )
else : return redirect ( f " /signup?redirect= { argval } " )
2022-05-04 23:09:46 +00:00
2022-07-29 13:23:34 +00:00
@app.errorhandler ( 406 )
def error_406 ( e ) :
2022-08-21 20:17:55 +00:00
if request . headers . get ( " Authorization " ) or request . headers . get ( " xhr " ) :
return { " error " : " Too many pings: max limit is 5 for comments and 50 for posts " } , 406
2022-07-29 13:23:34 +00:00
else : return render_template ( ' errors/406.html ' , err = True ) , 406
2022-05-04 23:09:46 +00:00
@app.errorhandler ( 403 )
def error_403 ( e ) :
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
@app.errorhandler ( 404 )
def error_404 ( e ) :
if request . headers . get ( " Authorization " ) or request . headers . get ( " xhr " ) : return { " error " : " 404 Not Found " } , 404
else : return render_template ( ' errors/404.html ' , err = True ) , 404
@app.errorhandler ( 405 )
def error_405 ( e ) :
if request . headers . get ( " Authorization " ) or request . headers . get ( " xhr " ) : return { " error " : " 405 Method Not Allowed " } , 405
else : return render_template ( ' errors/405.html ' , err = True ) , 405
@app.errorhandler ( 413 )
def error_413 ( e ) :
if request . headers . get ( " Authorization " ) or request . headers . get ( " xhr " ) :
2022-05-22 22:15:29 +00:00
return { " error " : " Max image/audio size is 8 MB (16 MB for paypigs) " } , 413
2022-05-04 23:09:46 +00:00
else : return render_template ( ' errors/413.html ' , err = True ) , 413
2022-10-06 04:31:08 +00:00
@app.errorhandler ( 414 )
def error_414 ( e ) :
if request . headers . get ( " Authorization " ) or request . headers . get ( " xhr " ) :
return { " error " : " Max video size is 32 MB (64 MB for paypigs) " } , 414
else : return render_template ( ' errors/414.html ' , err = True ) , 414
2022-06-19 16:56:45 +00:00
@app.errorhandler ( 415 )
def error_415 ( e ) :
if request . headers . get ( " Authorization " ) or request . headers . get ( " xhr " ) : return { " error " : " Please upload only Image, Video, or Audio files! " } , 415
else : return render_template ( ' errors/415.html ' , err = True ) , 415
2022-09-27 01:24:20 +00:00
@app.errorhandler ( 417 )
def error_417 ( e ) :
return { " error " : " Image already exists! " } , 417
2022-06-19 14:49:44 +00:00
@app.errorhandler ( 418 )
def error_418 ( e ) :
if request . headers . get ( " Authorization " ) or request . headers . get ( " xhr " ) :
return { " error " : " WEBM videos are not allowed, please convert your video to MP4 and re-upload it! " } , 418
else : return render_template ( ' errors/418.html ' , err = True ) , 418
2022-05-04 23:09:46 +00:00
@app.errorhandler ( 429 )
def error_429 ( e ) :
if request . headers . get ( " Authorization " ) or request . headers . get ( " xhr " ) : return { " error " : " 429 Too Many Requests " } , 429
else : return render_template ( ' errors/429.html ' , err = True ) , 429
@app.errorhandler ( 500 )
def error_500 ( e ) :
g . db . rollback ( )
if request . headers . get ( " Authorization " ) or request . headers . get ( " xhr " ) : return { " error " : " 500 Internal Server Error " } , 500
else : return render_template ( ' errors/500.html ' , err = True ) , 500
@app.post ( " /allow_nsfw " )
def allow_nsfw ( ) :
session [ " over_18 " ] = int ( time . time ( ) ) + 3600
redir = request . values . get ( " redir " )
2022-07-10 14:21:16 +00:00
if is_site_url ( redir ) : return redirect ( redir )
2022-09-29 05:43:29 +00:00
return redirect ( ' / ' )