1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-22 11:57:34 +00:00

fix enableFaceRecognition and menu Detect faces (#7979)

* fix frontend enableFaceRecognition and menu Detect faces

* Update apis.py

---------

Co-authored-by: 孙永强 <11704063+s-yongqiang@user.noreply.gitee.com>
This commit is contained in:
Michael An
2025-06-26 16:34:11 +08:00
committed by GitHub
parent da432ccd5d
commit c6805b9f64
5 changed files with 12 additions and 10 deletions

View File

@@ -52,7 +52,7 @@
flex-direction: column;
}
.lib-settings-dialog .oepn-metadata-tip {
.lib-settings-dialog .open-metadata-tip {
background-color: #ffeacd;
margin: -1rem -1rem 1rem;
padding: 0.5rem 1rem;

View File

@@ -62,7 +62,7 @@ const MetadataFaceRecognitionDialog = ({ value: oldValue, repoID, toggleDialog:
{!showTurnOffConfirmDialog && (
<>
<ModalBody className="metadata-face-recognition-dialog">
{!enableMetadata && <p className="oepn-metadata-tip">{gettext('Please turn on extended properties setting first')}</p>}
{!enableMetadata && <p className="open-metadata-tip">{gettext('Please turn on extended properties setting first')}</p>}
<Switch
checked={value}
disabled={submitting || !enableMetadata}

View File

@@ -89,7 +89,7 @@ const MetadataTagsStatusDialog = ({ value: oldValue, lang: oldLang, repoID, togg
{!showTurnOffConfirmDialog && (
<>
<ModalBody className="metadata-face-recognition-dialog">
{!enableMetadata && <p className="oepn-metadata-tip">{gettext('Please turn on extended properties setting first')}</p>}
{!enableMetadata && <p className="open-metadata-tip">{gettext('Please turn on extended properties setting first')}</p>}
<Switch
checked={value}
disabled={submitting || !enableMetadata}

View File

@@ -4,6 +4,7 @@ import { gettext, enableSeafileAI } from '@/utils/constants';
import { Utils } from '@/utils/utils';
import DeleteFolderDialog from '@/components/dialog/delete-folder-dialog';
import { useMetadataView } from '../../hooks/metadata-view';
import { useMetadataStatus } from '../../../hooks/metadata-status';
import RowUtils from './utils/row-utils';
import { checkIsDir } from '../../utils/row';
import { getColumnByKey, isNameColumn } from '../../utils/column';
@@ -40,6 +41,7 @@ const ContextMenu = ({
const [deletedFolderPath, setDeletedFolderPath] = useState('');
const { metadata } = useMetadataView();
const { enableFaceRecognition } = useMetadataStatus();
const repoID = window.sfMetadataStore.repoId;
@@ -116,7 +118,7 @@ const ContextMenu = ({
const fileName = getFileNameFromRecord(record);
return Utils.imageCheck(fileName);
});
if (imageRecords.length > 0) {
if (enableFaceRecognition && imageRecords.length > 0) {
list.push({ value: OPERATION.DETECT_FACES, label: gettext('Detect faces'), records: imageRecords });
}
}
@@ -152,7 +154,7 @@ const ContextMenu = ({
const fileName = getFileNameFromRecord(record);
return Utils.imageCheck(fileName);
});
if (imageRecords.length > 0) {
if (enableFaceRecognition && imageRecords.length > 0) {
list.push({ value: OPERATION.DETECT_FACES, label: gettext('Detect faces'), records: imageRecords });
}
}
@@ -202,7 +204,7 @@ const ContextMenu = ({
if (isImage || isVideo) {
aiOptions.push({ value: OPERATION.FILE_DETAIL, label: gettext('Extract file detail'), record: record });
}
if (isImage) {
if (enableFaceRecognition && isImage) {
aiOptions.push({ value: OPERATION.DETECT_FACES, label: gettext('Detect faces'), records: [record] });
}
@@ -229,7 +231,7 @@ const ContextMenu = ({
}
return list;
}, [isGroupView, selectedPosition, recordMetrics, selectedRange, metadata, recordGetterByIndex, checkIsDescribableFile, getAbleDeleteRecords]);
}, [isGroupView, selectedPosition, recordMetrics, selectedRange, metadata, recordGetterByIndex, checkIsDescribableFile, getAbleDeleteRecords, enableFaceRecognition]);
const handleOptionClick = useCallback((option, event) => {
switch (option.value) {

View File

@@ -1778,9 +1778,9 @@ class MetadataRecognizeFaces(APIView):
error_msg = 'obj_ids is invalid.'
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
record = RepoMetadata.objects.filter(repo_id=repo_id).first()
if not record or not record.enabled:
error_msg = f'The metadata module is disabled for repo {repo_id}.'
metadata = RepoMetadata.objects.filter(repo_id=repo_id).first()
if not metadata or not metadata.enabled or not metadata.face_recognition_enabled:
error_msg = f'The face recognition is disabled for repo {repo_id}.'
return api_error(status.HTTP_404_NOT_FOUND, error_msg)
repo = seafile_api.get_repo(repo_id)