[Enhance] API & LinkPlay & something else

- Add song names for getting the score list (For API)
- Try to ensure thread safety in Link Play (twice again)
- Small change about database timeout
- Have a try to use `nginx` and `gevent` (Yes. I ensure it works well. This will not be viewed as a formal and necessary update.)
This commit is contained in:
Lost-MSth
2022-10-03 23:46:52 +08:00
parent 299c8c582c
commit 8f1c28eb5c
7 changed files with 118 additions and 88 deletions

View File

@@ -6,7 +6,7 @@ from logging.config import dictConfig
from multiprocessing import Process, set_start_method
from traceback import format_exc
from flask import Flask, request, send_from_directory
from flask import Flask, make_response, request, send_from_directory
import api
import server
@@ -14,14 +14,20 @@ import server.init
import web.index
import web.login
from core.constant import Constant
from core.download import UserDownload, initialize_songfile, get_only_3_song_ids
from core.download import (UserDownload, get_only_3_song_ids,
initialize_songfile)
from core.error import ArcError
from core.sql import Connect
from server.func import error_return
from setting import Config
app = Flask(__name__)
wsgi_app = app.wsgi_app
# 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)
os.chdir(sys.path[0]) # 更改工作路径,以便于愉快使用相对路径
@@ -59,6 +65,10 @@ def download(file_path):
raise ArcError('You have reached the download limit.', 903)
if x.is_valid:
x.insert_user_download()
# response = make_response()
# response.headers['Content-Type'] = 'application/octet-stream'
# response.headers['X-Accel-Redirect'] = '/nginx_download/' + 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:
@@ -68,11 +78,15 @@ def download(file_path):
def tcp_server_run():
if Config.SSL_CERT and Config.SSL_KEY:
app.run(Config.HOST, Config.PORT, ssl_context=(
Config.SSL_CERT, Config.SSL_KEY))
if False:
from gevent.pywsgi import WSGIServer
WSGIServer(("127.0.0.1", 5000), app).serve_forever()
else:
app.run(Config.HOST, Config.PORT)
if Config.SSL_CERT and Config.SSL_KEY:
app.run(Config.HOST, Config.PORT, ssl_context=(
Config.SSL_CERT, Config.SSL_KEY))
else:
app.run(Config.HOST, Config.PORT)
def main():