Enhance note management: add corrected transcript field, update UI for reading mode, and improve archive display

This commit is contained in:
2026-09-28 17:17:58 +02:00
parent bc60c16079
commit 422a3548fd
4 changed files with 74 additions and 31 deletions
+23 -10
View File
@@ -55,6 +55,7 @@ def initialize_db() -> None:
filename TEXT NOT NULL,
audio_path TEXT NOT NULL,
transcript TEXT NOT NULL DEFAULT '',
corrected_transcript TEXT NOT NULL DEFAULT '',
status TEXT NOT NULL
)"""
)
@@ -74,6 +75,8 @@ def initialize_db() -> None:
columns = {row[1] for row in connection.execute("PRAGMA table_info(notes)")}
if "original_audio_path" not in columns:
connection.execute("ALTER TABLE notes ADD COLUMN original_audio_path TEXT")
if "corrected_transcript" not in columns:
connection.execute("ALTER TABLE notes ADD COLUMN corrected_transcript TEXT NOT NULL DEFAULT ''")
initialize_db()
@@ -636,7 +639,7 @@ def list_notes(q: str = "", status: str = "") -> list[dict[str, str]]:
query = " AND ".join(f'"{term.replace(chr(34), chr(34) * 2)}"' for term in search_terms)
if status:
rows = connection.execute(
"""SELECT n.id, n.created_at, n.filename, n.transcript, n.status
"""SELECT n.id, n.created_at, n.filename, n.transcript, n.corrected_transcript, n.status
FROM note_search s JOIN notes n ON n.id = s.note_id
WHERE note_search MATCH ? AND n.status = ?
ORDER BY n.created_at DESC LIMIT 100""",
@@ -644,20 +647,20 @@ def list_notes(q: str = "", status: str = "") -> list[dict[str, str]]:
).fetchall()
else:
rows = connection.execute(
"""SELECT n.id, n.created_at, n.filename, n.transcript, n.status
"""SELECT n.id, n.created_at, n.filename, n.transcript, n.corrected_transcript, n.status
FROM note_search s JOIN notes n ON n.id = s.note_id
WHERE note_search MATCH ? ORDER BY n.created_at DESC LIMIT 100""",
(query,),
).fetchall()
elif status:
rows = connection.execute(
"""SELECT id, created_at, filename, transcript, status
"""SELECT id, created_at, filename, transcript, corrected_transcript, status
FROM notes WHERE status = ? ORDER BY created_at DESC LIMIT 100""",
(status,),
).fetchall()
else:
rows = connection.execute(
"""SELECT id, created_at, filename, transcript, status
"""SELECT id, created_at, filename, transcript, corrected_transcript, status
FROM notes ORDER BY created_at DESC LIMIT 100"""
).fetchall()
return [dict(row) for row in rows]
@@ -684,14 +687,24 @@ def delete_note(note_id: str) -> dict[str, str]:
async def save_transcript(note_id: str, payload: dict[str, str]) -> dict[str, str]:
transcript = payload.get("transcript", "").strip()
with connect_db() as connection:
note = connection.execute("SELECT status FROM notes WHERE id = ?", (note_id,)).fetchone()
note = connection.execute("SELECT transcript FROM notes WHERE id = ?", (note_id,)).fetchone()
if not note:
raise HTTPException(status_code=404, detail="Note not found")
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": status}
with connect_db() as connection:
connection.execute(
"UPDATE notes SET corrected_transcript = ? WHERE id = ?",
(transcript, note_id),
)
connection.execute("DELETE FROM note_search WHERE note_id = ?", (note_id,))
searchable_text = transcript or note["transcript"]
if searchable_text.strip():
connection.execute(
"INSERT INTO note_search (note_id, transcript) VALUES (?, ?)",
(note_id, searchable_text.strip()),
)
connection.execute("UPDATE backup_state SET revision = revision + 1 WHERE id = 1")
schedule_backup()
return {"id": note_id, "status": "saved"}
app.mount("/", StaticFiles(directory=FRONTEND_DIR, html=True), name="frontend")