diff --git a/frontend/src/components/dialog/lib-settings.js b/frontend/src/components/dialog/lib-settings.js index 9c651fc53b..8d1784b08a 100644 --- a/frontend/src/components/dialog/lib-settings.js +++ b/frontend/src/components/dialog/lib-settings.js @@ -44,7 +44,7 @@ const LibSettingsDialog = ({ repoID, currentRepoInfo, toggleDialog, tab }) => { const { encrypted, is_admin } = currentRepoInfo; const { enableMetadataManagement } = window.app.pageOptions; const { enableFaceRecognition, updateEnableFaceRecognition } = useMetadata(); - const { enableMetadata, updateEnableMetadata, enableTags, updateEnableTags } = useMetadataStatus(); + const { enableMetadata, updateEnableMetadata, enableTags, tagsLang, updateEnableTags } = useMetadataStatus(); const enableHistorySetting = is_admin; // repo owner, admin of the department which the repo belongs to, and ... const enableAutoDelSetting = is_admin && enableRepoAutoDel; const enableExtendedPropertiesSetting = !encrypted && is_admin && enableMetadataManagement; @@ -139,6 +139,7 @@ const LibSettingsDialog = ({ repoID, currentRepoInfo, toggleDialog, tab }) => { diff --git a/frontend/src/hooks/metadata-status.js b/frontend/src/hooks/metadata-status.js index a43f5e1d1f..b60e63cab3 100644 --- a/frontend/src/hooks/metadata-status.js +++ b/frontend/src/hooks/metadata-status.js @@ -16,6 +16,7 @@ export const MetadataStatusProvider = ({ repoID, currentRepoInfo, hideMetadataVi const [isLoading, setLoading] = useState(true); const [enableMetadata, setEnableMetadata] = useState(false); const [enableTags, setEnableTags] = useState(false); + const [tagsLang, setTagsLang] = useState(null); const [isBeingBuilt, setIsBeingBuilt] = useState(false); const cancelMetadataURL = useCallback(() => { @@ -36,11 +37,12 @@ export const MetadataStatusProvider = ({ repoID, currentRepoInfo, hideMetadataVi return; } metadataAPI.getMetadataStatus(repoID).then(res => { - const { enabled: enableMetadata, tags_enabled: enableTags } = res.data; + const { enabled: enableMetadata, tags_enabled: enableTags, tags_lang: tagsLang } = res.data; if (!enableMetadata) { cancelMetadataURL(); } setEnableTags(enableTags); + setTagsLang(tagsLang); setEnableMetadata(enableMetadata); setLoading(false); }).catch(error => { @@ -62,14 +64,15 @@ export const MetadataStatusProvider = ({ repoID, currentRepoInfo, hideMetadataVi setEnableMetadata(newValue); }, [enableMetadata, cancelMetadataURL]); - const updateEnableTags = useCallback((newValue) => { - if (newValue === enableTags) return; + const updateEnableTags = useCallback((newValue, lang = 'en') => { + if (newValue === enableTags && lang === tagsLang) return; if (!newValue) { cancelMetadataURL(); hideMetadataView && hideMetadataView(); } setEnableTags(newValue); - }, [enableTags, cancelMetadataURL, hideMetadataView]); + setTagsLang(lang); + }, [enableTags, tagsLang, cancelMetadataURL, hideMetadataView]); return ( diff --git a/frontend/src/metadata/components/dialog/metadata-tags-status-dialog/index.css b/frontend/src/metadata/components/dialog/metadata-tags-status-dialog/index.css new file mode 100644 index 0000000000..f4a836e52c --- /dev/null +++ b/frontend/src/metadata/components/dialog/metadata-tags-status-dialog/index.css @@ -0,0 +1,10 @@ +.tags-language-container { + display: flex; + align-items: center; +} + +.tags-language-container .tags-language-selector { + width: 200px; + margin-top: 10px; + margin-left: 10px; +} diff --git a/frontend/src/metadata/components/dialog/metadata-tags-status-dialog/index.js b/frontend/src/metadata/components/dialog/metadata-tags-status-dialog/index.js index 2acd51cdc5..fedeb71c92 100644 --- a/frontend/src/metadata/components/dialog/metadata-tags-status-dialog/index.js +++ b/frontend/src/metadata/components/dialog/metadata-tags-status-dialog/index.js @@ -8,11 +8,24 @@ import tagsAPI from '../../../../tag/api'; import toaster from '../../../../components/toast'; import { Utils } from '../../../../utils/utils'; import TurnOffConfirmDialog from './turn-off-confirm'; +import { SeahubSelect } from '../../../../components/common/select'; -// import './index.css'; +import './index.css'; -const MetadataTagsStatusDialog = ({ value: oldValue, repoID, toggleDialog: toggle, submit }) => { +const langOptions = [ + { + value: 'zh-cn', + label: '简体中文' + }, + { + value: 'en', + label: 'English' + } +]; + +const MetadataTagsStatusDialog = ({ value: oldValue, lang: oldLang, repoID, toggleDialog: toggle, submit }) => { const [value, setValue] = useState(oldValue); + const [lang, setLang] = useState({ value: oldLang || 'en', label: langOptions.find(item => item.value === oldLang).label }); const [submitting, setSubmitting] = useState(false); const [showTurnOffConfirmDialog, setShowTurnOffConfirmDialog] = useState(false); @@ -26,15 +39,15 @@ const MetadataTagsStatusDialog = ({ value: oldValue, repoID, toggleDialog: toggl return; } setSubmitting(true); - tagsAPI.openTags(repoID).then(res => { - submit(true); + tagsAPI.openTags(repoID, lang.value).then(res => { + submit(true, lang.value); toggle(); }).catch(error => { const errorMsg = Utils.getErrorMsg(error); toaster.danger(errorMsg); setSubmitting(false); }); - }, [repoID, submit, toggle, value]); + }, [lang, repoID, submit, toggle, value]); const turnOffConfirmToggle = useCallback(() => { setShowTurnOffConfirmDialog(!showTurnOffConfirmDialog); @@ -58,6 +71,10 @@ const MetadataTagsStatusDialog = ({ value: oldValue, repoID, toggleDialog: toggl setValue(nextValue); }, [value]); + const onSelectChange = (option) => { + setLang(option); + }; + return ( <> {!showTurnOffConfirmDialog && ( @@ -75,10 +92,21 @@ const MetadataTagsStatusDialog = ({ value: oldValue, repoID, toggleDialog: toggl

{gettext('Enable tags to add tags to files and search files by tags.')}

+ {value && ( +
+ {gettext('Tags language:')} + +
+ )} - + )} diff --git a/frontend/src/tag/api.js b/frontend/src/tag/api.js index 3342338506..a34428664d 100644 --- a/frontend/src/tag/api.js +++ b/frontend/src/tag/api.js @@ -49,9 +49,12 @@ class TagsManagerAPI { return this.req.get(url); }; - openTags = (repoID) => { + openTags = (repoID, lang) => { const url = this.server + '/api/v2.1/repos/' + repoID + '/metadata/tags-status/'; - return this.req.put(url); + const params = { + lang: lang, + }; + return this.req.put(url, params); }; closeTags = (repoID) => { diff --git a/seahub/ai/apis.py b/seahub/ai/apis.py index b95f267139..2c9ba990fa 100644 --- a/seahub/ai/apis.py +++ b/seahub/ai/apis.py @@ -2,6 +2,7 @@ import logging import os.path from pysearpc import SearpcError +from seahub.repo_metadata.models import RepoMetadata from seaserv import seafile_api from rest_framework.authentication import SessionAuthentication @@ -161,6 +162,13 @@ class ImageTags(APIView): error_msg = 'Library %s not found.' % repo_id return api_error(status.HTTP_404_NOT_FOUND, error_msg) + try: + record = RepoMetadata.objects.filter(repo_id=repo_id).first() + except Exception as e: + logger.error(e) + error_msg = 'Internal Server Error' + return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg) + permission = check_folder_permission(request, repo_id, os.path.dirname(path)) if not permission: error_msg = 'Permission denied.' @@ -182,7 +190,8 @@ class ImageTags(APIView): params = { 'path': path, - 'download_token': token + 'download_token': token, + 'lang': record.tags_lang if record and record.tags_enabled else None } try: diff --git a/seahub/repo_metadata/apis.py b/seahub/repo_metadata/apis.py index 33c3b6740d..e8c15c3d42 100644 --- a/seahub/repo_metadata/apis.py +++ b/seahub/repo_metadata/apis.py @@ -62,6 +62,7 @@ class MetadataManage(APIView): return Response({ 'enabled': is_enabled, 'tags_enabled': is_tags_enabled, + 'tags_lang': record.tags_lang, }) def put(self, request, repo_id): @@ -1245,6 +1246,11 @@ class MetadataTagsStatusManage(APIView): throttle_classes = (UserRateThrottle,) def put(self, request, repo_id): + lang = request.data.get('lang') + if not lang: + error_msg = 'lang invalid.' + return api_error(status.HTTP_400_BAD_REQUEST, error_msg) + # resource check repo = seafile_api.get_repo(repo_id) if not repo: @@ -1260,15 +1266,19 @@ class MetadataTagsStatusManage(APIView): error_msg = f'The metadata module is not enabled for repo {repo_id}.' return api_error(status.HTTP_404_NOT_FOUND, error_msg) + old_tags_enabled = metadata.tags_enabled + try: - metadata.tags_enabled = True - metadata.save() + metadata.tags_enabled = True + metadata.tags_lang = lang + metadata.save() except Exception as e: logger.exception(e) return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, 'Internal Server Error') - metadata_server_api = MetadataServerAPI(repo_id, request.user.username) - init_tags(metadata_server_api) + if not old_tags_enabled: + metadata_server_api = MetadataServerAPI(repo_id, request.user.username) + init_tags(metadata_server_api) return Response({'success': True}) @@ -1300,6 +1310,7 @@ class MetadataTagsStatusManage(APIView): try: record.tags_enabled = False + record.tags_lang = None record.save() except Exception as e: logger.error(e) diff --git a/seahub/repo_metadata/models.py b/seahub/repo_metadata/models.py index 032dcb15b0..d2ed47b358 100644 --- a/seahub/repo_metadata/models.py +++ b/seahub/repo_metadata/models.py @@ -65,6 +65,7 @@ class RepoMetadata(models.Model): from_commit = models.CharField(max_length=40) to_commit = models.CharField(max_length=40) tags_enabled = models.BooleanField(db_index=True) + tags_lang = models.CharField(max_length=36) last_face_cluster_time = models.DateTimeField(db_index=True, blank=True, null=True) objects = RepoMetadataManager()