47 lines
1.3 KiB
TypeScript
47 lines
1.3 KiB
TypeScript
import { NextRequest, NextResponse } from 'next/server';
|
|
import { getAuth } from '@/lib/auth-middleware';
|
|
|
|
const SETTINGS: Record<string, string | boolean> = {
|
|
BOT_TOKEN: '•••••••',
|
|
SUPPORT_LINK: '',
|
|
ADMIN_IDS: '',
|
|
SUPER_ADMIN_IDS: '',
|
|
WG_ENABLED: false,
|
|
WG_ENDPOINT: '',
|
|
WG_ADDRESS: '',
|
|
WG_PUBLIC_KEY: '',
|
|
WG_DNS: '',
|
|
ADMIN_PORT: '3000',
|
|
ADMIN_URL: '',
|
|
CATALOG_PATH: '/catalog',
|
|
GITEA_API_URL: '',
|
|
};
|
|
|
|
const MASKED = ['ENCRYPTION_KEY', 'ADMIN_SECRET', 'GITEA_TOKEN', 'WG_PRIVATE_KEY', 'WG_PRESHARED_KEY'];
|
|
|
|
export async function GET(_request: NextRequest) {
|
|
const auth = getAuth(_request);
|
|
if ('status' in auth) return auth;
|
|
return NextResponse.json({ ...SETTINGS, _masked: MASKED });
|
|
}
|
|
|
|
export async function PUT(request: NextRequest) {
|
|
const auth = getAuth(request);
|
|
if ('status' in auth) return auth;
|
|
|
|
try {
|
|
const body = await request.json();
|
|
const { key, value } = body;
|
|
if (!key) {
|
|
return NextResponse.json({ error: 'Missing key' }, { status: 400 });
|
|
}
|
|
if (key in SETTINGS) {
|
|
SETTINGS[key] = value;
|
|
return NextResponse.json({ ok: true, message: 'Settings saved. Restart required.' });
|
|
}
|
|
return NextResponse.json({ error: 'Unknown setting key' }, { status: 400 });
|
|
} catch {
|
|
return NextResponse.json({ error: 'Invalid request' }, { status: 400 });
|
|
}
|
|
}
|