feat(personal): show scanned PDF OCR progress
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
import type { PersonalOcrProgress } from '@/types/api';
|
||||
|
||||
export const ocrProgressPercent = (ocr?: PersonalOcrProgress) => {
|
||||
if (!ocr?.required || ocr.totalPages <= 0) return 0;
|
||||
return Math.min(100, Math.max(0, Math.round((ocr.processedPages / ocr.totalPages) * 100)));
|
||||
};
|
||||
|
||||
export const ocrProgressText = (ocr?: PersonalOcrProgress) => {
|
||||
if (!ocr?.required) return '';
|
||||
if (ocr.processedPages < ocr.totalPages && ['PENDING', 'RUNNING', 'RETRY'].includes(ocr.status)) {
|
||||
return `正在识别扫描 PDF:${ocr.processedPages}/${ocr.totalPages} 页`;
|
||||
}
|
||||
if (ocr.failedPages > 0 && ocr.successPages > 0) return `已收录,${ocr.failedPages} 页识别失败`;
|
||||
if (ocr.failedPages > 0) return `${ocr.failedPages} 页识别失败`;
|
||||
if (ocr.totalPages > 0) return `扫描 PDF 已识别:${ocr.successPages}/${ocr.totalPages} 页`;
|
||||
return '正在准备扫描 PDF 识别';
|
||||
};
|
||||
|
||||
export const isOcrActive = (ocr?: PersonalOcrProgress) =>
|
||||
Boolean(ocr?.required && ['PENDING', 'RUNNING', 'RETRY'].includes(ocr.status));
|
||||
@@ -134,6 +134,11 @@ export const retryPersonalItem = (id: string) => apiRequest<PersonalItem>({
|
||||
method: 'POST'
|
||||
});
|
||||
|
||||
export const retryPersonalOcrPages = (id: string) => apiRequest<PersonalItem>({
|
||||
url: personalItemApiPath(id, '/ocr/retry-failed'),
|
||||
method: 'POST'
|
||||
});
|
||||
|
||||
export const deletePersonalItem = (id: string) => apiRequest<{ cleanupJobId: string }>({
|
||||
url: personalItemApiPath(id),
|
||||
method: 'DELETE',
|
||||
|
||||
Reference in New Issue
Block a user