Enhance text note functionality: add API for creating and managing written notes, implement draft saving, and improve UI for note capture modes
This commit is contained in:
+36
-5
@@ -199,6 +199,36 @@ async def create_note(
|
||||
return {"id": note_id, "status": status}
|
||||
|
||||
|
||||
@app.post("/api/text-notes", status_code=201)
|
||||
def create_text_note(payload: dict[str, str]) -> dict[str, str]:
|
||||
text = payload.get("text", "").strip()
|
||||
if not text:
|
||||
raise HTTPException(status_code=400, detail="Note text is required")
|
||||
try:
|
||||
note_id = str(uuid.UUID(payload.get("id", "")))
|
||||
except ValueError as error:
|
||||
raise HTTPException(status_code=400, detail="Invalid note ID") from error
|
||||
try:
|
||||
parsed_date = datetime.fromisoformat(payload.get("created_at", "").replace("Z", "+00:00"))
|
||||
if parsed_date.tzinfo is None:
|
||||
parsed_date = parsed_date.replace(tzinfo=timezone.utc)
|
||||
created_at = parsed_date.astimezone(timezone.utc).isoformat()
|
||||
except ValueError:
|
||||
created_at = datetime.now(timezone.utc).isoformat()
|
||||
|
||||
with connect_db() as connection:
|
||||
existing = connection.execute("SELECT status FROM notes WHERE id = ?", (note_id,)).fetchone()
|
||||
if existing:
|
||||
return {"id": note_id, "status": existing["status"]}
|
||||
connection.execute(
|
||||
"""INSERT INTO notes (id, created_at, filename, audio_path, transcript, status)
|
||||
VALUES (?, ?, ?, '', ?, 'written')""",
|
||||
(note_id, created_at, "Written note", text),
|
||||
)
|
||||
connection.execute("INSERT INTO note_search (note_id, transcript) VALUES (?, ?)", (note_id, text))
|
||||
return {"id": note_id, "status": "written"}
|
||||
|
||||
|
||||
@app.get("/api/notes")
|
||||
def list_notes(q: str = "", status: str = "") -> list[dict[str, str]]:
|
||||
with connect_db() as connection:
|
||||
@@ -255,13 +285,14 @@ def delete_note(note_id: str) -> dict[str, str]:
|
||||
def save_transcript(note_id: str, payload: dict[str, str]) -> dict[str, str]:
|
||||
transcript = payload.get("transcript", "").strip()
|
||||
with connect_db() as connection:
|
||||
exists = connection.execute("SELECT 1 FROM notes WHERE id = ?", (note_id,)).fetchone()
|
||||
if not exists:
|
||||
note = connection.execute("SELECT status FROM notes WHERE id = ?", (note_id,)).fetchone()
|
||||
if not note:
|
||||
raise HTTPException(status_code=404, detail="Note not found")
|
||||
update_transcript(note_id, transcript, "transcribed" if transcript else "awaiting_transcription")
|
||||
if transcript:
|
||||
status = "written" if note["status"] == "written" else "transcribed" if transcript else "awaiting_transcription"
|
||||
update_transcript(note_id, transcript, status)
|
||||
if transcript and note["status"] != "written":
|
||||
remove_transcribed_audio(note_id)
|
||||
return {"id": note_id, "status": "transcribed" if transcript else "awaiting_transcription"}
|
||||
return {"id": note_id, "status": status}
|
||||
|
||||
|
||||
app.mount("/", StaticFiles(directory=FRONTEND_DIR, html=True), name="frontend")
|
||||
Reference in New Issue
Block a user