chore(ledger): 重建所有历史资产快照,对齐最新修复的财务聚合计算逻辑

This commit is contained in:
2026-05-02 19:43:41 +08:00
parent bbcfc7d1bf
commit 3d0cfda981
2 changed files with 55 additions and 1 deletions
+48
View File
@@ -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 }
);
}
}