mirror of
https://github.com/Lost-MSth/Arcaea-server.git
synced 2026-02-12 19:17:26 +08:00
[Enhance] Content bundle
- Add support for content bundles - For Arcaea 5.4.0 play store version and iOS version
This commit is contained in:
@@ -27,6 +27,7 @@ import server
|
||||
import web.index
|
||||
import web.login
|
||||
# import webapi
|
||||
from core.bundle import BundleDownload
|
||||
from core.constant import Constant
|
||||
from core.download import UserDownload
|
||||
from core.error import ArcError, NoAccess, RateLimit
|
||||
@@ -81,7 +82,8 @@ def download(file_path):
|
||||
x.song_id, x.file_name = file_path.split('/', 1)
|
||||
x.select_for_check()
|
||||
if x.is_limited:
|
||||
raise RateLimit('You have reached the download limit.', 903)
|
||||
raise RateLimit(
|
||||
f'User `{x.user.user_id}` has reached the download limit.', 903)
|
||||
if not x.is_valid:
|
||||
raise NoAccess('Expired token.')
|
||||
x.download_hit()
|
||||
@@ -99,6 +101,26 @@ def download(file_path):
|
||||
return error_return()
|
||||
|
||||
|
||||
@app.route('/bundle_download/<string:token>', methods=['GET']) # 热更新下载
|
||||
def bundle_download(token: str):
|
||||
with Connect(in_memory=True) as c_m:
|
||||
try:
|
||||
file_path = BundleDownload(c_m).get_path_by_token(
|
||||
token, request.remote_addr)
|
||||
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.CONTENT_BUNDLE_FOLDER_PATH, file_path, as_attachment=True, conditional=True)
|
||||
except ArcError as e:
|
||||
if Config.ALLOW_WARNING_LOG:
|
||||
app.logger.warning(format_exc())
|
||||
return error_return(e)
|
||||
return error_return()
|
||||
|
||||
|
||||
if Config.DEPLOY_MODE == 'waitress':
|
||||
# 给waitress加个日志
|
||||
@app.after_request
|
||||
@@ -124,7 +146,7 @@ def tcp_server_run():
|
||||
elif Config.DEPLOY_MODE == 'waitress':
|
||||
# waitress WSGI server
|
||||
import logging
|
||||
from waitress import serve
|
||||
from waitress import serve # type: ignore
|
||||
logger = logging.getLogger('waitress')
|
||||
logger.setLevel(logging.INFO)
|
||||
serve(app, host=Config.HOST, port=Config.PORT)
|
||||
|
||||
Reference in New Issue
Block a user