import { query, getRequestEvent } from '$app/server'; import * as v from 'valibot'; import { searchWordformsApiDictionarySearchGet, searchWordformsApiDictionaryWordformsGet } from '../../../../client'; import { COOKIE_NAME_AUTH_TOKEN } from '$lib/auth'; export const dictionarySearch = query( v.object({ text: v.string(), langCode: v.string() }), async ({ langCode, text }) => { const { cookies } = getRequestEvent(); const trimmed = text.trim(); if (trimmed.length === 0) { return []; } if (trimmed.length < 5) { const { data } = await searchWordformsApiDictionaryWordformsGet({ headers: { Authorization: `Bearer ${cookies.get(COOKIE_NAME_AUTH_TOKEN)}` }, query: { lang_code: langCode, text } }); return data; } else { const { data } = await searchWordformsApiDictionarySearchGet({ headers: { Authorization: `Bearer ${cookies.get(COOKIE_NAME_AUTH_TOKEN)}` }, query: { lang_code: langCode, text } }); return data; } } );