mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-20 19:08:21 +00:00
docx to sdoc
This commit is contained in:
@@ -608,7 +608,7 @@ export const Utils = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ((permission == 'rw' || permission == 'cloud-edit') && enableSeadoc) {
|
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);
|
list.push(CONVERT_TO_SDOC);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -28,7 +28,9 @@ from seahub.utils.file_op import check_file_lock, if_locked_by_online_office
|
|||||||
from seahub.views.file import can_preview_file, can_edit_file
|
from seahub.views.file import can_preview_file, can_edit_file
|
||||||
from seahub.constants import PERMISSION_READ_WRITE
|
from seahub.constants import PERMISSION_READ_WRITE
|
||||||
from seahub.utils.repo import parse_repo_perm, is_repo_admin, is_repo_owner
|
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.tags.models import FileUUIDMap
|
||||||
from seahub.seadoc.models import SeadocHistoryName, SeadocDraft, SeadocCommentReply
|
from seahub.seadoc.models import SeadocHistoryName, SeadocDraft, SeadocCommentReply
|
||||||
from seahub.base.models import FileComment
|
from seahub.base.models import FileComment
|
||||||
@@ -553,12 +555,13 @@ class FileView(APIView):
|
|||||||
dst_type = request.data.get('dst_type')
|
dst_type = request.data.get('dst_type')
|
||||||
|
|
||||||
extension = Path(path).suffix
|
extension = Path(path).suffix
|
||||||
if extension not in ['.md', '.sdoc']:
|
if extension not in ['.md', '.sdoc', '.docx']:
|
||||||
error_msg = 'path invalid.'
|
error_msg = 'path invalid.'
|
||||||
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
|
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
|
||||||
|
|
||||||
if (extension == '.md' and dst_type not in MARKDOWN_SUPPORT_CONVERT_TYPES) or \
|
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.'
|
error_msg = 'dst_type invalid.'
|
||||||
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
|
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
|
||||||
|
|
||||||
@@ -596,6 +599,9 @@ class FileView(APIView):
|
|||||||
if extension == '.md':
|
if extension == '.md':
|
||||||
src_type = 'markdown'
|
src_type = 'markdown'
|
||||||
new_filename = filename[:-2] + 'sdoc'
|
new_filename = filename[:-2] + 'sdoc'
|
||||||
|
if extension == '.docx':
|
||||||
|
src_type = 'docx'
|
||||||
|
new_filename = filename[:-4] + 'sdoc'
|
||||||
elif extension == '.sdoc':
|
elif extension == '.sdoc':
|
||||||
src_type = 'sdoc'
|
src_type = 'sdoc'
|
||||||
if dst_type == 'markdown':
|
if dst_type == 'markdown':
|
||||||
@@ -606,14 +612,24 @@ class FileView(APIView):
|
|||||||
new_filename = check_filename_or_rename(repo_id, parent_dir, new_filename)
|
new_filename = check_filename_or_rename(repo_id, parent_dir, new_filename)
|
||||||
new_file_path = posixpath.join(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})
|
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)
|
use_onetime=True)
|
||||||
|
if extension == '.sdoc':
|
||||||
doc_uuid = get_seadoc_file_uuid(repo, path)
|
doc_uuid = get_seadoc_file_uuid(repo, path)
|
||||||
|
else:
|
||||||
|
doc_uuid = get_seadoc_file_uuid(repo, new_file_path)
|
||||||
|
|
||||||
if dst_type != 'docx':
|
if dst_type != 'docx':
|
||||||
|
# md, docx file convert to sdoc
|
||||||
try:
|
try:
|
||||||
resp = convert_file(path, username, doc_uuid,
|
resp = convert_file(path, username, doc_uuid,
|
||||||
download_token, upload_token,
|
download_token, upload_token,
|
||||||
@@ -629,7 +645,7 @@ class FileView(APIView):
|
|||||||
return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR,
|
return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||||
'Internal Server Error')
|
'Internal Server Error')
|
||||||
else:
|
else:
|
||||||
|
# sdoc file convert to docx
|
||||||
try:
|
try:
|
||||||
resp = sdoc_convert_to_docx(path, username, doc_uuid,
|
resp = sdoc_convert_to_docx(path, username, doc_uuid,
|
||||||
download_token, upload_token,
|
download_token, upload_token,
|
||||||
|
@@ -13,4 +13,5 @@ SEADOC = 'SDoc'
|
|||||||
|
|
||||||
|
|
||||||
MARKDOWN_SUPPORT_CONVERT_TYPES = ['sdoc']
|
MARKDOWN_SUPPORT_CONVERT_TYPES = ['sdoc']
|
||||||
|
DOCX_SUPPORT_CONVERT_TYPES = ['sdoc']
|
||||||
SDOC_SUPPORT_CONVERT_TYPES = ['markdown', 'docx']
|
SDOC_SUPPORT_CONVERT_TYPES = ['markdown', 'docx']
|
||||||
|
Reference in New Issue
Block a user