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;
|
||||
|
||||
@@ -8,27 +8,8 @@ export class CreateMiniAppReleaseDto {
|
||||
}
|
||||
|
||||
export class UpdateMiniAppReleaseStatusDto {
|
||||
@IsIn([
|
||||
"uploaded",
|
||||
"under_review",
|
||||
"approved",
|
||||
"rejected",
|
||||
"failed",
|
||||
"built",
|
||||
"building",
|
||||
"build_failed",
|
||||
"published",
|
||||
])
|
||||
status!:
|
||||
| "uploaded"
|
||||
| "under_review"
|
||||
| "approved"
|
||||
| "rejected"
|
||||
| "failed"
|
||||
| "built"
|
||||
| "building"
|
||||
| "build_failed"
|
||||
| "published";
|
||||
@IsIn(["uploaded", "under_review", "approved", "rejected", "failed", "built", "published"])
|
||||
status!: "uploaded" | "under_review" | "approved" | "rejected" | "failed" | "built" | "published";
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
|
||||
@@ -9,8 +9,6 @@ import { PrismaService } from "../../prisma.service.js";
|
||||
|
||||
const transitions: Record<string, string[]> = {
|
||||
built: ["uploaded", "under_review", "failed"],
|
||||
building: ["built", "build_failed"],
|
||||
build_failed: ["built"],
|
||||
uploaded: ["under_review", "failed"],
|
||||
under_review: ["approved", "rejected", "failed"],
|
||||
approved: ["published", "failed"],
|
||||
@@ -66,15 +64,8 @@ export class AdminMiniAppReleaseService {
|
||||
taskId: string,
|
||||
input: {
|
||||
status:
|
||||
| "uploaded"
|
||||
| "under_review"
|
||||
| "approved"
|
||||
| "rejected"
|
||||
| "failed"
|
||||
| "built"
|
||||
| "building"
|
||||
| "build_failed"
|
||||
| "published";
|
||||
"uploaded" | "under_review" | "approved" | "rejected" | "failed" | "built" | "published";
|
||||
buildStatus?: "building" | "success" | "failed";
|
||||
error?: string;
|
||||
weappUploadId?: string;
|
||||
buildLogs?: unknown;
|
||||
@@ -103,6 +94,7 @@ export class AdminMiniAppReleaseService {
|
||||
...(input.buildLogs !== undefined
|
||||
? { buildLogs: input.buildLogs as Prisma.InputJsonValue }
|
||||
: {}),
|
||||
...(input.buildStatus ? { buildStatus: input.buildStatus } : {}),
|
||||
audit,
|
||||
},
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user