Add admin upgrade package preflight

This commit is contained in:
FengLee
2026-05-10 00:18:03 +08:00
parent 70656562b1
commit 8ae28e030d
3 changed files with 79 additions and 18 deletions

View File

@@ -37,6 +37,7 @@ type UpgradeJobState = {
updatedAt: string;
finishedAt?: string;
logs: string[];
dryRun?: boolean;
};
const MAX_PACKAGE_BYTES = 300 * 1024 * 1024;
@@ -74,6 +75,7 @@ export async function POST(request: NextRequest) {
const form = await request.formData();
const modeValue = String(form.get('mode') || '');
const mode = modeValue === 'hot' || modeValue === 'cold' ? modeValue : null;
const dryRun = String(form.get('dryRun') || '') === 'true';
if (!mode) {
return NextResponse.json({ error: '请选择热更新或冷更新' }, { status: 400 });
}
@@ -116,10 +118,14 @@ export async function POST(request: NextRequest) {
startedAt: now,
updatedAt: now,
logs: [`[${now}] 上传升级包 ${file.name} (${file.size} bytes)`],
dryRun,
};
if (dryRun) {
initialState.message = '升级包已上传,正在执行预检';
}
await writeState(jobDir, initialState);
const child = spawn(process.execPath, [
const runnerArgs = [
path.join(process.cwd(), 'scripts/admin-upgrade-runner.mjs'),
'--job-id',
jobId,
@@ -131,7 +137,10 @@ export async function POST(request: NextRequest) {
file.name,
'--project',
process.cwd(),
], {
];
if (dryRun) runnerArgs.push('--dry-run', 'true');
const child = spawn(process.execPath, runnerArgs, {
cwd: process.cwd(),
detached: true,
stdio: 'ignore',
@@ -143,7 +152,7 @@ export async function POST(request: NextRequest) {
});
child.unref();
return NextResponse.json({ success: true, job: initialState });
return NextResponse.json({ success: true, dryRun, job: initialState });
} catch (error) {
console.error('[admin/upgrade] failed to start upgrade:', error);
return NextResponse.json({ error: error instanceof Error ? error.message : '创建升级任务失败' }, { status: 500 });