From 04cfab11607893eaaaa3bdcb4c7f7ce5e4f9f382 Mon Sep 17 00:00:00 2001 From: zhishi <1951671751@qq.com> Date: Wed, 15 Apr 2026 15:20:05 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../production/editImage/generateFlowImage.ts | 54 ++++++++++--------- src/routes/script/extractAssets.ts | 10 +++- 2 files changed, 37 insertions(+), 27 deletions(-) diff --git a/src/routes/production/editImage/generateFlowImage.ts b/src/routes/production/editImage/generateFlowImage.ts index d20511c..e62affc 100644 --- a/src/routes/production/editImage/generateFlowImage.ts +++ b/src/routes/production/editImage/generateFlowImage.ts @@ -1,7 +1,7 @@ import express from "express"; import u from "@/utils"; import { z } from "zod"; -import { success } from "@/lib/responseFormat"; +import { error, success } from "@/lib/responseFormat"; import { validateFields } from "@/middleware/middleware"; import axios from "axios"; const router = express.Router(); @@ -27,31 +27,35 @@ export default router.post( }), async (req, res) => { const { model, references = [], quality, ratio, prompt, projectId } = req.body; + try { + const imageClass = await u.Ai.Image(model).run( + { + prompt: prompt, + referenceList: await (async () => { + const list: { type: "image"; base64: string }[] = []; + for (const url of references) { + list.push({ type: "image" as const, base64: await urlToBase64(url) }); + } + return list; + })(), + size: quality, + aspectRatio: ratio, + }, + { + taskClass: "工作流图片生成", + describe: "工作流图片生成", + relatedObjects: JSON.stringify(req.body), + projectId: projectId, + }, + ); + const savePath = `${projectId}/workFlow/${u.uuid()}.jpg`; + await imageClass.save(savePath); - const imageClass = await u.Ai.Image(model).run( - { - prompt: prompt, - referenceList: await (async () => { - const list: { type: "image"; base64: string }[] = []; - for (const url of references) { - list.push({ type: "image" as const, base64: await urlToBase64(url) }); - } - return list; - })(), - size: quality, - aspectRatio: ratio, - }, - { - taskClass: "工作流图片生成", - describe: "工作流图片生成", - relatedObjects: JSON.stringify(req.body), - projectId: projectId, - }, - ); - const savePath = `${projectId}/workFlow/${u.uuid()}.jpg`; - await imageClass.save(savePath); + const url = await u.oss.getFileUrl(savePath); + return res.status(200).send(success({ url })); + } catch (e) { + res.status(400).send(error(u.error(e).message)) + } - const url = await u.oss.getFileUrl(savePath); - return res.status(200).send(success({ url })); }, ); diff --git a/src/routes/script/extractAssets.ts b/src/routes/script/extractAssets.ts index 30b35dc..e72cdc9 100644 --- a/src/routes/script/extractAssets.ts +++ b/src/routes/script/extractAssets.ts @@ -130,10 +130,16 @@ export default router.post( } } + // 去重:相同 scriptId + assetId 只保留一条 + const uniqueRows = [ + ...new Map(scriptAssetRows.map((r) => [`${r.scriptId}_${r.assetId}`, r])).values(), + ]; + console.log("%c Line:135 🥝 uniqueRows", "background:#7f2b82", uniqueRows); + // 先删除本批 scriptId 的旧关联,再插入新的 await u.db("o_scriptAssets").whereIn("scriptId", batchScriptIds).delete(); - if (scriptAssetRows.length) { - await u.db("o_scriptAssets").insert(scriptAssetRows); + if (uniqueRows.length) { + await u.db("o_scriptAssets").insert(uniqueRows); } // 本批成功的剧本状态更新为 1(成功)