fix 上下文出错的bug
This commit is contained in:
parent
7d27d566cc
commit
33803a44ce
@ -27,4 +27,4 @@ except:
|
|||||||
# PYWXDUMP_ROOT_PATH = os.path.dirname(__file__)
|
# PYWXDUMP_ROOT_PATH = os.path.dirname(__file__)
|
||||||
# db_init = DBPool("DBPOOL_INIT")
|
# db_init = DBPool("DBPOOL_INIT")
|
||||||
|
|
||||||
__version__ = "3.1.2"
|
__version__ = "3.1.3"
|
||||||
|
@ -57,72 +57,72 @@ def start_falsk(merge_path="", wx_path="", key="", my_wxid="", port=5000, online
|
|||||||
host = "127.0.0.1"
|
host = "127.0.0.1"
|
||||||
|
|
||||||
app = Flask(__name__, template_folder='./ui/web', static_folder='./ui/web/assets/', static_url_path='/assets/')
|
app = Flask(__name__, template_folder='./ui/web', static_folder='./ui/web/assets/', static_url_path='/assets/')
|
||||||
|
with app.app_context():
|
||||||
|
# 设置超时时间为 1000 秒
|
||||||
|
app.config['TIMEOUT'] = 1000
|
||||||
|
app.secret_key = 'secret_key'
|
||||||
|
|
||||||
# 设置超时时间为 1000 秒
|
app.logger.setLevel(logging.WARNING)
|
||||||
app.config['TIMEOUT'] = 1000
|
if loger_handler:
|
||||||
app.secret_key = 'secret_key'
|
app.logger.addHandler(loger_handler)
|
||||||
|
# 获取 Werkzeug 的日志记录器
|
||||||
|
werkzeug_logger = logging.getLogger('werkzeug')
|
||||||
|
# 将自定义格式器应用到 Werkzeug 的日志记录器
|
||||||
|
werkzeug_logger.addHandler(loger_handler)
|
||||||
|
werkzeug_logger.setLevel(logging.DEBUG)
|
||||||
|
|
||||||
app.logger.setLevel(logging.WARNING)
|
CORS(app, resources={r"/*": {"origins": "*"}}, supports_credentials=True) # 允许所有域名跨域
|
||||||
if loger_handler:
|
|
||||||
app.logger.addHandler(loger_handler)
|
|
||||||
# 获取 Werkzeug 的日志记录器
|
|
||||||
werkzeug_logger = logging.getLogger('werkzeug')
|
|
||||||
# 将自定义格式器应用到 Werkzeug 的日志记录器
|
|
||||||
werkzeug_logger.addHandler(loger_handler)
|
|
||||||
werkzeug_logger.setLevel(logging.DEBUG)
|
|
||||||
|
|
||||||
CORS(app, resources={r"/*": {"origins": "*"}}, supports_credentials=True) # 允许所有域名跨域
|
@app.after_request # 请求后的处理 用于解决部分用户浏览器不支持flask以及vue的js文件返回问题
|
||||||
|
def changeHeader(response):
|
||||||
|
disposition = response.get_wsgi_headers('environ').get(
|
||||||
|
'Content-Disposition') or '' # 获取返回头文件名描述,如'inline; filename=index.562b9b5a.js'
|
||||||
|
if disposition.rfind('.js') == len(disposition) - 3:
|
||||||
|
response.mimetype = 'application/javascript'
|
||||||
|
return response
|
||||||
|
|
||||||
@app.after_request # 请求后的处理 用于解决部分用户浏览器不支持flask以及vue的js文件返回问题
|
@app.before_request
|
||||||
def changeHeader(response):
|
def before_request():
|
||||||
disposition = response.get_wsgi_headers('environ').get(
|
g.work_path = work_path # 临时文件夹,用于存放图片等-新版本
|
||||||
'Content-Disposition') or '' # 获取返回头文件名描述,如'inline; filename=index.562b9b5a.js'
|
g.caf = conf_auto_file # 用于存放各种基础信息-新版本
|
||||||
if disposition.rfind('.js') == len(disposition) - 3:
|
g.at = "auto_setting" # 用于默认设置-新版本
|
||||||
response.mimetype = 'application/javascript'
|
|
||||||
return response
|
|
||||||
|
|
||||||
@app.before_request
|
if merge_path: set_conf(conf_auto_file, g.at, "merge_path", merge_path)
|
||||||
def before_request():
|
if wx_path: set_conf(conf_auto_file, g.at, "wx_path", wx_path)
|
||||||
g.work_path = work_path # 临时文件夹,用于存放图片等-新版本
|
if key: set_conf(conf_auto_file, g.at, "key", key)
|
||||||
g.caf = conf_auto_file # 用于存放各种基础信息-新版本
|
if my_wxid: set_conf(conf_auto_file, g.at, "my_wxid", my_wxid)
|
||||||
g.at = "auto_setting" # 用于默认设置-新版本
|
if not os.path.exists(conf_auto_file):
|
||||||
|
set_conf(conf_auto_file, g.at, "last", my_wxid)
|
||||||
|
|
||||||
if merge_path: set_conf(conf_auto_file, g.at, "merge_path", merge_path)
|
app.register_blueprint(rs_api)
|
||||||
if wx_path: set_conf(conf_auto_file, g.at, "wx_path", wx_path)
|
app.register_blueprint(ls_api)
|
||||||
if key: set_conf(conf_auto_file, g.at, "key", key)
|
|
||||||
if my_wxid: set_conf(conf_auto_file, g.at, "my_wxid", my_wxid)
|
|
||||||
if not os.path.exists(conf_auto_file):
|
|
||||||
set_conf(conf_auto_file, g.at, "last", my_wxid)
|
|
||||||
|
|
||||||
app.register_blueprint(rs_api)
|
if isopenBrowser:
|
||||||
app.register_blueprint(ls_api)
|
try:
|
||||||
|
# 自动打开浏览器
|
||||||
|
url = f"http://127.0.0.1:{port}/"
|
||||||
|
# 根据操作系统使用不同的命令打开默认浏览器
|
||||||
|
if sys.platform.startswith('darwin'): # macOS
|
||||||
|
subprocess.call(['open', url])
|
||||||
|
elif sys.platform.startswith('win'): # Windows
|
||||||
|
subprocess.call(['start', url], shell=True)
|
||||||
|
elif sys.platform.startswith('linux'): # Linux
|
||||||
|
subprocess.call(['xdg-open', url])
|
||||||
|
else:
|
||||||
|
server_loger.error(f"Unsupported platform, can't open browser automatically.", exc_info=True)
|
||||||
|
print("Unsupported platform, can't open browser automatically.")
|
||||||
|
except Exception as e:
|
||||||
|
server_loger.error(f"自动打开浏览器失败:{e}", exc_info=True)
|
||||||
|
|
||||||
if isopenBrowser:
|
if is_port_in_use(host, port):
|
||||||
try:
|
server_loger.error(f"Port {port} is already in use. Choose a different port.")
|
||||||
# 自动打开浏览器
|
print(f"Port {port} is already in use. Choose a different port.")
|
||||||
url = f"http://127.0.0.1:{port}/"
|
input("Press Enter to exit...")
|
||||||
# 根据操作系统使用不同的命令打开默认浏览器
|
else:
|
||||||
if sys.platform.startswith('darwin'): # macOS
|
time.sleep(1)
|
||||||
subprocess.call(['open', url])
|
server_loger.info(f"启动flask服务,host:port:{host}:{port}")
|
||||||
elif sys.platform.startswith('win'): # Windows
|
print("[+] 请使用浏览器访问 http://127.0.0.1:5000/ 查看聊天记录")
|
||||||
subprocess.call(['start', url], shell=True)
|
app.run(host=host, port=port, debug=debug, threaded=False)
|
||||||
elif sys.platform.startswith('linux'): # Linux
|
|
||||||
subprocess.call(['xdg-open', url])
|
|
||||||
else:
|
|
||||||
server_loger.error(f"Unsupported platform, can't open browser automatically.", exc_info=True)
|
|
||||||
print("Unsupported platform, can't open browser automatically.")
|
|
||||||
except Exception as e:
|
|
||||||
server_loger.error(f"自动打开浏览器失败:{e}", exc_info=True)
|
|
||||||
|
|
||||||
if is_port_in_use(host, port):
|
|
||||||
server_loger.error(f"Port {port} is already in use. Choose a different port.")
|
|
||||||
print(f"Port {port} is already in use. Choose a different port.")
|
|
||||||
input("Press Enter to exit...")
|
|
||||||
else:
|
|
||||||
time.sleep(1)
|
|
||||||
server_loger.info(f"启动flask服务,host:port:{host}:{port}")
|
|
||||||
print("[+] 请使用浏览器访问 http://127.0.0.1:5000/ 查看聊天记录")
|
|
||||||
app.run(host=host, port=port, debug=debug)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
Loading…
Reference in New Issue
Block a user