feat(settings): add settings route and API updates\n\nCo-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -1,23 +1,20 @@
|
||||
import type { LoaderFunction, ActionFunction } from '@remix-run/node';
|
||||
import { json } from '@remix-run/node';
|
||||
import { settingsService } from '~/lib/settings.server';
|
||||
import { requireAdmin } from '~/lib/auth.server';
|
||||
import { settingsService } from '../../../../lib/settings.server';
|
||||
import { requireAdmin } from '../../../../lib/auth.server';
|
||||
|
||||
export const loader: LoaderFunction = async ({ request }) => {
|
||||
export async function loader({ request }: { request: Request }) {
|
||||
await requireAdmin(request);
|
||||
await settingsService.init?.();
|
||||
await (settingsService as any).init?.();
|
||||
const entries: any[] = [];
|
||||
// @ts-ignore access cache
|
||||
for (const key of (settingsService as any).cache.keys()) {
|
||||
entries.push({ key, value: await settingsService.get(key) });
|
||||
}
|
||||
return json(entries);
|
||||
};
|
||||
return new Response(JSON.stringify(entries), { headers: { 'content-type': 'application/json' } });
|
||||
}
|
||||
|
||||
export const action: ActionFunction = async ({ request }) => {
|
||||
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 });
|
||||
};
|
||||
return new Response(JSON.stringify(created), { status: 201, headers: { 'content-type': 'application/json' } });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user