Refactor project name from "Voice KB" to "Faerro KB" across all files and update related configurations
This commit is contained in:
+38
-9
@@ -12,14 +12,14 @@ from fastapi.staticfiles import StaticFiles
|
||||
|
||||
DATA_DIR = Path(os.environ.get("DATA_DIR", "./data"))
|
||||
AUDIO_DIR = DATA_DIR / "audio"
|
||||
DB_PATH = DATA_DIR / "voice-kb.sqlite3"
|
||||
DB_PATH = DATA_DIR / "faerro-kb.sqlite3"
|
||||
WHISPER_SERVER_URL = os.environ.get("WHISPER_SERVER_URL", "").strip()
|
||||
FRONTEND_DIR = Path(__file__).resolve().parent.parent / "frontend"
|
||||
|
||||
DATA_DIR.mkdir(parents=True, exist_ok=True)
|
||||
AUDIO_DIR.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
app = FastAPI(title="Voice KB")
|
||||
app = FastAPI(title="Faerro KB")
|
||||
|
||||
|
||||
def connect_db() -> sqlite3.Connection:
|
||||
@@ -51,12 +51,12 @@ initialize_db()
|
||||
|
||||
def update_transcript(note_id: str, transcript: str, status: str) -> None:
|
||||
with connect_db() as connection:
|
||||
connection.execute(
|
||||
result = connection.execute(
|
||||
"UPDATE notes SET transcript = ?, status = ? WHERE id = ?",
|
||||
(transcript, status, note_id),
|
||||
)
|
||||
connection.execute("DELETE FROM note_search WHERE note_id = ?", (note_id,))
|
||||
if transcript.strip():
|
||||
if result.rowcount and transcript.strip():
|
||||
connection.execute(
|
||||
"INSERT INTO note_search (note_id, transcript) VALUES (?, ?)",
|
||||
(note_id, transcript.strip()),
|
||||
@@ -135,16 +135,31 @@ async def create_note(
|
||||
|
||||
|
||||
@app.get("/api/notes")
|
||||
def list_notes(q: str = "") -> list[dict[str, str]]:
|
||||
def list_notes(q: str = "", status: str = "") -> list[dict[str, str]]:
|
||||
with connect_db() as connection:
|
||||
search_terms = re.findall(r"[\w]+", q, flags=re.UNICODE)
|
||||
if search_terms:
|
||||
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
|
||||
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""",
|
||||
(query, status),
|
||||
).fetchall()
|
||||
else:
|
||||
rows = connection.execute(
|
||||
"""SELECT n.id, n.created_at, n.filename, n.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 n.id, n.created_at, n.filename, n.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,),
|
||||
"""SELECT id, created_at, filename, transcript, status
|
||||
FROM notes WHERE status = ? ORDER BY created_at DESC LIMIT 100""",
|
||||
(status,),
|
||||
).fetchall()
|
||||
else:
|
||||
rows = connection.execute(
|
||||
@@ -154,6 +169,20 @@ def list_notes(q: str = "") -> list[dict[str, str]]:
|
||||
return [dict(row) for row in rows]
|
||||
|
||||
|
||||
@app.delete("/api/notes/{note_id}")
|
||||
def delete_note(note_id: str) -> dict[str, str]:
|
||||
with connect_db() as connection:
|
||||
note = connection.execute(
|
||||
"SELECT audio_path FROM notes WHERE id = ?", (note_id,)
|
||||
).fetchone()
|
||||
if not note:
|
||||
raise HTTPException(status_code=404, detail="Note not found")
|
||||
connection.execute("DELETE FROM note_search WHERE note_id = ?", (note_id,))
|
||||
connection.execute("DELETE FROM notes WHERE id = ?", (note_id,))
|
||||
Path(note["audio_path"]).unlink(missing_ok=True)
|
||||
return {"id": note_id, "status": "deleted"}
|
||||
|
||||
|
||||
@app.put("/api/notes/{note_id}/transcript")
|
||||
def save_transcript(note_id: str, payload: dict[str, str]) -> dict[str, str]:
|
||||
transcript = payload.get("transcript", "").strip()
|
||||
|
||||
Reference in New Issue
Block a user