Spaces:
Sleeping
Sleeping
Download src/app/api/gallery/route.ts from veltrixcode/Iot: direct link, hf CLI and curl.
- Browser
- Download file 1.46 kB
-
https://huggingface.co/spaces/veltrixcode/Iot/resolve/main/src/app/api/gallery/route.ts
- Command line
-
hf download hf://spaces/veltrixcode/Iot/src/app/api/gallery/route.ts
-
curl -L -o route.ts https://huggingface.co/spaces/veltrixcode/Iot/resolve/main/src/app/api/gallery/route.ts
1.46 kB
| import { prisma } from "@/lib/prisma" | |
| import { NextResponse } from "next/server" | |
| export async function GET(request: Request) { | |
| try { | |
| const { searchParams } = new URL(request.url) | |
| const cursor = searchParams.get("cursor") | |
| const limit = parseInt(searchParams.get("limit") || "20") | |
| const generations = await prisma.generation.findMany({ | |
| where: { isPublic: true }, | |
| orderBy: [{ createdAt: "desc" }, { id: "desc" }], | |
| take: limit + 1, // Fetch one extra to check for next page | |
| cursor: cursor ? { id: cursor } : undefined, | |
| skip: cursor ? 1 : 0, // Skip the cursor itself if present | |
| include: { | |
| user: { | |
| select: { | |
| name: true, | |
| username: true, | |
| image: true, | |
| }, | |
| }, | |
| }, | |
| }) | |
| let nextCursor: string | null = null | |
| if (generations.length > limit) { | |
| const nextItem = generations.pop() // Remove the extra item | |
| nextCursor = nextItem?.id || null | |
| } | |
| return NextResponse.json({ | |
| data: generations, | |
| nextCursor, | |
| }) | |
| } catch (error) { | |
| console.error("Gallery fetch error:", error) | |
| return NextResponse.json( | |
| { error: "Failed to fetch gallery images" }, | |
| { status: 500 } | |
| ) | |
| } | |
| } | |