21 lines
937 B
TypeScript
21 lines
937 B
TypeScript
import { settingsService } from '../../../../lib/settings.server';
|
|
import { requireAdmin } from '../../../../lib/auth.server';
|
|
|
|
export async function loader({ request }: { request: Request }) {
|
|
await requireAdmin(request);
|
|
await (settingsService as any).init?.();
|
|
const entries: any[] = [];
|
|
for (const key of (settingsService as any).cache.keys()) {
|
|
entries.push({ key, value: await settingsService.get(key) });
|
|
}
|
|
return new Response(JSON.stringify(entries), { headers: { 'content-type': 'application/json' } });
|
|
}
|
|
|
|
export async function action({ request }: { request: Request }) {
|
|
await requireAdmin(request);
|
|
const body = await request.json();
|
|
if (!body || !body.key) return new Response('Missing key', { status: 400 });
|
|
const created = await settingsService.set(body.key, body.value, 'admin');
|
|
return new Response(JSON.stringify(created), { status: 201, headers: { 'content-type': 'application/json' } });
|
|
}
|