完善
This commit is contained in:
parent
0507fadfda
commit
04cfab1160
@ -1,7 +1,7 @@
|
|||||||
import express from "express";
|
import express from "express";
|
||||||
import u from "@/utils";
|
import u from "@/utils";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import { success } from "@/lib/responseFormat";
|
import { error, success } from "@/lib/responseFormat";
|
||||||
import { validateFields } from "@/middleware/middleware";
|
import { validateFields } from "@/middleware/middleware";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
@ -27,31 +27,35 @@ export default router.post(
|
|||||||
}),
|
}),
|
||||||
async (req, res) => {
|
async (req, res) => {
|
||||||
const { model, references = [], quality, ratio, prompt, projectId } = req.body;
|
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(
|
const url = await u.oss.getFileUrl(savePath);
|
||||||
{
|
return res.status(200).send(success({ url }));
|
||||||
prompt: prompt,
|
} catch (e) {
|
||||||
referenceList: await (async () => {
|
res.status(400).send(error(u.error(e).message))
|
||||||
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 }));
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|||||||
@ -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 的旧关联,再插入新的
|
// 先删除本批 scriptId 的旧关联,再插入新的
|
||||||
await u.db("o_scriptAssets").whereIn("scriptId", batchScriptIds).delete();
|
await u.db("o_scriptAssets").whereIn("scriptId", batchScriptIds).delete();
|
||||||
if (scriptAssetRows.length) {
|
if (uniqueRows.length) {
|
||||||
await u.db("o_scriptAssets").insert(scriptAssetRows);
|
await u.db("o_scriptAssets").insert(uniqueRows);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 本批成功的剧本状态更新为 1(成功)
|
// 本批成功的剧本状态更新为 1(成功)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user