Download src/app/api/reading/content/route.ts from NAP1320/RotNot: direct link, hf CLI and curl.
- Browser
- Download file 1.41 kB
-
https://huggingface.co/spaces/NAP1320/RotNot/resolve/main/src/app/api/reading/content/route.ts
- Command line
-
hf download hf://spaces/NAP1320/RotNot/src/app/api/reading/content/route.ts
-
curl -L -o route.ts https://huggingface.co/spaces/NAP1320/RotNot/resolve/main/src/app/api/reading/content/route.ts
1.41 kB
| import { NextRequest, NextResponse } from "next/server"; | |
| import { | |
| ARTICLES, | |
| getArticleBySlug, | |
| getRandomArticle, | |
| type ArticleDifficulty, | |
| } from "@/lib/reading/articles"; | |
| import { withApiError } from "@/lib/api-error"; | |
| /** | |
| * GET /api/reading/content | |
| * | |
| * Query params: | |
| * slug – return a specific article | |
| * difficulty – filter random pick by difficulty (beginner | intermediate | advanced) | |
| * list – if "1", return article metadata (no body) | |
| */ | |
| export const GET = withApiError(async (request: NextRequest) => { | |
| const { searchParams } = new URL(request.url); | |
| const slug = searchParams.get("slug"); | |
| const difficulty = searchParams.get("difficulty") as ArticleDifficulty | null; | |
| const list = searchParams.get("list"); | |
| // List mode: return metadata only | |
| if (list === "1") { | |
| // eslint-disable-next-line @typescript-eslint/no-unused-vars | |
| const articles = ARTICLES.map(({ body: _body, ...meta }) => meta); | |
| return NextResponse.json({ articles }); | |
| } | |
| // Specific slug | |
| if (slug) { | |
| const article = getArticleBySlug(slug); | |
| if (!article) { | |
| return NextResponse.json({ error: "Article not found", status: 404 }, { status: 404 }); | |
| } | |
| return NextResponse.json({ article }); | |
| } | |
| // Random article (optionally filtered by difficulty) | |
| const article = getRandomArticle(difficulty ?? undefined); | |
| return NextResponse.json({ article }); | |
| }); | |