mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-17 15:53:28 +00:00
@@ -31,12 +31,12 @@ export const MetadataAIOperationsProvider = ({
|
|||||||
|
|
||||||
const onOCR = useCallback(({ parentDir, fileName }, { success_callback, fail_callback } = {}) => {
|
const onOCR = useCallback(({ parentDir, fileName }, { success_callback, fail_callback } = {}) => {
|
||||||
const filePath = Utils.joinPath(parentDir, fileName);
|
const filePath = Utils.joinPath(parentDir, fileName);
|
||||||
const inProgressToaster = toaster.notifyInProgress(gettext('Using AI to extract text, please wait...'), { duration: null });
|
const inProgressToaster = toaster.notifyInProgress(gettext('Extracting text by AI...'), { duration: null });
|
||||||
metadataAPI.ocr(repoID, filePath).then(res => {
|
metadataAPI.ocr(repoID, filePath).then(res => {
|
||||||
const ocrResult = res.data.ocr_result;
|
const ocrResult = res.data.ocr_result;
|
||||||
const validResult = Array.isArray(ocrResult) && ocrResult.length > 0 ? JSON.stringify(ocrResult) : null;
|
const validResult = Array.isArray(ocrResult) && ocrResult.length > 0 ? JSON.stringify(ocrResult) : null;
|
||||||
inProgressToaster.close();
|
inProgressToaster.close();
|
||||||
toaster.success(gettext('AI to extract text, completed.'));
|
toaster.success(gettext('Text extracted'));
|
||||||
success_callback && success_callback({ parentDir, fileName, ocrResult: validResult });
|
success_callback && success_callback({ parentDir, fileName, ocrResult: validResult });
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
inProgressToaster.close();
|
inProgressToaster.close();
|
||||||
@@ -54,27 +54,26 @@ export const MetadataAIOperationsProvider = ({
|
|||||||
APIName = isImage ? 'imageCaption' : 'generateDescription';
|
APIName = isImage ? 'imageCaption' : 'generateDescription';
|
||||||
}
|
}
|
||||||
if (!APIName) return;
|
if (!APIName) return;
|
||||||
const descriptionTip = isImage ? gettext('image description') : gettext('description');
|
const inProgressToaster = toaster.notifyInProgress(gettext('Generating description by AI...'), { duration: null });
|
||||||
const inProgressToaster = toaster.notifyInProgress(gettext('Using AI to generate {description}, please wait...').replace('{description}', descriptionTip), { duration: null });
|
|
||||||
metadataAPI[APIName](repoID, filePath, lang).then(res => {
|
metadataAPI[APIName](repoID, filePath, lang).then(res => {
|
||||||
const description = res?.data?.summary || res.data.desc || '';
|
const description = res?.data?.summary || res.data.desc || '';
|
||||||
inProgressToaster.close();
|
inProgressToaster.close();
|
||||||
toaster.success(gettext('AI to generate description, completed.').replace('{description}', descriptionTip));
|
toaster.success(gettext('Description generated'));
|
||||||
success_callback && success_callback({ parentDir, fileName, description });
|
success_callback && success_callback({ parentDir, fileName, description });
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
inProgressToaster.close();
|
inProgressToaster.close();
|
||||||
const errorMessage = gettext('Failed to generate description').replace('{description}', descriptionTip);
|
const errorMessage = gettext('Failed to generate description');
|
||||||
toaster.danger(errorMessage);
|
toaster.danger(errorMessage);
|
||||||
fail_callback && fail_callback();
|
fail_callback && fail_callback();
|
||||||
});
|
});
|
||||||
}, [repoID]);
|
}, [repoID]);
|
||||||
|
|
||||||
const extractFilesDetails = useCallback((objIds, { success_callback, fail_callback } = {}) => {
|
const extractFilesDetails = useCallback((objIds, { success_callback, fail_callback } = {}) => {
|
||||||
const inProgressToaster = toaster.notifyInProgress(gettext('Using AI to extract file details, please wait...'), { duration: null });
|
const inProgressToaster = toaster.notifyInProgress(gettext('Extracting file details by AI...'), { duration: null });
|
||||||
metadataAPI.extractFileDetails(repoID, objIds).then(res => {
|
metadataAPI.extractFileDetails(repoID, objIds).then(res => {
|
||||||
const details = res?.data?.details || [];
|
const details = res?.data?.details || [];
|
||||||
inProgressToaster.close();
|
inProgressToaster.close();
|
||||||
toaster.success(gettext('AI to extract file details, completed.'));
|
toaster.success(gettext('File details extracted'));
|
||||||
success_callback && success_callback({ details });
|
success_callback && success_callback({ details });
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
inProgressToaster.close();
|
inProgressToaster.close();
|
||||||
|
@@ -44,7 +44,7 @@ const AI = () => {
|
|||||||
if (descriptionColumn && isDescribableDoc) {
|
if (descriptionColumn && isDescribableDoc) {
|
||||||
list.push({
|
list.push({
|
||||||
value: OPERATION.GENERATE_DESCRIPTION,
|
value: OPERATION.GENERATE_DESCRIPTION,
|
||||||
label: isImage ? gettext('Generate image description') : gettext('Generate description'),
|
label: gettext('Generate description'),
|
||||||
record
|
record
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@@ -178,7 +178,7 @@ const ContextMenu = ({
|
|||||||
if (descriptionColumn && isDescribableFile) {
|
if (descriptionColumn && isDescribableFile) {
|
||||||
list.push({
|
list.push({
|
||||||
value: OPERATION.GENERATE_DESCRIPTION,
|
value: OPERATION.GENERATE_DESCRIPTION,
|
||||||
label: Utils.imageCheck(fileName) ? gettext('Generate image description') : gettext('Generate description'),
|
label: gettext('Generate description'),
|
||||||
record
|
record
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user