MCPcopy Create free account
hub / github.com/karpathy/reader3 / read_chapter

Function read_chapter

server.py:64–87  ·  view source on GitHub ↗

The main reader interface.

(request: Request, book_id: str, chapter_index: int)

Source from the content-addressed store, hash-verified

62
63@app.get("/read/{book_id}/{chapter_index}", response_class=HTMLResponse)
64async 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}")
90async def serve_image(book_id: str, image_name: str):

Callers 1

Calls 1

load_book_cachedFunction · 0.85

Tested by

no test coverage detected