The main reader interface.
(request: Request, book_id: str, chapter_index: int)
| 62 | |
| 63 | @app.get("/read/{book_id}/{chapter_index}", response_class=HTMLResponse) |
| 64 | async def read_chapter(request: Request, book_id: str, chapter_index: int): |
| 65 | """The main reader interface.""" |
| 66 | book = load_book_cached(book_id) |
| 67 | if not book: |
| 68 | raise HTTPException(status_code=404, detail="Book not found") |
| 69 | |
| 70 | if chapter_index < 0 or chapter_index >= len(book.spine): |
| 71 | raise HTTPException(status_code=404, detail="Chapter not found") |
| 72 | |
| 73 | current_chapter = book.spine[chapter_index] |
| 74 | |
| 75 | # Calculate Prev/Next links |
| 76 | prev_idx = chapter_index - 1 if chapter_index > 0 else None |
| 77 | next_idx = chapter_index + 1 if chapter_index < len(book.spine) - 1 else None |
| 78 | |
| 79 | return templates.TemplateResponse("reader.html", { |
| 80 | "request": request, |
| 81 | "book": book, |
| 82 | "current_chapter": current_chapter, |
| 83 | "chapter_index": chapter_index, |
| 84 | "book_id": book_id, |
| 85 | "prev_idx": prev_idx, |
| 86 | "next_idx": next_idx |
| 87 | }) |
| 88 | |
| 89 | @app.get("/read/{book_id}/images/{image_name}") |
| 90 | async def serve_image(book_id: str, image_name: str): |
no test coverage detected