29 lines
950 B
TypeScript
29 lines
950 B
TypeScript
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<boolean> {
|
|
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<AppLocalPreferences>(req);
|
|
sendJson(res, 200, await patchLocalPreferences(patch));
|
|
} catch (error) {
|
|
sendJson(res, 500, { success: false, error: String(error) });
|
|
}
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|