[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:
Lost-MSth
2022-10-16 17:07:32 +08:00
parent ba36190f30
commit d150553e6b
8 changed files with 50 additions and 273 deletions

View File

@@ -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=(