mirror of
https://github.com/Lost-MSth/Arcaea-server.git
synced 2026-02-10 18:07:28 +08:00
[Enhance] Add download error status code
This commit is contained in:
@@ -93,7 +93,7 @@ class UserDownload:
|
|||||||
|
|
||||||
x = self.c.fetchone()
|
x = self.c.fetchone()
|
||||||
if not x:
|
if not x:
|
||||||
raise NoAccess('The token `%s` is not valid.' % self.token)
|
raise NoAccess('The token `%s` is not valid.' % self.token, status=403)
|
||||||
self.user = User()
|
self.user = User()
|
||||||
self.user.user_id = x[0]
|
self.user.user_id = x[0]
|
||||||
self.token_time = x[1]
|
self.token_time = x[1]
|
||||||
|
|||||||
@@ -62,14 +62,16 @@ def download(file_path):
|
|||||||
x.song_id, x.file_name = file_path.split('/', 1)
|
x.song_id, x.file_name = file_path.split('/', 1)
|
||||||
x.select_for_check()
|
x.select_for_check()
|
||||||
if x.is_limited:
|
if x.is_limited:
|
||||||
raise ArcError('You have reached the download limit.', 903)
|
raise ArcError(
|
||||||
if x.is_valid:
|
'You have reached the download limit.', 903, status=403)
|
||||||
x.insert_user_download()
|
if not x.is_valid:
|
||||||
# response = make_response()
|
raise ArcError('Expired token.', status=403)
|
||||||
# response.headers['Content-Type'] = 'application/octet-stream'
|
x.insert_user_download()
|
||||||
# response.headers['X-Accel-Redirect'] = '/nginx_download/' + file_path
|
# response = make_response()
|
||||||
# return response
|
# response.headers['Content-Type'] = 'application/octet-stream'
|
||||||
return send_from_directory(Constant.SONG_FILE_FOLDER_PATH, file_path, as_attachment=True, conditional=True)
|
# response.headers['X-Accel-Redirect'] = '/nginx_download/' + file_path
|
||||||
|
# return response
|
||||||
|
return send_from_directory(Constant.SONG_FILE_FOLDER_PATH, file_path, as_attachment=True, conditional=True)
|
||||||
except ArcError as e:
|
except ArcError as e:
|
||||||
if Config.ALLOW_WARNING_LOG:
|
if Config.ALLOW_WARNING_LOG:
|
||||||
app.logger.warning(format_exc())
|
app.logger.warning(format_exc())
|
||||||
|
|||||||
Reference in New Issue
Block a user