Add re-analyse button and POST /documents/{id}/reprocess endpoint
Resets status to pending, clears error_message, and re-enqueues the background AI extraction task. Button is disabled while the document is already pending or processing; returns 409 in that case from the API. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -305,6 +305,24 @@ async def update_document_title(
|
||||
return _doc_with_categories(doc)
|
||||
|
||||
|
||||
@router.post("/{doc_id}/reprocess", response_model=DocumentOut)
|
||||
async def reprocess_document(
|
||||
doc_id: str,
|
||||
background_tasks: BackgroundTasks,
|
||||
user_id: str = Depends(get_user_id),
|
||||
db: AsyncSession = Depends(get_db),
|
||||
) -> DocumentOut:
|
||||
doc = await _get_user_doc(doc_id, user_id, db)
|
||||
if doc.status in ("pending", "processing"):
|
||||
raise HTTPException(status_code=409, detail="Document is already being processed")
|
||||
doc.status = "pending"
|
||||
doc.error_message = None
|
||||
await db.commit()
|
||||
background_tasks.add_task(process_document, doc_id)
|
||||
doc = await _get_user_doc(doc_id, user_id, db)
|
||||
return _doc_with_categories(doc)
|
||||
|
||||
|
||||
@router.delete("/{doc_id}", status_code=204)
|
||||
async def delete_document(
|
||||
doc_id: str,
|
||||
|
||||
Reference in New Issue
Block a user