1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-05-14 10:50:00 +00:00

Feature/adjust inserting sdoc file link ()

* insert sdoc file link directly

* adjust search files api
This commit is contained in:
Stephen 2024-12-21 13:49:25 +08:00 committed by GitHub
parent bdc09c0e4e
commit 8ef2c35331
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 30 additions and 4 deletions
frontend/src/pages/sdoc/sdoc-editor
seahub

View File

@ -121,6 +121,17 @@ class ExternalOperations extends React.Component {
};
onCreateSdocFile = (params) => {
if (params?.noShowDialog) {
this.setState({
insertSdocFileLink: params.insertSdocFileLink,
editor: params.editor,
}, () => {
const filePath = `${this.props.dirPath}/${params.newFileName}.sdoc`;
this.onAddFile(filePath);
});
return;
}
if (params?.editor && params?.insertSdocFileLink) {
this.setState({ editor: params.editor, insertSdocFileLink: params.insertSdocFileLink });
}

View File

@ -49,7 +49,8 @@ from seahub.utils import get_file_type_and_ext, normalize_file_path, \
normalize_dir_path, PREVIEW_FILEEXT, \
gen_inner_file_get_url, gen_inner_file_upload_url, gen_file_get_url, \
get_service_url, is_valid_username, is_pro_version, \
get_file_history_by_day, get_file_daily_history_detail, HAS_FILE_SEARCH, HAS_FILE_SEASEARCH, gen_file_upload_url
get_file_history_by_day, get_file_daily_history_detail, HAS_FILE_SEARCH, HAS_FILE_SEASEARCH, gen_file_upload_url, \
get_non_sdoc_file_exts
from seahub.tags.models import FileUUIDMap
from seahub.utils.error_msg import file_type_error_msg
from seahub.utils.repo import parse_repo_perm, get_related_users_by_repo
@ -2918,7 +2919,15 @@ class SeadocSearchFilenameView(APIView):
except ValueError:
current_page = 1
per_page = 10
search_type = request.GET.get('search_type', None)
suffixes = []
if search_type == 'sdoc':
suffixes = ['sdoc',]
if search_type == 'file':
suffixes = get_non_sdoc_file_exts()
if not suffixes:
error_msg = 'search_type is not valid.'
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
# resource check
uuid_map = FileUUIDMap.objects.get_fileuuidmap_by_uuid(file_uuid)
if not uuid_map:
@ -2928,7 +2937,6 @@ class SeadocSearchFilenameView(APIView):
repo = seafile_api.get_repo(repo_id)
search_filename_only = True
suffixes = ['sdoc',]
if HAS_FILE_SEARCH:
org_id = get_org_id_by_repo_id(repo_id)
map_id = repo.origin_repo_id if repo.origin_repo_id else repo_id
@ -2977,7 +2985,6 @@ class SeadocSearchFilenameView(APIView):
repos = [(repo.id, repo.origin_repo_id, repo.origin_path, repo.name)]
searched_repos, repos_map = format_repos(repos)
results, total = ai_search_files(query, searched_repos, per_page, suffixes)
for f in results:
repo_id = f['repo_id']
repo = repos_map.get(repo_id, None)

View File

@ -145,6 +145,14 @@ PREVIEW_FILEEXT = {
SEADOC: ('sdoc',),
}
def get_non_sdoc_file_exts():
exts = []
for filetype in PREVIEW_FILEEXT.keys():
if filetype in [IMAGE, SEADOC]:
continue
exts.extend(list(PREVIEW_FILEEXT.get(filetype, [])))
return exts
def gen_fileext_type_map():
"""
Generate previewed file extension and file type relation map.