chore(ledger): 重建所有历史资产快照,对齐最新修复的财务聚合计算逻辑
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
import { reconstructPortfolioHistory } from '@/actions/snapshots';
|
||||
|
||||
export const dynamic = 'force-dynamic';
|
||||
export const runtime = 'nodejs';
|
||||
export const maxDuration = 3600;
|
||||
|
||||
export async function POST(req: Request) {
|
||||
const rebuildSecret = process.env.REBUILD_SECRET || process.env.CRON_SECRET;
|
||||
const authHeader = req.headers.get('Authorization');
|
||||
|
||||
if (!rebuildSecret) {
|
||||
return NextResponse.json(
|
||||
{ error: 'REBUILD_SECRET or CRON_SECRET not configured' },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
|
||||
if (authHeader !== `Bearer ${rebuildSecret}`) {
|
||||
return NextResponse.json(
|
||||
{ error: 'Unauthorized' },
|
||||
{ status: 401 }
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
console.log('[Rebuild Snapshots] Starting full rebuild...');
|
||||
|
||||
const result = await reconstructPortfolioHistory();
|
||||
|
||||
console.log('[Rebuild Snapshots] Rebuild complete:', result);
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
message: '历史快照全量重建完成',
|
||||
daysReconstructed: result.daysReconstructed,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('[Rebuild Snapshots] Rebuild failed:', error);
|
||||
return NextResponse.json(
|
||||
{
|
||||
error: '重建失败',
|
||||
details: String(error),
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user