mirror of
https://github.com/Lost-MSth/Arcaea-server.git
synced 2026-02-07 16:27:26 +08:00
[Enhance] Some config options & Login limiter
- Add limiter for login and API login - Add some config options - Delete `setting.py` files
This commit is contained in:
@@ -12,6 +12,7 @@ from flask import Flask, make_response, request, send_from_directory
|
||||
from core.config_manager import Config, ConfigManager
|
||||
|
||||
if os.path.exists('config.py') or os.path.exists('config'):
|
||||
# 导入用户自定义配置
|
||||
ConfigManager.load(import_module('config').Config)
|
||||
|
||||
|
||||
@@ -29,10 +30,14 @@ from server.func import error_return
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
# from werkzeug.middleware.proxy_fix import ProxyFix
|
||||
# app.wsgi_app = ProxyFix(app.wsgi_app, x_proto=1, x_host=1)
|
||||
# from flask_cors import CORS
|
||||
# CORS(app, supports_credentials=True)
|
||||
if Config.USE_PROXY_FIX:
|
||||
# 代理修复
|
||||
from werkzeug.middleware.proxy_fix import ProxyFix
|
||||
app.wsgi_app = ProxyFix(app.wsgi_app, x_proto=1, x_host=1)
|
||||
if Config.USE_CORS:
|
||||
# 服务端跨域
|
||||
from flask_cors import CORS
|
||||
CORS(app, supports_credentials=True)
|
||||
|
||||
|
||||
os.chdir(sys.path[0]) # 更改工作路径,以便于愉快使用相对路径
|
||||
@@ -73,10 +78,12 @@ def download(file_path):
|
||||
if not x.is_valid:
|
||||
raise NoAccess('Expired token.')
|
||||
x.download_hit()
|
||||
# response = make_response()
|
||||
# response.headers['Content-Type'] = 'application/octet-stream'
|
||||
# response.headers['X-Accel-Redirect'] = '/nginx_download/' + file_path
|
||||
# return response
|
||||
if Config.DOWNLOAD_USE_NGINX_X_ACCEL_REDIRECT:
|
||||
# nginx X-Accel-Redirect
|
||||
response = make_response()
|
||||
response.headers['Content-Type'] = 'application/octet-stream'
|
||||
response.headers['X-Accel-Redirect'] = Config.NGINX_X_ACCEL_REDIRECT_PREFIX + file_path
|
||||
return response
|
||||
return send_from_directory(Constant.SONG_FILE_FOLDER_PATH, file_path, as_attachment=True, conditional=True)
|
||||
except ArcError as e:
|
||||
if Config.ALLOW_WARNING_LOG:
|
||||
@@ -86,9 +93,12 @@ def download(file_path):
|
||||
|
||||
|
||||
def tcp_server_run():
|
||||
if False:
|
||||
if Config.USE_GEVENT_WSGI:
|
||||
# 异步 gevent WSGI server
|
||||
host_port = (Config.HOST, Config.PORT)
|
||||
app.logger.info('Running gevent WSGI server... (%s:%s)' % host_port)
|
||||
from gevent.pywsgi import WSGIServer
|
||||
WSGIServer(("127.0.0.1", 5000), app).serve_forever()
|
||||
WSGIServer(host_port, app).serve_forever()
|
||||
else:
|
||||
if Config.SSL_CERT and Config.SSL_KEY:
|
||||
app.run(Config.HOST, Config.PORT, ssl_context=(
|
||||
|
||||
Reference in New Issue
Block a user