Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docx to sdoc #5912

Merged
merged 1 commit into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion frontend/src/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ export const Utils = {
}

if ((permission == 'rw' || permission == 'cloud-edit') && enableSeadoc) {
if (dirent.name.endsWith('.md')) {
if (dirent.name.endsWith('.md') || dirent.name.endsWith('.docx')) {
list.push(CONVERT_TO_SDOC);
}

Expand Down
30 changes: 23 additions & 7 deletions seahub/api2/endpoints/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
from seahub.views.file import can_preview_file, can_edit_file
from seahub.constants import PERMISSION_READ_WRITE
from seahub.utils.repo import parse_repo_perm, is_repo_admin, is_repo_owner
from seahub.utils.file_types import MARKDOWN, TEXT, SEADOC, MARKDOWN_SUPPORT_CONVERT_TYPES, SDOC_SUPPORT_CONVERT_TYPES
from seahub.utils.file_types import MARKDOWN, TEXT, SEADOC, \
MARKDOWN_SUPPORT_CONVERT_TYPES, SDOC_SUPPORT_CONVERT_TYPES, \
DOCX_SUPPORT_CONVERT_TYPES
from seahub.tags.models import FileUUIDMap
from seahub.seadoc.models import SeadocHistoryName, SeadocDraft, SeadocCommentReply
from seahub.base.models import FileComment
Expand Down Expand Up @@ -553,12 +555,13 @@ def post(self, request, repo_id, format=None):
dst_type = request.data.get('dst_type')

extension = Path(path).suffix
if extension not in ['.md', '.sdoc']:
if extension not in ['.md', '.sdoc', '.docx']:
error_msg = 'path invalid.'
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)

if (extension == '.md' and dst_type not in MARKDOWN_SUPPORT_CONVERT_TYPES) or \
(extension == '.sdoc' and dst_type not in SDOC_SUPPORT_CONVERT_TYPES):
(extension == '.sdoc' and dst_type not in SDOC_SUPPORT_CONVERT_TYPES) or \
(extension == '.docx' and dst_type not in DOCX_SUPPORT_CONVERT_TYPES):
error_msg = 'dst_type invalid.'
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)

Expand Down Expand Up @@ -596,6 +599,9 @@ def post(self, request, repo_id, format=None):
if extension == '.md':
src_type = 'markdown'
new_filename = filename[:-2] + 'sdoc'
if extension == '.docx':
src_type = 'docx'
new_filename = filename[:-4] + 'sdoc'
elif extension == '.sdoc':
src_type = 'sdoc'
if dst_type == 'markdown':
Expand All @@ -606,14 +612,24 @@ def post(self, request, repo_id, format=None):
new_filename = check_filename_or_rename(repo_id, parent_dir, new_filename)
new_file_path = posixpath.join(parent_dir, new_filename)

download_token = seafile_api.get_fileserver_access_token(repo_id, file_id, 'download', username)
download_token = seafile_api.get_fileserver_access_token(repo_id,
file_id,
'download',
username)

obj_id = json.dumps({'parent_dir': parent_dir})
upload_token = seafile_api.get_fileserver_access_token(repo_id, obj_id, 'upload-link', username,
upload_token = seafile_api.get_fileserver_access_token(repo_id,
obj_id,
'upload-link',
username,
use_onetime=True)
doc_uuid = get_seadoc_file_uuid(repo, path)
if extension == '.sdoc':
doc_uuid = get_seadoc_file_uuid(repo, path)
else:
doc_uuid = get_seadoc_file_uuid(repo, new_file_path)

if dst_type != 'docx':
# md, docx file convert to sdoc
try:
resp = convert_file(path, username, doc_uuid,
download_token, upload_token,
Expand All @@ -629,7 +645,7 @@ def post(self, request, repo_id, format=None):
return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR,
'Internal Server Error')
else:

# sdoc file convert to docx
try:
resp = sdoc_convert_to_docx(path, username, doc_uuid,
download_token, upload_token,
Expand Down
1 change: 1 addition & 0 deletions seahub/utils/file_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@


MARKDOWN_SUPPORT_CONVERT_TYPES = ['sdoc']
DOCX_SUPPORT_CONVERT_TYPES = ['sdoc']
SDOC_SUPPORT_CONVERT_TYPES = ['markdown', 'docx']
Loading