fix: mock

This commit is contained in:
2026-03-13 23:29:55 +08:00
parent b7e973e2b6
commit c72fbc9a14
7 changed files with 165 additions and 21 deletions

View File

@@ -65,7 +65,13 @@ async def upload_images(
# trigger OCR tasks in-process background (non-blocking for API response)
from app.workers.ocr_tasks import process_images_ocr_batch_async
pending_ids = [str(img.id) for img in results if img.ocr_status.value == "pending"]
pending_imgs = [img for img in results if img.ocr_status.value == "pending"]
for img in pending_imgs:
img.ocr_status = OcrStatus.processing
if pending_imgs:
await db.flush()
await db.commit()
pending_ids = [str(img.id) for img in pending_imgs]
if pending_ids:
asyncio.create_task(
process_images_ocr_batch_async(
@@ -171,20 +177,25 @@ async def start_case_ocr(
image_ids = payload.image_ids if payload else []
if image_ids:
images = await repo.list_by_ids_in_case(case_id, image_ids)
# Never submit images that are already processing: this prevents
# duplicate OCR tasks when users trigger OCR from multiple pages.
images = [img for img in images if img.ocr_status != OcrStatus.processing]
# For explicit re-run, mark selected images as processing immediately
# so frontend can reflect state transition without full page refresh.
for img in images:
img.ocr_status = OcrStatus.processing
await db.flush()
await db.commit()
if images:
await db.flush()
await db.commit()
else:
images = await repo.list_for_ocr(case_id, include_done=include_done)
# Mark queued images as processing immediately, including when OCR is
# triggered from workspace page, so UI can show progress right away.
for img in images:
img.ocr_status = OcrStatus.processing
await db.flush()
await db.commit()
if images:
await db.flush()
await db.commit()
from app.workers.ocr_tasks import process_images_ocr_batch_async