mirror of
https://github.com/yusufipk/RepoHub.git
synced 2026-09-11 18:46:07 +00:00
feat: introduce API rate limiting for API routes and cap package query limits.
This commit is contained in:
@@ -4,26 +4,26 @@ import { PackageService } from '@/services/packageService'
|
||||
export async function GET(request: NextRequest) {
|
||||
try {
|
||||
const { searchParams } = new URL(request.url)
|
||||
|
||||
|
||||
// Parse query parameters
|
||||
const filter = {
|
||||
platform_id: searchParams.get('platform_id') || undefined,
|
||||
category_id: searchParams.get('category_id') ?
|
||||
category_id: searchParams.get('category_id') ?
|
||||
parseInt(searchParams.get('category_id')!) : undefined,
|
||||
type: searchParams.get('type') as 'gui' | 'cli' | undefined,
|
||||
repository: searchParams.get('repository') as 'official' | 'third-party' | 'aur' | undefined,
|
||||
search: searchParams.get('search') || undefined,
|
||||
limit: searchParams.get('limit') ?
|
||||
parseInt(searchParams.get('limit')!) : undefined,
|
||||
offset: searchParams.get('offset') ?
|
||||
limit: searchParams.get('limit') ?
|
||||
Math.min(parseInt(searchParams.get('limit')!), 100) : undefined,
|
||||
offset: searchParams.get('offset') ?
|
||||
parseInt(searchParams.get('offset')!) : undefined,
|
||||
sort_by: searchParams.get('sort_by') as
|
||||
sort_by: searchParams.get('sort_by') as
|
||||
'name' | 'popularity_score' | 'last_updated' | 'downloads_count' | undefined,
|
||||
sort_order: searchParams.get('sort_order') as 'asc' | 'desc' | undefined
|
||||
}
|
||||
|
||||
const result = await PackageService.getMany(filter)
|
||||
|
||||
|
||||
return NextResponse.json({
|
||||
packages: result.packages,
|
||||
total: result.total,
|
||||
|
||||
Reference in New Issue
Block a user