feat(settings): add admin settings API routes
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
import type { ActionFunction } from '@remix-run/node';
|
||||
import { settingsService } from '~/lib/settings.server';
|
||||
import { requireAdmin } from '~/lib/auth.server';
|
||||
|
||||
export const action: ActionFunction = async ({ request, params }) => {
|
||||
await requireAdmin(request);
|
||||
const key = params.key as string;
|
||||
const body = await request.json();
|
||||
if (!key) return new Response('Missing key', { status: 400 });
|
||||
await settingsService.set(key, body.value, 'admin');
|
||||
return new Response(null, { status: 204 });
|
||||
};
|
||||
@@ -0,0 +1,23 @@
|
||||
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';
|
||||
|
||||
export const loader: LoaderFunction = async ({ request }) => {
|
||||
await requireAdmin(request);
|
||||
await settingsService.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);
|
||||
};
|
||||
|
||||
export const action: ActionFunction = async ({ 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 });
|
||||
};
|
||||
Reference in New Issue
Block a user