Skip to content

Commit

Permalink
optimize code
Browse files Browse the repository at this point in the history
  • Loading branch information
孙永强 committed Jul 10, 2024
1 parent b2a51db commit ead822b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
10 changes: 9 additions & 1 deletion seahub/api2/endpoints/admin/logs_export.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import logging
import time
import json
from shutil import rmtree
from django.http import FileResponse
from rest_framework.authentication import SessionAuthentication
Expand Down Expand Up @@ -52,7 +53,14 @@ def get(self, request):
error_msg = 'task_id invalid.'
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)

is_finished = event_export_status(task_id)
resp = event_export_status(task_id)
if resp.status_code == 500:
logger.error('query export status error: %s, %s' % (task_id, resp.content))
return api_error(500, 'Internal Server Error')
if not resp.status_code == 200:
return api_error(resp.status_code, resp.content)

is_finished = json.loads(resp.content)['is_finished']

return Response({'is_finished': is_finished})

Expand Down
9 changes: 2 additions & 7 deletions seahub/api2/endpoints/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,10 +314,5 @@ def event_export_status(task_id):
url = urljoin(SEAFEVENTS_SERVER_URL, '/query-export-status')
params = {'task_id': task_id}
resp = requests.get(url, params=params, headers=headers)
if resp.status_code == 500:
logger.error('query export status error: %s, %s' % (task_id, resp.content))
return api_error(500, 'Internal Server Error')
if not resp.status_code == 200:
return api_error(resp.status_code, resp.content)
is_finished = json.loads(resp.content)['is_finished']
return is_finished

return resp

0 comments on commit ead822b

Please sign in to comment.