Source identity
| Field | Recorded value |
|---|---|
| Source type | GitHub source |
| Original record | Janady13/llms-txt-hub / apps/web/app/api/websites/paginated/route.ts |
| Date | Not specified in source |
| Repository | Janady13/llms-txt-hub |
| Revision | e0f4bf978d4df168369c7601d9c5f5ea89e84377 |
| Branch | main |
| Path or archive member | apps/web/app/api/websites/paginated/route.ts |
| Original SHA-256 | 4f405eaab6cc54e64549740c0a0cf323a88656ba18fbc262ba2b4490d55ab6d1 |
| Git blob SHA | ae02fcbd5308b0bdca9a702be75c7fff4ff126e1 |
| Reading-copy SHA-256 | 4f405eaab6cc54e64549740c0a0cf323a88656ba18fbc262ba2b4490d55ab6d1 |
Recovered source transcript
Download complete source text ↓71 lines · 2.0 KB
import { logger } from '@thedaviddias/logging'
import { NextResponse } from 'next/server'
import { getWebsites } from '@/lib/content-loader'
interface PaginatedWebsitesResponse {
websites: Array<{
slug: string
name: string
description: string
website: string
category: string
publishedAt: string
isUnofficial?: boolean
}>
totalCount: number
page: number
totalPages: number
hasMore: boolean
}
/**
* API endpoint for paginated website loading
* Used for Load More pattern - loads 48 websites at a time by default
*/
export async function GET(request: Request) {
try {
const { searchParams } = new URL(request.url)
const page = Math.max(1, Number.parseInt(searchParams.get('page') || '1', 10))
const limit = Math.min(
100,
Math.max(10, Number.parseInt(searchParams.get('limit') || '48', 10))
)
const offset = Number.parseInt(searchParams.get('offset') || '0', 10)
const allWebsites = await getWebsites()
const totalCount = allWebsites.length
// Calculate pagination
const startIndex = offset || (page - 1) * limit
const endIndex = startIndex + limit
const websites = allWebsites.slice(startIndex, endIndex)
const totalPages = Math.ceil(totalCount / limit)
const hasMore = endIndex < totalCount
const response: PaginatedWebsitesResponse = {
websites: websites.map(website => ({
slug: website.slug,
name: website.name,
description: website.description,
website: website.website,
category: website.category,
publishedAt: website.publishedAt,
isUnofficial: website.isUnofficial
})),
totalCount,
page,
totalPages,
hasMore
}
return NextResponse.json(response)
} catch (error) {
logger.error('Error fetching paginated websites', {
data: error,
tags: { api: 'websites-paginated' }
})
return NextResponse.json({ error: 'Failed to fetch websites' }, { status: 500 })
}
}