fix: 修复后端竞态/安全/数据处理问题并移除冗余 outImage 列

首次激活改条件更新消除并发竞态;备份恢复补模型全集与版本校验防清库;
审核列表分页总数、操作日志未捕获 Promise、出库导入重复码、加密密钥可编辑、
溯源码盐以 env 为准、证书按 originKey reconcile、env 加载去重等修复;
新增 parseBigId 防非法入参 500、全局安全响应头、去除 SVG 上传、接入 throttler 限流、
入队失败补偿、hashData 稳定序列化、无效码负缓存、看板已激活口径调整;
移除冗余 TraceCode.outImage 列统一 outImages(迁移 drop_trace_code_out_image)。
This commit is contained in:
Nixevol
2026-07-09 13:14:26 +08:00
parent c39974e72d
commit f712b16c1f
29 changed files with 328 additions and 170 deletions
+32 -15
View File
@@ -326,7 +326,11 @@ export class ArtworkService {
}
async auditList(query: QueryArtworkRevisionDto) {
const where: Prisma.ArtworkRevisionWhereInput = {};
// 把作品维度的过滤(未删除、非草稿)下推到 where.artwork,
// 使 count 与 findMany 用同一条件,避免分页总数虚高、末页出现空行
const where: Prisma.ArtworkRevisionWhereInput = {
artwork: { deletedAt: null, status: { not: ArtworkStatus.DRAFT } },
};
if (query.status) where.status = query.status;
else where.status = ArtworkRevisionStatus.PENDING;
if (query.keyword) {
@@ -359,7 +363,6 @@ export class ArtworkService {
this.prisma.artworkRevision.count({ where }),
]);
const list = rows
.filter((r) => !r.artwork.deletedAt && r.artwork.status !== ArtworkStatus.DRAFT)
.map((r) => {
const after = this.snapshotWithUrls(r.afterSnapshot) as ArtworkSnapshot & {
artwork?: { images?: Array<MediaItem & { url: string }> };
@@ -680,19 +683,33 @@ export class ArtworkService {
})),
});
}
await tx.certificate.deleteMany({ where: { artworkId: id } });
if (snapshot.certificates.length) {
await tx.certificate.createMany({
data: snapshot.certificates.map((cert) => ({
artworkId: id,
name: cert.name,
issuer: cert.issuer,
issuedAt: cert.issuedAt ? new Date(cert.issuedAt) : null,
type: cert.type as any,
originFileUrl: cert.originKey,
watermarkFileUrl: cert.watermarkKey ?? null,
})),
});
// 证书按 originFileUrl(originKey) reconcile,而非全删重建:
// 未变的原件保留原证书 id 与已生成的 watermarkFileUrl,避免 ID 漂移和重复水印任务;
// 只删除快照中不再存在的证书、更新元数据、新增缺失证书。
const existingCerts = await tx.certificate.findMany({ where: { artworkId: id } });
const snapshotOriginKeys = new Set(snapshot.certificates.map((c) => c.originKey));
const staleIds = existingCerts.filter((c) => !snapshotOriginKeys.has(c.originFileUrl)).map((c) => c.id);
if (staleIds.length) await tx.certificate.deleteMany({ where: { id: { in: staleIds } } });
const byOrigin = new Map(existingCerts.map((c) => [c.originFileUrl, c]));
for (const cert of snapshot.certificates) {
const prev = byOrigin.get(cert.originKey);
const data = {
name: cert.name,
issuer: cert.issuer,
issuedAt: cert.issuedAt ? new Date(cert.issuedAt) : null,
type: cert.type as any,
};
if (prev) {
// 原件不变:保留 id 与 watermarkFileUrl(快照带则以快照为准,否则沿用已生成的)
await tx.certificate.update({
where: { id: prev.id },
data: { ...data, watermarkFileUrl: cert.watermarkKey ?? prev.watermarkFileUrl },
});
} else {
await tx.certificate.create({
data: { ...data, artworkId: id, originFileUrl: cert.originKey, watermarkFileUrl: cert.watermarkKey ?? null },
});
}
}
}