55
66from pathlib import Path
77
8- from flask import Flask , send_from_directory , jsonify
8+ from flask import Flask , send_from_directory , jsonify , request , redirect
99
1010
1111app = Flask (__name__ , static_folder = None )
1414psfree_files_dir = current_files_dir / "PSFree"
1515static_files_dir = current_files_dir / "static"
1616is_debug = False
17+ redirect_url = None
1718
1819
1920@app .route ("/api/<path:path>" , methods = ["POST" ])
@@ -49,6 +50,9 @@ def catch_static_routes(path: str = "index.html"):
4950
5051@app .route ("/<path:path>" , methods = ["GET" ])
5152def catch_all_routes (path : str ):
53+ if redirect_url and "playstation.net" in request .host :
54+ return redirect (redirect_url )
55+
5256 file_path = psfree_files_dir / path
5357 return send_from_directory (file_path .parent , file_path .name )
5458
@@ -57,9 +61,11 @@ def catch_all_routes(path: str):
5761@click .option ("--host" , default = "0.0.0.0" , help = "Host to run the server on" )
5862@click .option ("--port" , default = 9191 , help = "Port to run the server on" )
5963@click .option ("--debug" , is_flag = True , help = "Enable debug mode" )
60- def main (host : str , port : int , debug : bool ):
61- global is_debug
64+ @click .option ("--redirect-playstation-domain" , default = None , type = str , help = "Redirect *.playstation.net domain to other URL" )
65+ def main (host : str , port : int , debug : bool , redirect_playstation_domain : str ):
66+ global is_debug , redirect_url
6267 is_debug = debug
68+ redirect_url = redirect_playstation_domain
6369 app .run (host = host , port = port , debug = debug , threaded = True )
6470
6571
0 commit comments