Untitled
export async function GET() { try { const fileContent = await fs.readFile(METRICS_FILE, 'utf-8'); const metrics = JSON.parse(fileContent); // Use the non-empty fill_predictions if (Object.keys(metrics.time_metrics.fill_predictions || {}).length > 0) { metrics.fill_predictions = metrics.time_metrics.fill_predictions; } // Otherwise keep the root level fill_predictions if it's not empty else if (Object.keys(metrics.fill_predictions || {}).length === 0) { metrics.fill_predictions = {}; } return NextResponse.json(metrics); } catch (error) { console.error('Error reading metrics file:', error); return NextResponse.json( { error: 'Failed to read metrics data' }, { status: 500 } ); } }
Leave a Comment