Spaces:
Running
Running
Commit
·
dd8f00c
1
Parent(s):
9d864ff
update
Browse files
app/api/notes/internal_notes.py
CHANGED
|
@@ -1,8 +1,9 @@
|
|
| 1 |
-
from fastapi import APIRouter, HTTPException
|
| 2 |
from pydantic import BaseModel, Field
|
| 3 |
from typing import Optional, List, Dict, Any
|
| 4 |
|
| 5 |
from app.services.note_store import get_note, update_note
|
|
|
|
| 6 |
from app.utils.time import now_ts
|
| 7 |
|
| 8 |
router = APIRouter(
|
|
@@ -22,7 +23,7 @@ class InternalUpdateNoteRequest(BaseModel):
|
|
| 22 |
generate: Optional[List[str]] = None
|
| 23 |
|
| 24 |
@router.patch("/{note_id}")
|
| 25 |
-
def update_note_internal(note_id: str, req: InternalUpdateNoteRequest):
|
| 26 |
note = get_note(note_id)
|
| 27 |
if not note:
|
| 28 |
raise HTTPException(status_code=404, detail="Note not found")
|
|
@@ -34,6 +35,31 @@ def update_note_internal(note_id: str, req: InternalUpdateNoteRequest):
|
|
| 34 |
|
| 35 |
update_note(note_id, updates)
|
| 36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
return {
|
| 38 |
"note_id": note_id,
|
| 39 |
"updated": True,
|
|
|
|
| 1 |
+
from fastapi import APIRouter, HTTPException, BackgroundTasks
|
| 2 |
from pydantic import BaseModel, Field
|
| 3 |
from typing import Optional, List, Dict, Any
|
| 4 |
|
| 5 |
from app.services.note_store import get_note, update_note
|
| 6 |
+
from app.jobs.async_enrichment_job import enrich_note
|
| 7 |
from app.utils.time import now_ts
|
| 8 |
|
| 9 |
router = APIRouter(
|
|
|
|
| 23 |
generate: Optional[List[str]] = None
|
| 24 |
|
| 25 |
@router.patch("/{note_id}")
|
| 26 |
+
def update_note_internal(note_id: str, req: InternalUpdateNoteRequest, bg: BackgroundTasks):
|
| 27 |
note = get_note(note_id)
|
| 28 |
if not note:
|
| 29 |
raise HTTPException(status_code=404, detail="Note not found")
|
|
|
|
| 35 |
|
| 36 |
update_note(note_id, updates)
|
| 37 |
|
| 38 |
+
# Decide whether to trigger enrichment:
|
| 39 |
+
# - If client supplied `generate` in payload → run those tasks
|
| 40 |
+
# - Or if status switched to `transcribed` and the existing note has a `generate` list → run that
|
| 41 |
+
try:
|
| 42 |
+
allowed = {"normalize", "keywords", "summary", "mindmap"}
|
| 43 |
+
tasks = None
|
| 44 |
+
|
| 45 |
+
if req.generate is not None:
|
| 46 |
+
if not set(req.generate).issubset(allowed):
|
| 47 |
+
raise HTTPException(400, "Invalid generate task")
|
| 48 |
+
tasks = req.generate
|
| 49 |
+
|
| 50 |
+
elif updates.get("status") == "transcribed":
|
| 51 |
+
existing_generate = note.get("generate")
|
| 52 |
+
if existing_generate and set(existing_generate).issubset(allowed):
|
| 53 |
+
tasks = existing_generate
|
| 54 |
+
|
| 55 |
+
if tasks:
|
| 56 |
+
bg.add_task(enrich_note, note_id, tasks)
|
| 57 |
+
except HTTPException:
|
| 58 |
+
raise
|
| 59 |
+
except Exception:
|
| 60 |
+
# Don't fail the update if scheduling enrichment fails; just log in real app
|
| 61 |
+
pass
|
| 62 |
+
|
| 63 |
return {
|
| 64 |
"note_id": note_id,
|
| 65 |
"updated": True,
|