summaryrefslogtreecommitdiff
path: root/src/routes/api/search/+server.ts
blob: 57bf347cb8307306ef12aa384734903ac7e96651 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import { json } from '@sveltejs/kit';
import { search } from '$lib/server/ytdlp';
import type { RequestHandler } from './$types';

export const GET: RequestHandler = async ({ url }) => {
  const query = url.searchParams.get('q');
  if (!query) {
    return json({ error: 'Missing query parameter' }, { status: 400 });
  }

  try {
    const results = await search(query);
    return json(results);
  } catch (e) {
    console.error('Search error:', e);
    return json({ error: 'Search failed' }, { status: 500 });
  }
};