mirror of
https://github.com/Lost-MSth/Arcaea-server.git
synced 2025-12-14 08:06:23 +08:00
Fix some bugs
- Fix a bug that `GET` requests without data will report an error in API - Fix a bug that `aggregate` requests will get an error when the inner function raises an error - Fix a bug that the charts of a course cannot be the same because of the incorrect primary keys - Fix a bug that global ranking scores cannot be calculated if there are no chart in the database #61 - The first try to fix #60 (I don't think it can be done so easily.)
This commit is contained in:
@@ -16,7 +16,8 @@ def role_required(request, powers=[]):
|
||||
@wraps(view)
|
||||
def wrapped_view(*args, **kwargs):
|
||||
try:
|
||||
request.json # 检查请求json格式
|
||||
if request.data:
|
||||
request.json # 检查请求json格式
|
||||
except:
|
||||
return error_return(PostError('Payload must be a valid json', api_error_code=-1), 400)
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ from core.sql import Connect
|
||||
from flask import Blueprint, request
|
||||
|
||||
from .api_auth import api_try, request_json_handle, role_required
|
||||
from .api_code import error_return, success_return
|
||||
from .api_code import success_return
|
||||
|
||||
bp = Blueprint('token', __name__, url_prefix='/token')
|
||||
|
||||
@@ -22,9 +22,9 @@ def token_post(data):
|
||||
try:
|
||||
auth_decode = bytes.decode(b64decode(data['auth']))
|
||||
except:
|
||||
return error_return(PostError(api_error_code=-100))
|
||||
raise PostError(api_error_code=-100)
|
||||
if not ':' in auth_decode:
|
||||
return error_return(PostError(api_error_code=-100))
|
||||
raise PostError(api_error_code=-100)
|
||||
name, password = auth_decode.split(':', 1)
|
||||
|
||||
with Connect() as c:
|
||||
|
||||
@@ -382,7 +382,7 @@ class UserItemList:
|
||||
self.items: list = []
|
||||
for i in x:
|
||||
if len(i) > 1:
|
||||
amount = i[1] if i[1] else 0
|
||||
amount = i[1] if i[1] is not None else 1
|
||||
else:
|
||||
amount = 1
|
||||
self.items.append(ItemFactory.from_dict(
|
||||
|
||||
@@ -619,24 +619,23 @@ class UserInfo(User):
|
||||
with Connect() as c2:
|
||||
c2.execute('''select song_id, rating_ftr, rating_byn from chart''')
|
||||
x = c2.fetchall()
|
||||
if x:
|
||||
song_list_ftr = [self.user_id]
|
||||
song_list_byn = [self.user_id]
|
||||
for i in x:
|
||||
if i[1] > 0:
|
||||
song_list_ftr.append(i[0])
|
||||
if i[2] > 0:
|
||||
song_list_byn.append(i[0])
|
||||
|
||||
song_list_ftr = [self.user_id]
|
||||
song_list_byn = [self.user_id]
|
||||
for i in x:
|
||||
if i[1] > 0:
|
||||
song_list_ftr.append(i[0])
|
||||
if i[2] > 0:
|
||||
song_list_byn.append(i[0])
|
||||
|
||||
score_sum = 0
|
||||
if len(song_list_ftr) >= 2:
|
||||
self.c.execute('''select sum(score) from best_score where user_id=? and difficulty=2 and song_id in ({0})'''.format(
|
||||
','.join(['?']*(len(song_list_ftr)-1))), tuple(song_list_ftr))
|
||||
|
||||
x = self.c.fetchone()
|
||||
if x[0] is not None:
|
||||
score_sum = x[0]
|
||||
else:
|
||||
score_sum = 0
|
||||
score_sum += x[0]
|
||||
|
||||
if len(song_list_byn) >= 2:
|
||||
self.c.execute('''select sum(score) from best_score where user_id=? and difficulty=3 and song_id in ({0})'''.format(
|
||||
@@ -645,8 +644,6 @@ class UserInfo(User):
|
||||
x = self.c.fetchone()
|
||||
if x[0] is not None:
|
||||
score_sum += x[0]
|
||||
else:
|
||||
score_sum += 0
|
||||
|
||||
self.c.execute('''update user set world_rank_score = :b where user_id = :a''', {
|
||||
'a': self.user_id, 'b': score_sum})
|
||||
|
||||
@@ -4,7 +4,7 @@ import json
|
||||
|
||||
# 数据库初始化文件,删掉arcaea_database.db文件后运行即可,谨慎使用
|
||||
|
||||
ARCAEA_SERVER_VERSION = 'v2.9.1'
|
||||
ARCAEA_SERVER_VERSION = 'v2.9.1.dev'
|
||||
|
||||
|
||||
def main(path='./'):
|
||||
@@ -324,7 +324,7 @@ def main(path='./'):
|
||||
difficulty int,
|
||||
flag_as_hidden int,
|
||||
song_index int,
|
||||
primary key(course_id, song_id, difficulty)
|
||||
primary key(course_id, song_index)
|
||||
);''')
|
||||
c.execute('''create table if not exists course_requirement(course_id text,
|
||||
required_id text,
|
||||
|
||||
@@ -58,7 +58,7 @@ def download(file_path):
|
||||
raise ArcError('You have reached the download limit.', 903)
|
||||
if x.is_valid:
|
||||
x.insert_user_download()
|
||||
return send_from_directory(Constant.SONG_FILE_FOLDER_PATH, file_path, as_attachment=True)
|
||||
return send_from_directory(Constant.SONG_FILE_FOLDER_PATH, file_path, as_attachment=True, conditional=True)
|
||||
except ArcError as e:
|
||||
app.logger.warning(format_exc())
|
||||
return error_return(e)
|
||||
|
||||
@@ -82,16 +82,19 @@ def aggregate():
|
||||
{key: value[0] for key, value in parse_qs(urlparse(endpoint).query).items()})
|
||||
|
||||
resp_t = map_dict[urlparse(endpoint).path]()
|
||||
if isinstance(resp_t, tuple):
|
||||
# The response may be a tuple, if it is an error response
|
||||
resp_t = resp_t[0]
|
||||
|
||||
if hasattr(resp_t, "response"):
|
||||
resp_t = resp_t.response[0].decode().rstrip('\n')
|
||||
resp = json.loads(resp_t)
|
||||
|
||||
if hasattr(resp, 'get') and resp.get('success') is False:
|
||||
finally_response = {'success': False, 'error_code': 7, 'extra': {
|
||||
"id": i['id'], 'error_code': resp.get('error_code')}}
|
||||
finally_response = {'success': False, 'error_code': resp.get(
|
||||
'error_code'), 'id': i['id']}
|
||||
if "extra" in resp:
|
||||
finally_response['extra']['extra'] = resp['extra']
|
||||
finally_response['extra'] = resp['extra']
|
||||
#request = request_
|
||||
return jsonify(finally_response)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user