fix: 分离小程序构建状态与发布状态
This commit is contained in:
1 parent
998e32e49c
commit
8e90b8ca09
7 files changed
+41
-57
No files matched your search
@@ -1,6 +1,7 @@
|
||||
import {
|
||||
BadRequestException,
|
||||
Body,
|
||||
ConflictException,
|
||||
Controller,
|
||||
Get,
|
||||
Param,
|
||||
@@ -168,6 +169,8 @@ export class AdminMiniAppReleaseController {
|
||||
if (!task) throw new BadRequestException("小程序发布任务不存在");
|
||||
if (task.status !== "built" && task.status !== "failed")
|
||||
throw new BadRequestException("当前小程序发布任务不能重复上传");
|
||||
if (task.buildStatus === "building")
|
||||
throw new ConflictException("小程序构建正在进行中,请稍后");
|
||||
const brand = await this.prisma.brandProfile.findUniqueOrThrow({
|
||||
where: { id: identity.brandId },
|
||||
select: { miniAppSettings: true, templateKey: true },
|
||||
@@ -191,13 +194,18 @@ export class AdminMiniAppReleaseController {
|
||||
},
|
||||
];
|
||||
await this.releases.updateStatus(identity.brandId, identity.subject, taskId, {
|
||||
status: "building",
|
||||
status: task.status,
|
||||
buildLogs,
|
||||
buildStatus: "building",
|
||||
});
|
||||
const result = await this.buildWeApp(templateKey, (message, stream) => {
|
||||
buildLogs.push({ at: new Date().toISOString(), message, stream });
|
||||
void this.releases
|
||||
.updateStatus(identity.brandId, identity.subject, taskId, { status: "building", buildLogs })
|
||||
.updateStatus(identity.brandId, identity.subject, taskId, {
|
||||
status: task.status,
|
||||
buildLogs,
|
||||
buildStatus: "building",
|
||||
})
|
||||
.catch(() => undefined);
|
||||
});
|
||||
if (result.exitCode !== 0) {
|
||||
@@ -207,9 +215,10 @@ export class AdminMiniAppReleaseController {
|
||||
stream: "stderr",
|
||||
});
|
||||
await this.releases.updateStatus(identity.brandId, identity.subject, taskId, {
|
||||
status: "build_failed",
|
||||
status: task.status,
|
||||
error: `小程序构建失败,请查看构建日志`,
|
||||
buildLogs,
|
||||
buildStatus: "failed",
|
||||
});
|
||||
throw new BadRequestException("小程序构建失败,请查看构建日志");
|
||||
}
|
||||
@@ -220,9 +229,10 @@ export class AdminMiniAppReleaseController {
|
||||
stream: "stderr",
|
||||
});
|
||||
await this.releases.updateStatus(identity.brandId, identity.subject, taskId, {
|
||||
status: "build_failed",
|
||||
status: task.status,
|
||||
error: "小程序构建产物缺少 app.json",
|
||||
buildLogs,
|
||||
buildStatus: "failed",
|
||||
});
|
||||
throw new BadRequestException("小程序构建产物缺少 app.json");
|
||||
}
|
||||
@@ -232,8 +242,9 @@ export class AdminMiniAppReleaseController {
|
||||
stream: "stdout",
|
||||
});
|
||||
await this.releases.updateStatus(identity.brandId, identity.subject, taskId, {
|
||||
status: "built",
|
||||
status: task.status,
|
||||
buildLogs,
|
||||
buildStatus: "success",
|
||||
});
|
||||
const ci = (await import("miniprogram-ci")) as unknown as MiniprogramCi;
|
||||
const project = new ci.Project({
|
||||
@@ -253,6 +264,7 @@ export class AdminMiniAppReleaseController {
|
||||
return this.releases.updateStatus(identity.brandId, identity.subject, taskId, {
|
||||
status: "uploaded",
|
||||
buildLogs,
|
||||
buildStatus: "success",
|
||||
weappUploadId:
|
||||
typeof uploadResult.strUint64Version === "string"
|
||||
? uploadResult.strUint64Version
|
||||
@@ -262,6 +274,7 @@ export class AdminMiniAppReleaseController {
|
||||
await this.releases.updateStatus(identity.brandId, identity.subject, taskId, {
|
||||
status: "failed",
|
||||
buildLogs,
|
||||
buildStatus: "failed",
|
||||
error: error instanceof Error ? error.message : "微信代码上传失败",
|
||||
});
|
||||
throw error;
|
||||
|
||||
Reference in new issue
Block a user