added recoding and settings tab
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user