41 lines
1.2 KiB
TypeScript
Raw Normal View History

import { NextResponse } from 'next/server';
import { getOpenClawConfig, applyConfig } from '@/lib/openclaw';
export async function GET() {
try {
const config = await getOpenClawConfig();
// Mask API keys for security
const maskedConfig = JSON.parse(JSON.stringify(config));
if (maskedConfig.auth?.profiles) {
for (const profile of Object.values(maskedConfig.auth.profiles) as any) {
if (profile.apiKey) {
profile.apiKey = profile.apiKey.slice(0, 8) + '***masked***';
}
}
}
if (maskedConfig.tools?.web?.search?.apiKey) {
maskedConfig.tools.web.search.apiKey =
maskedConfig.tools.web.search.apiKey.slice(0, 8) + '***masked***';
}
return NextResponse.json(maskedConfig);
} catch (error) {
return NextResponse.json(
{ error: (error as Error).message },
{ status: 500 }
);
}
}
export async function POST(request: Request) {
try {
const config = await request.json();
const result = await applyConfig(config);
return NextResponse.json(result);
} catch (error) {
return NextResponse.json(
{ error: (error as Error).message },
{ status: 500 }
);
}
}