import type { IncomingMessage, ServerResponse } from 'http'; import { getAllLocalPreferences, patchLocalPreferences, type AppLocalPreferences } from '../../utils/local-preferences'; import type { HostApiContext } from '../context'; import { parseJsonBody, sendJson } from '../route-utils'; export async function handleLocalPreferenceRoutes( req: IncomingMessage, res: ServerResponse, url: URL, _ctx: HostApiContext, ): Promise { if (url.pathname === '/api/local-preferences' && req.method === 'GET') { sendJson(res, 200, await getAllLocalPreferences()); return true; } if (url.pathname === '/api/local-preferences' && req.method === 'PUT') { try { const patch = await parseJsonBody(req); sendJson(res, 200, await patchLocalPreferences(patch)); } catch (error) { sendJson(res, 500, { success: false, error: String(error) }); } return true; } return false; }