cleaned up and added a logging system
This commit is contained in:
@@ -90,6 +90,26 @@ export async function GET(request: Request) {
|
||||
});
|
||||
}
|
||||
}
|
||||
const logs = searchParams.get('logs');
|
||||
if (logs === '1') {
|
||||
// Call the Rust backend for parser logs
|
||||
const rustResult = spawnSync(
|
||||
process.cwd() + '/markdown_backend/target/release/markdown_backend',
|
||||
['logs'],
|
||||
{ encoding: 'utf-8' }
|
||||
);
|
||||
if (rustResult.status === 0 && rustResult.stdout) {
|
||||
return new Response(rustResult.stdout, {
|
||||
status: 200,
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
});
|
||||
} else {
|
||||
return new Response(JSON.stringify({ error: rustResult.stderr || rustResult.error }), {
|
||||
status: 500,
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
});
|
||||
}
|
||||
}
|
||||
// Return the current pinned.json object
|
||||
try {
|
||||
const pinnedPath = path.join(process.cwd(), 'posts', 'pinned.json');
|
||||
@@ -150,4 +170,36 @@ export async function PUT(request: Request) {
|
||||
console.error('Error editing post:', error);
|
||||
return NextResponse.json({ error: 'Error editing post' }, { status: 500 });
|
||||
}
|
||||
}
|
||||
|
||||
export async function DELETE(request: Request) {
|
||||
try {
|
||||
const { searchParams } = new URL(request.url);
|
||||
const clearLogs = searchParams.get('clearLogs');
|
||||
|
||||
if (clearLogs === '1') {
|
||||
// Call the Rust backend to clear parser logs
|
||||
const rustResult = spawnSync(
|
||||
process.cwd() + '/markdown_backend/target/release/markdown_backend',
|
||||
['clearLogs'],
|
||||
{ encoding: 'utf-8' }
|
||||
);
|
||||
if (rustResult.status === 0 && rustResult.stdout) {
|
||||
return new Response(rustResult.stdout, {
|
||||
status: 200,
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
});
|
||||
} else {
|
||||
return new Response(JSON.stringify({ error: rustResult.stderr || rustResult.error }), {
|
||||
status: 500,
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return NextResponse.json({ error: 'Invalid delete operation' }, { status: 400 });
|
||||
} catch (error) {
|
||||
console.error('Error clearing logs:', error);
|
||||
return NextResponse.json({ error: 'Error clearing logs' }, { status: 500 });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user