37 lines
1.2 KiB
JavaScript
37 lines
1.2 KiB
JavaScript
import { NextResponse } from 'next/server';
|
|
import fs from 'fs';
|
|
import yaml from 'js-yaml';
|
|
|
|
const CONFIG_PATH = 'c:/Users/sunde/proxmox/agentic-os/agents/k8s/whatsapp-config.yaml';
|
|
|
|
export async function GET() {
|
|
try {
|
|
const fileContents = fs.readFileSync(CONFIG_PATH, 'utf8');
|
|
const doc = yaml.load(fileContents);
|
|
return NextResponse.json({ success: true, data: doc.data });
|
|
} catch (e) {
|
|
return NextResponse.json({ success: false, error: e.message }, { status: 500 });
|
|
}
|
|
}
|
|
|
|
export async function PUT(req) {
|
|
try {
|
|
const body = await req.json();
|
|
const { defaultGroupUrl, tripGroupUrl } = body;
|
|
|
|
const fileContents = fs.readFileSync(CONFIG_PATH, 'utf8');
|
|
const doc = yaml.load(fileContents);
|
|
|
|
if (!doc.data) doc.data = {};
|
|
if (defaultGroupUrl) doc.data['default-group-url'] = defaultGroupUrl;
|
|
if (tripGroupUrl) doc.data['trip-group-url'] = tripGroupUrl;
|
|
|
|
const newYaml = yaml.dump(doc, { lineWidth: -1 });
|
|
fs.writeFileSync(CONFIG_PATH, newYaml, 'utf8');
|
|
|
|
return NextResponse.json({ success: true, data: doc.data });
|
|
} catch (e) {
|
|
return NextResponse.json({ success: false, error: e.message }, { status: 500 });
|
|
}
|
|
}
|