mirror of
https://github.com/Lost-MSth/Arcaea-server.git
synced 2026-02-04 13:17:27 +08:00
[Enhance][Bug fix] Waitress & API token
- Fix a bug that using API token in config file will not success - Add deployment mode `waitress`
This commit is contained in:
@@ -27,12 +27,12 @@ def role_required(request, powers=[]):
|
|||||||
return error_return(PostError('No token', api_error_code=-1), 401)
|
return error_return(PostError('No token', api_error_code=-1), 401)
|
||||||
|
|
||||||
user = APIUser()
|
user = APIUser()
|
||||||
if Config.API_TOKEN == request.headers['Token'] and Config.API_TOKEN != '':
|
with Connect() as c:
|
||||||
user.set_role_system()
|
user.c = c
|
||||||
else:
|
if Config.API_TOKEN == request.headers['Token'] and Config.API_TOKEN != '':
|
||||||
with Connect() as c:
|
user.set_role_system()
|
||||||
|
else:
|
||||||
try:
|
try:
|
||||||
user.c = c
|
|
||||||
user.select_user_id_from_api_token(
|
user.select_user_id_from_api_token(
|
||||||
request.headers['Token'])
|
request.headers['Token'])
|
||||||
user.select_role_and_powers()
|
user.select_role_and_powers()
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ class Config:
|
|||||||
HOST = '0.0.0.0'
|
HOST = '0.0.0.0'
|
||||||
PORT = 80
|
PORT = 80
|
||||||
|
|
||||||
USE_GEVENT_WSGI = False
|
DEPLOY_MODE = 'flask_multithread'
|
||||||
USE_PROXY_FIX = False
|
USE_PROXY_FIX = False
|
||||||
USE_CORS = False
|
USE_CORS = False
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import sqlite3
|
import sqlite3
|
||||||
import traceback
|
import traceback
|
||||||
|
from atexit import register
|
||||||
|
|
||||||
from flask import current_app
|
from flask import current_app
|
||||||
|
|
||||||
@@ -367,5 +368,7 @@ class MemoryDatabase:
|
|||||||
'''create index if not exists download_token_1 on download_token (song_id, file_name);''')
|
'''create index if not exists download_token_1 on download_token (song_id, file_name);''')
|
||||||
self.conn.commit()
|
self.conn.commit()
|
||||||
|
|
||||||
def atexit(self):
|
|
||||||
self.conn.close()
|
@register
|
||||||
|
def atexit():
|
||||||
|
MemoryDatabase.conn.close()
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ if os.path.exists('config.py') or os.path.exists('config'):
|
|||||||
# 导入用户自定义配置
|
# 导入用户自定义配置
|
||||||
ConfigManager.load(import_module('config').Config)
|
ConfigManager.load(import_module('config').Config)
|
||||||
|
|
||||||
if Config.USE_GEVENT_WSGI:
|
if Config.DEPLOY_MODE == 'gevent':
|
||||||
# 异步
|
# 异步
|
||||||
from gevent import monkey
|
from gevent import monkey
|
||||||
monkey.patch_all()
|
monkey.patch_all()
|
||||||
@@ -99,12 +99,19 @@ def download(file_path):
|
|||||||
|
|
||||||
|
|
||||||
def tcp_server_run():
|
def tcp_server_run():
|
||||||
if Config.USE_GEVENT_WSGI:
|
if Config.DEPLOY_MODE == 'gevent':
|
||||||
# 异步 gevent WSGI server
|
# 异步 gevent WSGI server
|
||||||
host_port = (Config.HOST, Config.PORT)
|
host_port = (Config.HOST, Config.PORT)
|
||||||
app.logger.info('Running gevent WSGI server... (%s:%s)' % host_port)
|
app.logger.info('Running gevent WSGI server... (%s:%s)' % host_port)
|
||||||
from gevent.pywsgi import WSGIServer
|
from gevent.pywsgi import WSGIServer
|
||||||
WSGIServer(host_port, app, log=app.logger).serve_forever()
|
WSGIServer(host_port, app, log=app.logger).serve_forever()
|
||||||
|
elif Config.DEPLOY_MODE == 'waitress':
|
||||||
|
# waitress WSGI server
|
||||||
|
from waitress import serve
|
||||||
|
import logging
|
||||||
|
logger = logging.getLogger('waitress')
|
||||||
|
logger.setLevel(logging.INFO)
|
||||||
|
serve(app, host=Config.HOST, port=Config.PORT)
|
||||||
else:
|
else:
|
||||||
if Config.SSL_CERT and Config.SSL_KEY:
|
if Config.SSL_CERT and Config.SSL_KEY:
|
||||||
app.run(Config.HOST, Config.PORT, ssl_context=(
|
app.run(Config.HOST, Config.PORT, ssl_context=(
|
||||||
|
|||||||
Reference in New Issue
Block a user