修复 ocr 错误
This commit is contained in:
@@ -17,7 +17,8 @@ import {
|
||||
deleteQrCode,
|
||||
fetchQrCodeStats,
|
||||
fetchQrCodes,
|
||||
recognizeQrCodeGroupName,
|
||||
getOCRJobResult,
|
||||
submitOCRJob,
|
||||
updateQrCode,
|
||||
type ChatQrCode,
|
||||
type CreateQrCodePayload,
|
||||
@@ -230,8 +231,19 @@ function parseGroupNameFromOcrText(text: string) {
|
||||
}
|
||||
|
||||
async function recognizeGroupName(file: File) {
|
||||
const result = await recognizeQrCodeGroupName(file)
|
||||
return result.group_name || parseGroupNameFromOcrText(result.raw_text || '')
|
||||
const { job_id } = await submitOCRJob(file)
|
||||
const delays = [1000, 2000, 3000, 3000, 3000]
|
||||
for (let i = 0; i < delays.length; i++) {
|
||||
await new Promise(resolve => setTimeout(resolve, delays[i]))
|
||||
const record = await getOCRJobResult(job_id)
|
||||
if (record.status === 'done' && record.result) {
|
||||
return record.result.group_name || parseGroupNameFromOcrText(record.result.raw_text || '')
|
||||
}
|
||||
if (record.status === 'failed') {
|
||||
throw new Error(record.error || 'OCR 识别失败')
|
||||
}
|
||||
}
|
||||
throw new Error('OCR 识别超时')
|
||||
}
|
||||
|
||||
// 上传:逐个上传图片拿 URL
|
||||
|
||||
Reference in New Issue
Block a user