stock-portfolio_byQwen3.6/scripts/trigger-rebuild.ts

39 lines
1.2 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { config } from 'dotenv';
// 强制加载所有可能的本地环境变量文件
config({ path: ['.env.local', '.env'] });
const triggerRebuild = async () => {
// 优先读取 REBUILD_SECRET降级读取 CRON_SECRET
const secret = process.env.REBUILD_SECRET || process.env.CRON_SECRET;
if (!secret) {
console.error('❌ 致命错误: 未在 .env.local 或 .env 找到 REBUILD_SECRET 或 CRON_SECRET');
process.exit(1);
}
console.log('🚀 正在携带合法 Token 请求时光机重置接口...');
try {
// 默认请求本地 8080 端口,确保 Next.js 服务正在运行
const response = await fetch('http://localhost:8080/api/admin/rebuild-snapshots', {
method: 'POST',
headers: {
'Authorization': `Bearer ${secret}`,
'Content-Type': 'application/json'
}
});
const data = await response.json();
if (response.ok) {
console.log('✅ 历史快照重建成功!', JSON.stringify(data, null, 2));
} else {
console.error('❌ 重建失败,服务器返回:', data);
}
} catch (error) {
console.error('❌ 请求发送异常 (请确认 npm run dev 正在运行且端口为 8080):', error);
}
};
triggerRebuild();