diff --git a/package.json b/package.json index d66281c..ce63f5f 100644 --- a/package.json +++ b/package.json @@ -55,6 +55,7 @@ "express-ws": "^5.0.2", "fast-glob": "^3.3.3", "form-data": "^4.0.5", + "graphlib": "^2.1.8", "is-path-inside": "^4.0.0", "js-md5": "^0.8.3", "jsonwebtoken": "^9.0.3", diff --git a/src/lib/initDB.ts b/src/lib/initDB.ts index bd43e3e..de19a0e 100644 --- a/src/lib/initDB.ts +++ b/src/lib/initDB.ts @@ -307,7 +307,12 @@ export default async (knex: Knex, forceInit: boolean = false): Promise => name: "o_storyboard", builder: (table) => { table.integer("id").notNullable(); - table.string("name"); + table.text("name"); + table.text("detail"); + table.text("prompt"); + table.text("seconds"); + table.text("filePath"); + table.text("frameType"); table.integer("createTime"); table.primary(["id"]); table.unique(["id"]); @@ -414,6 +419,17 @@ export default async (knex: Knex, forceInit: boolean = false): Promise => table.index(["isolationKey", "summarized"]); }, }, + //分镜工作流表 + { + name: "o_storyboardFlow", + builder: (table) => { + table.integer("id").notNullable(); + table.text("flowData").notNullable(); + table.integer("stroryboardId").notNullable(); + table.primary(["id"]); + table.unique(["id"]); + }, + }, ]; for (const t of tables) { diff --git a/src/routes/production/editStoryboard/generateStoryboardImage.ts b/src/routes/production/editStoryboard/generateStoryboardImage.ts new file mode 100644 index 0000000..31d4db0 --- /dev/null +++ b/src/routes/production/editStoryboard/generateStoryboardImage.ts @@ -0,0 +1,41 @@ +import express from "express"; +import u from "@/utils"; +import { z } from "zod"; +import { success } from "@/lib/responseFormat"; +import { validateFields } from "@/middleware/middleware"; +const router = express.Router(); + +export default router.post( + "/", + validateFields({ + model: z.string(), + references: z.array(z.string()).optional(), + quality: z.string(), + ratio: z.string(), + prompt: z.string(), + projectId: z.number(), + }), + async (req, res) => { + const { model, references = [], quality, ratio, prompt, projectId } = req.body; + const imageClass = await u.Ai.Image(model).run({ + prompt: prompt, + imageBase64: references, + size: quality, + aspectRatio: ratio, + taskClass: "分镜生成", + describe: "生成分镜图片", + relatedObjects: JSON.stringify(req.body), + projectId: projectId, + }); + const savePath = `${projectId}/storyboard/${u.uuid()}.jpg`; + await imageClass.save(savePath); + + const url = await u.oss.getFileUrl(savePath); + const [imageId] = await u.db("o_image").insert({ + filePath: savePath, + state: "1", + type: "storyFlow", + }); + return res.status(200).send(success({ imageId, url })); + }, +); diff --git a/src/routes/production/editStoryboard/getStoryboardFlow.ts b/src/routes/production/editStoryboard/getStoryboardFlow.ts new file mode 100644 index 0000000..499aee7 --- /dev/null +++ b/src/routes/production/editStoryboard/getStoryboardFlow.ts @@ -0,0 +1,27 @@ +import express from "express"; +import u from "@/utils"; +import { z } from "zod"; +import { success } from "@/lib/responseFormat"; +import { validateFields } from "@/middleware/middleware"; +const router = express.Router(); + +export default router.post( + "/", + validateFields({ + id: z.number(), + }), + async (req, res) => { + const { id } = req.body; + console.log("%c Line:15 🥤 id", "background:#e41a6a", id); + const storyboardFlowData = await u.db("o_storyboardFlow").where("stroryboardId", id).first(); + if (storyboardFlowData?.flowData) { + return res.status(200).send(success(JSON.parse(storyboardFlowData?.flowData))); + } + return res.status(200).send( + success({ + nodes: [], + edges: [], + }), + ); + }, +); diff --git a/src/routes/production/editStoryboard/saveStoryboardFlow.ts b/src/routes/production/editStoryboard/saveStoryboardFlow.ts new file mode 100644 index 0000000..920bd48 --- /dev/null +++ b/src/routes/production/editStoryboard/saveStoryboardFlow.ts @@ -0,0 +1,28 @@ +import express from "express"; +import u from "@/utils"; +import { z } from "zod"; +import { success } from "@/lib/responseFormat"; +import { validateFields } from "@/middleware/middleware"; +const router = express.Router(); + +export default router.post( + "/", + validateFields({ + edges: z.any(), + nodes: z.any(), + imageId: z.number(), + }), + async (req, res) => { + const { edges, nodes, imageId } = req.body; + // if + const [id] = await u.db("o_storyboad").insert({ + imageId, + }); + await u.db("o_storyboardFlow").insert({ + id: 1, + stroryboardId: id, + flowData: JSON.stringify({ edges, nodes }), + }); + return res.status(200).send(success()); + }, +); diff --git a/src/routes/production/editStoryboard/updateStoryboardFlow.ts b/src/routes/production/editStoryboard/updateStoryboardFlow.ts new file mode 100644 index 0000000..0174a25 --- /dev/null +++ b/src/routes/production/editStoryboard/updateStoryboardFlow.ts @@ -0,0 +1,28 @@ +import express from "express"; +import u from "@/utils"; +import { z } from "zod"; +import { success } from "@/lib/responseFormat"; +import { validateFields } from "@/middleware/middleware"; +const router = express.Router(); + +export default router.post( + "/", + validateFields({ + edges: z.any(), + nodes: z.any(), + id: z.number(), + imageId: z.number(), + }), + async (req, res) => { + const { edges, nodes, id, imageId } = req.body; + // if + await u.db("o_storyboard").where("id", id).update({ imageId }); + await u + .db("o_storyboardFlow") + .where("stroryboardId", id) + .update({ + flowData: JSON.stringify({ edges, nodes }), + }); + return res.status(200).send(success()); + }, +); diff --git a/yarn.lock b/yarn.lock index 9c6f5a4..320488e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2520,6 +2520,13 @@ graceful-fs@^4.1.2, graceful-fs@^4.1.6, graceful-fs@^4.2.0, graceful-fs@^4.2.11, resolved "https://registry.npmmirror.com/graceful-fs/-/graceful-fs-4.2.11.tgz#4183e4e8bf08bb6e05bbb2f7d2e0c8f712ca40e3" integrity sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ== +graphlib@^2.1.8: + version "2.1.8" + resolved "https://registry.npmmirror.com/graphlib/-/graphlib-2.1.8.tgz#5761d414737870084c92ec7b5dbcb0592c9d35da" + integrity sha512-jcLLfkpoVGmH7/InMC/1hIvOPSUh38oJtGhvrOFGzioE1DZ+0YW16RgmOJhHiuWTvGiJQ9Z1Ik43JvkRPRvE+A== + dependencies: + lodash "^4.17.15" + guid-typescript@^1.0.9: version "1.0.9" resolved "https://registry.npmmirror.com/guid-typescript/-/guid-typescript-1.0.9.tgz#e35f77003535b0297ea08548f5ace6adb1480ddc"