[Enhance] Add limiter & Building API

- Add a custom limiter and use it for limiting users' download instead of using database
> So add a requirement `limits`.

- Fix a character's value
- Change the email max length to 64
- Change something about API's roles and powers
- Add an API endpoint for getting users' roles and powers
This commit is contained in:
Lost-MSth
2022-10-12 15:27:45 +08:00
parent a04df8bba6
commit 68a83a29d2
13 changed files with 140 additions and 104 deletions

View File

@@ -26,10 +26,7 @@ def role_required(request, powers=[]):
user = APIUser()
if Config.API_TOKEN == request.headers['Token'] and Config.API_TOKEN != '':
user.user_id = 0
elif powers == []:
# 无powers则非本地权限API_TOKEN规定的无法访问
return error_return(NoAccess('No permission', api_error_code=-1), 403)
user.set_role_system()
else:
with Connect() as c:
try:
@@ -38,7 +35,7 @@ def role_required(request, powers=[]):
request.headers['Token'])
user.select_role_and_powers()
if not any([y in [x.power_name for x in user.role.powers] for y in powers]):
if not any(user.role.has_power(y) for y in powers):
return error_return(NoAccess('No permission', api_error_code=-1), 403)
except ArcError as e:
return error_return(e, 401)