12 lines
532 B
TypeScript
12 lines
532 B
TypeScript
|
|
import type { RequestHandler } from './$types';
|
||
|
|
import { json } from '@sveltejs/kit';
|
||
|
|
import { getDb } from '$lib/server/db';
|
||
|
|
import { listRecentRecipes, searchLocal } from '$lib/server/recipes/search-local';
|
||
|
|
|
||
|
|
export const GET: RequestHandler = async ({ url }) => {
|
||
|
|
const q = url.searchParams.get('q')?.trim() ?? '';
|
||
|
|
const limit = Math.min(Number(url.searchParams.get('limit') ?? 30), 100);
|
||
|
|
const hits = q.length >= 1 ? searchLocal(getDb(), q, limit) : listRecentRecipes(getDb(), limit);
|
||
|
|
return json({ query: q, hits });
|
||
|
|
};
|