mirror of
https://github.com/Lost-MSth/Arcaea-server.git
synced 2025-12-14 08:06:23 +08:00
[Enhance] Game new/old API prefix list support
- Add some endpoints for old API prefixes to notify users to update the client; add support for multiple game prefixes
This commit is contained in:
@@ -12,7 +12,8 @@ class Config:
|
||||
|
||||
SONG_FILE_HASH_PRE_CALCULATE = True
|
||||
|
||||
GAME_API_PREFIX = '/samusugiru/26'
|
||||
GAME_API_PREFIX = '/samusugiru/26' # str | list[str]
|
||||
OLD_GAME_API_PREFIX = [] # str | list[str]
|
||||
|
||||
ALLOW_APPVERSION = [] # list[str]
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ app.config['SESSION_TYPE'] = 'filesystem'
|
||||
app.register_blueprint(web.login.bp)
|
||||
app.register_blueprint(web.index.bp)
|
||||
app.register_blueprint(api.bp)
|
||||
app.register_blueprint(server.bp)
|
||||
list(map(app.register_blueprint, server.get_bps()))
|
||||
# app.register_blueprint(webapi.bp)
|
||||
|
||||
|
||||
|
||||
@@ -1,18 +1,39 @@
|
||||
from flask import Blueprint
|
||||
from flask import Blueprint, jsonify
|
||||
|
||||
from core.config_manager import Config
|
||||
|
||||
from . import (auth, course, friend, multiplayer, others, present, purchase,
|
||||
score, user, world)
|
||||
|
||||
bp = Blueprint('server', __name__, url_prefix=Config.GAME_API_PREFIX)
|
||||
bp.register_blueprint(user.bp)
|
||||
bp.register_blueprint(auth.bp)
|
||||
bp.register_blueprint(friend.bp)
|
||||
bp.register_blueprint(score.bp)
|
||||
bp.register_blueprint(world.bp)
|
||||
bp.register_blueprint(purchase.bp)
|
||||
bp.register_blueprint(present.bp)
|
||||
bp.register_blueprint(others.bp)
|
||||
bp.register_blueprint(multiplayer.bp)
|
||||
bp.register_blueprint(course.bp)
|
||||
|
||||
__bp_old = Blueprint('old_server', __name__)
|
||||
|
||||
|
||||
@__bp_old.route('/<path:any>', methods=['GET', 'POST']) # 旧版 API 提示
|
||||
def server_hello(any):
|
||||
return jsonify({"success": False, "error_code": 5})
|
||||
|
||||
|
||||
def get_bps():
|
||||
def string_to_list(s):
|
||||
if isinstance(s, str):
|
||||
s = [s]
|
||||
elif not isinstance(s, list):
|
||||
s = []
|
||||
return s
|
||||
|
||||
bp = Blueprint('server', __name__)
|
||||
list(map(bp.register_blueprint, [user.bp, auth.bp, friend.bp, score.bp,
|
||||
world.bp, purchase.bp, present.bp, others.bp, multiplayer.bp, course.bp]))
|
||||
|
||||
bps = [Blueprint(x, __name__, url_prefix=x)
|
||||
for x in string_to_list(Config.GAME_API_PREFIX)]
|
||||
for x in bps:
|
||||
x.register_blueprint(bp)
|
||||
|
||||
old_bps = [Blueprint(x, __name__, url_prefix=x)
|
||||
for x in string_to_list(Config.OLD_GAME_API_PREFIX)]
|
||||
for x in old_bps:
|
||||
x.register_blueprint(__bp_old)
|
||||
|
||||
return bps + old_bps
|
||||
|
||||
@@ -106,7 +106,7 @@ def header_check(request) -> ArcError:
|
||||
headers = request.headers
|
||||
if Config.ALLOW_APPVERSION: # 版本检查
|
||||
if 'AppVersion' not in headers or headers['AppVersion'] not in Config.ALLOW_APPVERSION:
|
||||
return NoAccess('Invalid app version', 1203)
|
||||
return NoAccess('Invalid app version', 5)
|
||||
|
||||
if has_arc_hash and not ArcHashChecker(request).check():
|
||||
return NoAccess('Invalid request')
|
||||
|
||||
Reference in New Issue
Block a user