mirror of
https://github.com/Lost-MSth/Arcaea-server.git
synced 2025-12-14 08:06:23 +08:00
[Enhance] API query param
- Add support for the `query` param in `GET` requests
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
from functools import wraps
|
||||
from traceback import format_exc
|
||||
from base64 import b64decode
|
||||
from json import loads
|
||||
|
||||
from core.api_user import APIUser
|
||||
from core.config_manager import Config
|
||||
@@ -60,17 +62,24 @@ def request_json_handle(request, required_keys=[], optional_keys=[]):
|
||||
def wrapped_view(*args, **kwargs):
|
||||
|
||||
data = {}
|
||||
if not request.data:
|
||||
return view(data, *args, **kwargs)
|
||||
if request.data:
|
||||
json_data = request.json
|
||||
else:
|
||||
if request.method == 'GET' and 'query' in request.args:
|
||||
# 处理axios没法GET传data的问题
|
||||
json_data = loads(
|
||||
b64decode(request.args['query']).decode())
|
||||
else:
|
||||
return view(data, *args, **kwargs)
|
||||
|
||||
for key in required_keys:
|
||||
if key not in request.json:
|
||||
if key not in json_data:
|
||||
return error_return(PostError('Missing parameter: ' + key, api_error_code=-100))
|
||||
data[key] = request.json[key]
|
||||
data[key] = json_data[key]
|
||||
|
||||
for key in optional_keys:
|
||||
if key in request.json:
|
||||
data[key] = request.json[key]
|
||||
if key in json_data:
|
||||
data[key] = json_data[key]
|
||||
|
||||
return view(data, *args, **kwargs)
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ def users_get(data, user):
|
||||
'name': x.name,
|
||||
'join_date': x.join_date,
|
||||
'user_code': x.user_code,
|
||||
'rating_ptt': x.rating_ptt/100,
|
||||
'rating_ptt': x.rating_ptt,
|
||||
'character_id': x.character.character_id,
|
||||
'is_char_uncapped': x.character.is_uncapped,
|
||||
'is_char_uncapped_override': x.character.is_uncapped_override,
|
||||
|
||||
@@ -83,7 +83,7 @@ class Config:
|
||||
class ConfigManager:
|
||||
|
||||
@staticmethod
|
||||
def load(config):
|
||||
def load(config) -> None:
|
||||
for k, v in config.__dict__.items():
|
||||
if k.startswith('__') or k.endswith('__'):
|
||||
continue
|
||||
|
||||
Reference in New Issue
Block a user