This commit is contained in:
zhishi 2026-04-15 15:20:05 +08:00
parent 0507fadfda
commit 04cfab1160
2 changed files with 37 additions and 27 deletions

View File

@ -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 }));
},
);

View File

@ -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成功