Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
|
@@ -471,13 +471,13 @@ async def serve_shelf():
|
|
| 471 |
async def api_get_shelf():
|
| 472 |
"""API endpoint to get all shelf items with their progress."""
|
| 473 |
rows = await sheets.get_all_rows_sync_fallback()
|
| 474 |
-
progress_data = progress.get_all_progress
|
| 475 |
return {"status": "success", "data": rows, "progress": progress_data}
|
| 476 |
|
| 477 |
@app.get("/api/progress")
|
| 478 |
async def api_get_progress():
|
| 479 |
"""API endpoint to get all user progress."""
|
| 480 |
-
progress_data = progress.get_all_progress
|
| 481 |
return {"status": "success", "progress": progress_data}
|
| 482 |
|
| 483 |
class ProgressUpdate(BaseModel):
|
|
@@ -488,11 +488,12 @@ class ProgressUpdate(BaseModel):
|
|
| 488 |
@app.post("/api/progress")
|
| 489 |
async def api_update_progress(update: ProgressUpdate):
|
| 490 |
"""API endpoint to update user progress for an item."""
|
| 491 |
-
success = progress.update_progress
|
| 492 |
if success:
|
| 493 |
return {"status": "success"}
|
| 494 |
else:
|
| 495 |
-
|
|
|
|
| 496 |
|
| 497 |
class NoteCreate(BaseModel):
|
| 498 |
content_hash: str
|
|
@@ -502,16 +503,17 @@ class NoteCreate(BaseModel):
|
|
| 502 |
@app.get("/api/notes/{content_hash}")
|
| 503 |
async def api_get_notes(content_hash: str):
|
| 504 |
"""API endpoint to get all notes for a specific content item."""
|
| 505 |
-
notes = progress.get_notes
|
| 506 |
return {"status": "success", "notes": notes}
|
| 507 |
|
| 508 |
@app.post("/api/notes")
|
| 509 |
async def api_create_note(note: NoteCreate):
|
| 510 |
"""API endpoint to create a new timestamped note."""
|
| 511 |
-
new_note = progress.add_note
|
| 512 |
if new_note:
|
| 513 |
return {"status": "success", "note": new_note}
|
| 514 |
-
|
|
|
|
| 515 |
|
| 516 |
class GenerateNoteRequest(BaseModel):
|
| 517 |
title: str
|
|
@@ -519,14 +521,15 @@ class GenerateNoteRequest(BaseModel):
|
|
| 519 |
@app.post("/api/notes/{content_hash}/generate")
|
| 520 |
async def api_generate_notes_summary(content_hash: str, req: GenerateNoteRequest):
|
| 521 |
"""API endpoint to generate an AI summary from existing notes."""
|
| 522 |
-
notes = progress.get_notes
|
|
|
|
| 523 |
if not notes:
|
| 524 |
-
|
| 525 |
|
| 526 |
summary = await ai_client.generate_notes_summary(req.title, notes)
|
| 527 |
if summary:
|
| 528 |
return {"status": "success", "summary": summary}
|
| 529 |
-
|
| 530 |
|
| 531 |
@app.get("/", response_class=HTMLResponse)
|
| 532 |
async def serve_dashboard():
|
|
|
|
| 471 |
async def api_get_shelf():
|
| 472 |
"""API endpoint to get all shelf items with their progress."""
|
| 473 |
rows = await sheets.get_all_rows_sync_fallback()
|
| 474 |
+
progress_data = await asyncio.to_thread(progress.get_all_progress)
|
| 475 |
return {"status": "success", "data": rows, "progress": progress_data}
|
| 476 |
|
| 477 |
@app.get("/api/progress")
|
| 478 |
async def api_get_progress():
|
| 479 |
"""API endpoint to get all user progress."""
|
| 480 |
+
progress_data = await asyncio.to_thread(progress.get_all_progress)
|
| 481 |
return {"status": "success", "progress": progress_data}
|
| 482 |
|
| 483 |
class ProgressUpdate(BaseModel):
|
|
|
|
| 488 |
@app.post("/api/progress")
|
| 489 |
async def api_update_progress(update: ProgressUpdate):
|
| 490 |
"""API endpoint to update user progress for an item."""
|
| 491 |
+
success = await asyncio.to_thread(progress.update_progress, update.content_hash, update.progress_seconds, update.is_completed)
|
| 492 |
if success:
|
| 493 |
return {"status": "success"}
|
| 494 |
else:
|
| 495 |
+
from fastapi import HTTPException
|
| 496 |
+
raise HTTPException(status_code=500, detail="Failed to update progress")
|
| 497 |
|
| 498 |
class NoteCreate(BaseModel):
|
| 499 |
content_hash: str
|
|
|
|
| 503 |
@app.get("/api/notes/{content_hash}")
|
| 504 |
async def api_get_notes(content_hash: str):
|
| 505 |
"""API endpoint to get all notes for a specific content item."""
|
| 506 |
+
notes = await asyncio.to_thread(progress.get_notes, content_hash)
|
| 507 |
return {"status": "success", "notes": notes}
|
| 508 |
|
| 509 |
@app.post("/api/notes")
|
| 510 |
async def api_create_note(note: NoteCreate):
|
| 511 |
"""API endpoint to create a new timestamped note."""
|
| 512 |
+
new_note = await asyncio.to_thread(progress.add_note, note.content_hash, note.timestamp_seconds, note.note_text)
|
| 513 |
if new_note:
|
| 514 |
return {"status": "success", "note": new_note}
|
| 515 |
+
from fastapi import HTTPException
|
| 516 |
+
raise HTTPException(status_code=500, detail="Failed to create note")
|
| 517 |
|
| 518 |
class GenerateNoteRequest(BaseModel):
|
| 519 |
title: str
|
|
|
|
| 521 |
@app.post("/api/notes/{content_hash}/generate")
|
| 522 |
async def api_generate_notes_summary(content_hash: str, req: GenerateNoteRequest):
|
| 523 |
"""API endpoint to generate an AI summary from existing notes."""
|
| 524 |
+
notes = await asyncio.to_thread(progress.get_notes, content_hash)
|
| 525 |
+
from fastapi import HTTPException
|
| 526 |
if not notes:
|
| 527 |
+
raise HTTPException(status_code=400, detail="No notes found")
|
| 528 |
|
| 529 |
summary = await ai_client.generate_notes_summary(req.title, notes)
|
| 530 |
if summary:
|
| 531 |
return {"status": "success", "summary": summary}
|
| 532 |
+
raise HTTPException(status_code=500, detail="Failed to generate summary")
|
| 533 |
|
| 534 |
@app.get("/", response_class=HTMLResponse)
|
| 535 |
async def serve_dashboard():
|