Skip to content

Commit

Permalink
fix: sdoc rebase delete file bug (#5669)
Browse files Browse the repository at this point in the history
* fix: sdoc rebase delete file bug

* fix: sdoc rebase delete file bug

* feat: update code

* feat: update code

* feat: update code
  • Loading branch information
YangGuoXuan-0503 authored Oct 8, 2023
1 parent bfbaeaa commit bd34adb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
31 changes: 21 additions & 10 deletions seahub/seadoc/apis.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,15 +257,18 @@ def get(self, request, file_uuid):
error_msg = 'seadoc origin uuid %s not found.' % origin_doc_uuid
return api_error(status.HTTP_404_NOT_FOUND, error_msg)

origin_file_download_link = get_seadoc_download_link(origin_uuid_map, True)
if not origin_file_download_link:
error_msg = 'seadoc origin file %s not found.' % origin_uuid_map.filename
return api_error(status.HTTP_404_NOT_FOUND, error_msg)

resp = requests.get(origin_file_download_link)
return Response({
'content': resp.content
})
# get content from sdoc server
username = request.user.username
sdoc_server_api = SdocServerAPI(origin_doc_uuid, str(origin_uuid_map.filename), username)
try:
res = sdoc_server_api.get_doc()
return Response({
'content': json.dumps(res)
})
except Exception as e:
logger.error(e)
error_msg = 'Internal Server Error'
return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg)


class SeadocUploadImage(APIView):
Expand Down Expand Up @@ -1165,6 +1168,14 @@ def post(self, request):
if SeadocRevision.objects.get_by_doc_uuid(origin_file_uuid):
error_msg = 'seadoc %s is already a revision.' % filename
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)

# save origin file
try:
sdoc_server_api = SdocServerAPI(origin_file_uuid, filename, username)
res = sdoc_server_api.save_doc()
except Exception as e:
warning_msg = 'Save origin sdoc %s failed.' % origin_file_uuid
logger.warning(warning_msg)

origin_file_id = seafile_api.get_file_id_by_path(repo_id, path)
revision_file_uuid = str(uuid.uuid4())
Expand Down Expand Up @@ -1338,7 +1349,7 @@ def delete(self, request, file_uuid):
repo_id, '/images/sdoc/', json.dumps([str(revision_file_uuid.uuid)]), username)

seafile_api.del_file(
repo_id, revision_parent_path, revision_filename, username)
repo_id, revision_parent_path, json.dumps([revision_filename]), username)

SeadocRevision.objects.delete_by_doc_uuid(file_uuid)

Expand Down
7 changes: 6 additions & 1 deletion seahub/seadoc/sdoc_server_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,16 @@ def internal_refresh_docs(self, doc_uuids):
data = {"doc_uuids" : doc_uuids}
response = requests.post(url, json=data, headers=self.headers)
return parse_response(response)

def remove_doc(self):
url = self.sdoc_server_url + '/api/v1/docs/' + self.doc_uuid + '/?from=seahub'
response = requests.delete(url, headers=self.headers)
return parse_response(response)

def get_doc(self):
url = self.sdoc_server_url + '/api/v1/docs/' + self.doc_uuid + '/?from=seahub'
response = requests.get(url, headers=self.headers)
return parse_response(response)

def save_doc(self):
url = self.sdoc_server_url + '/api/v1/docs/' + self.doc_uuid + '/save/?from=seahub'
Expand Down

0 comments on commit bd34adb

Please sign in to comment.