added recoding and settings tab

This commit is contained in:
2025-01-13 12:37:08 +01:00
parent b2267813c0
commit 6918534b95
7 changed files with 269 additions and 9 deletions
+27
View File
@@ -2,6 +2,8 @@ import {NextResponse} from "next/server";
import fs from "fs";
import path from "path";
let writeLock: boolean = false;
export async function GET() {
const configPath = process.env.CONFIG_PATH || "./config.json";
const absolutePath = path.resolve(configPath);
@@ -14,4 +16,29 @@ export async function GET() {
const config = JSON.parse(fileContent);
return NextResponse.json(config);
}
// post function for updating the config
export async function POST({body}) {
if (writeLock) {
return NextResponse.json({error: "Write lock is active"}, {status: 400});
}
writeLock = true;
try {
const configPath = process.env.CONFIG_PATH || "./config.json";
const absolutePath = path.resolve(configPath);
fs.writeFileSync(absolutePath, JSON.stringify(body, null, 2));
return NextResponse.json({success: true});
}
catch (e) {
return NextResponse.json({error: e.message}, {status: 500});
}
finally {
writeLock = false;
}
}