Merge branch '108' of https://github.com/HBAI-Ltd/Toonflow-app into 108
# Conflicts: # src/router.ts
This commit is contained in:
commit
db4b86dacd
@ -55,6 +55,7 @@
|
|||||||
"express-ws": "^5.0.2",
|
"express-ws": "^5.0.2",
|
||||||
"fast-glob": "^3.3.3",
|
"fast-glob": "^3.3.3",
|
||||||
"form-data": "^4.0.5",
|
"form-data": "^4.0.5",
|
||||||
|
"graphlib": "^2.1.8",
|
||||||
"is-path-inside": "^4.0.0",
|
"is-path-inside": "^4.0.0",
|
||||||
"js-md5": "^0.8.3",
|
"js-md5": "^0.8.3",
|
||||||
"jsonwebtoken": "^9.0.3",
|
"jsonwebtoken": "^9.0.3",
|
||||||
|
|||||||
@ -276,7 +276,7 @@ export default async (knex: Knex, forceInit: boolean = false): Promise<void> =>
|
|||||||
table.text("remark");
|
table.text("remark");
|
||||||
table.text("type");
|
table.text("type");
|
||||||
table.text("describe");
|
table.text("describe");
|
||||||
table.integer("scriptId");//剧本id
|
table.integer("scriptId"); //剧本id
|
||||||
table.integer("imageId").unsigned().references("id").inTable("o_image");
|
table.integer("imageId").unsigned().references("id").inTable("o_image");
|
||||||
table.integer("sonId");
|
table.integer("sonId");
|
||||||
table.integer("projectId");
|
table.integer("projectId");
|
||||||
@ -307,7 +307,12 @@ export default async (knex: Knex, forceInit: boolean = false): Promise<void> =>
|
|||||||
name: "o_storyboard",
|
name: "o_storyboard",
|
||||||
builder: (table) => {
|
builder: (table) => {
|
||||||
table.integer("id").notNullable();
|
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.integer("createTime");
|
||||||
table.primary(["id"]);
|
table.primary(["id"]);
|
||||||
table.unique(["id"]);
|
table.unique(["id"]);
|
||||||
@ -332,14 +337,13 @@ export default async (knex: Knex, forceInit: boolean = false): Promise<void> =>
|
|||||||
table.text("resolution");
|
table.text("resolution");
|
||||||
table.text("prompt");
|
table.text("prompt");
|
||||||
table.text("filePath");
|
table.text("filePath");
|
||||||
table.text("firstFrame");
|
|
||||||
table.text("storyboardImgs");
|
|
||||||
table.text("model");
|
table.text("model");
|
||||||
|
table.text("mode");
|
||||||
table.text("errorReason");
|
table.text("errorReason");
|
||||||
table.integer("time");
|
table.integer("time");
|
||||||
table.integer("state");
|
table.text("state");
|
||||||
table.integer("scriptId");
|
table.integer("scriptId");
|
||||||
table.integer("configId"); // 关联的视频配置ID
|
table.integer("storyboardId");
|
||||||
table.primary(["id"]);
|
table.primary(["id"]);
|
||||||
table.unique(["id"]);
|
table.unique(["id"]);
|
||||||
},
|
},
|
||||||
@ -349,19 +353,14 @@ export default async (knex: Knex, forceInit: boolean = false): Promise<void> =>
|
|||||||
name: "o_videoConfig",
|
name: "o_videoConfig",
|
||||||
builder: (table) => {
|
builder: (table) => {
|
||||||
table.integer("id").notNullable();
|
table.integer("id").notNullable();
|
||||||
table.integer("scriptId"); // 关联的脚本ID
|
table.integer("videoId"); //视频Id
|
||||||
table.integer("projectId"); // 关联的项目ID
|
table.integer("audio"); //声音
|
||||||
table.integer("aiConfigId"); //ai配置ID
|
table.text("model"); //模型
|
||||||
table.integer("audioEnabled"); //声音
|
|
||||||
table.text("manufacturer"); // 厂商:volcengine/runninghub/openAi
|
|
||||||
table.text("mode"); // 模式:startEnd/multi/single
|
table.text("mode"); // 模式:startEnd/multi/single
|
||||||
table.text("startFrame"); // 首帧图片信息 JSON
|
table.text("data"); // 所选数据集图片 JSON
|
||||||
table.text("endFrame"); // 尾帧图片信息 JSON
|
|
||||||
table.text("images"); // 多图模式的图片列表 JSON
|
|
||||||
table.text("resolution"); // 分辨率
|
table.text("resolution"); // 分辨率
|
||||||
table.integer("duration"); // 时长
|
table.integer("duration"); // 时长
|
||||||
table.text("prompt"); // 提示词
|
table.text("prompt"); // 提示词
|
||||||
table.integer("selectedResultId"); // 选中的生成结果ID
|
|
||||||
table.integer("createTime"); // 创建时间
|
table.integer("createTime"); // 创建时间
|
||||||
table.integer("updateTime"); // 更新时间
|
table.integer("updateTime"); // 更新时间
|
||||||
table.primary(["id"]);
|
table.primary(["id"]);
|
||||||
@ -420,6 +419,17 @@ export default async (knex: Knex, forceInit: boolean = false): Promise<void> =>
|
|||||||
table.index(["isolationKey", "summarized"]);
|
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) {
|
for (const t of tables) {
|
||||||
|
|||||||
112
src/router.ts
112
src/router.ts
@ -1,4 +1,4 @@
|
|||||||
// @routes-hash eb87a13a06fbdb3ce3e25bcea6173c31
|
// @routes-hash beeb358ee056d0414c7a2ca88bc9b566
|
||||||
import { Express } from "express";
|
import { Express } from "express";
|
||||||
|
|
||||||
import route1 from "./routes/agents/clearMemory";
|
import route1 from "./routes/agents/clearMemory";
|
||||||
@ -35,33 +35,34 @@ import route31 from "./routes/novel/updateNovel";
|
|||||||
import route32 from "./routes/other/deleteAllData";
|
import route32 from "./routes/other/deleteAllData";
|
||||||
import route33 from "./routes/other/getCaptcha";
|
import route33 from "./routes/other/getCaptcha";
|
||||||
import route34 from "./routes/production/getProductionData";
|
import route34 from "./routes/production/getProductionData";
|
||||||
import route35 from "./routes/production/workbench/getVideoModelDetail";
|
import route35 from "./routes/production/workbench/generateVideo";
|
||||||
import route36 from "./routes/project/addProject";
|
import route36 from "./routes/production/workbench/getVideoModelDetail";
|
||||||
import route37 from "./routes/project/delProject";
|
import route37 from "./routes/project/addProject";
|
||||||
import route38 from "./routes/project/editProject";
|
import route38 from "./routes/project/delProject";
|
||||||
import route39 from "./routes/project/getProject";
|
import route39 from "./routes/project/editProject";
|
||||||
import route40 from "./routes/script/addScript";
|
import route40 from "./routes/project/getProject";
|
||||||
import route41 from "./routes/script/delScript";
|
import route41 from "./routes/script/addScript";
|
||||||
import route42 from "./routes/script/getScrptApi";
|
import route42 from "./routes/script/delScript";
|
||||||
import route43 from "./routes/script/updateScript";
|
import route43 from "./routes/script/getScrptApi";
|
||||||
import route44 from "./routes/setting/agentDeploy/deployAgentModel";
|
import route44 from "./routes/script/updateScript";
|
||||||
import route45 from "./routes/setting/agentDeploy/getAgentDeploy";
|
import route45 from "./routes/setting/agentDeploy/deployAgentModel";
|
||||||
import route46 from "./routes/setting/agentDeploy/updateKey";
|
import route46 from "./routes/setting/agentDeploy/getAgentDeploy";
|
||||||
import route47 from "./routes/setting/dbConfig/clearData";
|
import route47 from "./routes/setting/agentDeploy/updateKey";
|
||||||
import route48 from "./routes/setting/getTextModel";
|
import route48 from "./routes/setting/dbConfig/clearData";
|
||||||
import route49 from "./routes/setting/loginConfig/getUser";
|
import route49 from "./routes/setting/getTextModel";
|
||||||
import route50 from "./routes/setting/loginConfig/updateUserPwd";
|
import route50 from "./routes/setting/loginConfig/getUser";
|
||||||
import route51 from "./routes/setting/memoryConfig/getMemory";
|
import route51 from "./routes/setting/loginConfig/updateUserPwd";
|
||||||
import route52 from "./routes/setting/memoryConfig/sureMemory";
|
import route52 from "./routes/setting/memoryConfig/getMemory";
|
||||||
import route53 from "./routes/setting/vendorConfig/addVendor";
|
import route53 from "./routes/setting/memoryConfig/sureMemory";
|
||||||
import route54 from "./routes/setting/vendorConfig/deleteVendor";
|
import route54 from "./routes/setting/vendorConfig/addVendor";
|
||||||
import route55 from "./routes/setting/vendorConfig/getVendorList";
|
import route55 from "./routes/setting/vendorConfig/deleteVendor";
|
||||||
import route56 from "./routes/setting/vendorConfig/modelTest";
|
import route56 from "./routes/setting/vendorConfig/getVendorList";
|
||||||
import route57 from "./routes/setting/vendorConfig/updateVendor";
|
import route57 from "./routes/setting/vendorConfig/modelTest";
|
||||||
import route58 from "./routes/task/getMyTaskApi";
|
import route58 from "./routes/setting/vendorConfig/updateVendor";
|
||||||
import route59 from "./routes/task/getTaskCategories";
|
import route59 from "./routes/task/getMyTaskApi";
|
||||||
import route60 from "./routes/task/taskDetails";
|
import route60 from "./routes/task/getTaskCategories";
|
||||||
import route61 from "./routes/test/test";
|
import route61 from "./routes/task/taskDetails";
|
||||||
|
import route62 from "./routes/test/test";
|
||||||
|
|
||||||
export default async (app: Express) => {
|
export default async (app: Express) => {
|
||||||
app.use("/api/agents/clearMemory", route1);
|
app.use("/api/agents/clearMemory", route1);
|
||||||
@ -98,31 +99,32 @@ export default async (app: Express) => {
|
|||||||
app.use("/api/other/deleteAllData", route32);
|
app.use("/api/other/deleteAllData", route32);
|
||||||
app.use("/api/other/getCaptcha", route33);
|
app.use("/api/other/getCaptcha", route33);
|
||||||
app.use("/api/production/getProductionData", route34);
|
app.use("/api/production/getProductionData", route34);
|
||||||
app.use("/api/production/workbench/getVideoModelDetail", route35);
|
app.use("/api/production/workbench/generateVideo", route35);
|
||||||
app.use("/api/project/addProject", route36);
|
app.use("/api/production/workbench/getVideoModelDetail", route36);
|
||||||
app.use("/api/project/delProject", route37);
|
app.use("/api/project/addProject", route37);
|
||||||
app.use("/api/project/editProject", route38);
|
app.use("/api/project/delProject", route38);
|
||||||
app.use("/api/project/getProject", route39);
|
app.use("/api/project/editProject", route39);
|
||||||
app.use("/api/script/addScript", route40);
|
app.use("/api/project/getProject", route40);
|
||||||
app.use("/api/script/delScript", route41);
|
app.use("/api/script/addScript", route41);
|
||||||
app.use("/api/script/getScrptApi", route42);
|
app.use("/api/script/delScript", route42);
|
||||||
app.use("/api/script/updateScript", route43);
|
app.use("/api/script/getScrptApi", route43);
|
||||||
app.use("/api/setting/agentDeploy/deployAgentModel", route44);
|
app.use("/api/script/updateScript", route44);
|
||||||
app.use("/api/setting/agentDeploy/getAgentDeploy", route45);
|
app.use("/api/setting/agentDeploy/deployAgentModel", route45);
|
||||||
app.use("/api/setting/agentDeploy/updateKey", route46);
|
app.use("/api/setting/agentDeploy/getAgentDeploy", route46);
|
||||||
app.use("/api/setting/dbConfig/clearData", route47);
|
app.use("/api/setting/agentDeploy/updateKey", route47);
|
||||||
app.use("/api/setting/getTextModel", route48);
|
app.use("/api/setting/dbConfig/clearData", route48);
|
||||||
app.use("/api/setting/loginConfig/getUser", route49);
|
app.use("/api/setting/getTextModel", route49);
|
||||||
app.use("/api/setting/loginConfig/updateUserPwd", route50);
|
app.use("/api/setting/loginConfig/getUser", route50);
|
||||||
app.use("/api/setting/memoryConfig/getMemory", route51);
|
app.use("/api/setting/loginConfig/updateUserPwd", route51);
|
||||||
app.use("/api/setting/memoryConfig/sureMemory", route52);
|
app.use("/api/setting/memoryConfig/getMemory", route52);
|
||||||
app.use("/api/setting/vendorConfig/addVendor", route53);
|
app.use("/api/setting/memoryConfig/sureMemory", route53);
|
||||||
app.use("/api/setting/vendorConfig/deleteVendor", route54);
|
app.use("/api/setting/vendorConfig/addVendor", route54);
|
||||||
app.use("/api/setting/vendorConfig/getVendorList", route55);
|
app.use("/api/setting/vendorConfig/deleteVendor", route55);
|
||||||
app.use("/api/setting/vendorConfig/modelTest", route56);
|
app.use("/api/setting/vendorConfig/getVendorList", route56);
|
||||||
app.use("/api/setting/vendorConfig/updateVendor", route57);
|
app.use("/api/setting/vendorConfig/modelTest", route57);
|
||||||
app.use("/api/task/getMyTaskApi", route58);
|
app.use("/api/setting/vendorConfig/updateVendor", route58);
|
||||||
app.use("/api/task/getTaskCategories", route59);
|
app.use("/api/task/getMyTaskApi", route59);
|
||||||
app.use("/api/task/taskDetails", route60);
|
app.use("/api/task/getTaskCategories", route60);
|
||||||
app.use("/api/test/test", route61);
|
app.use("/api/task/taskDetails", route61);
|
||||||
|
app.use("/api/test/test", route62);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,34 +6,38 @@ import { validateFields } from "@/middleware/middleware";
|
|||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
|
|
||||||
export default router.post(
|
export default router.post(
|
||||||
"/",
|
"/",
|
||||||
validateFields({
|
validateFields({
|
||||||
type: z.enum(["text", "image", "video", "all"]),
|
type: z.enum(["text", "image", "video", "all"]),
|
||||||
}),
|
}),
|
||||||
async (req, res) => {
|
async (req, res) => {
|
||||||
const { type } = req.body;
|
const { type } = req.body;
|
||||||
const data = await u.db("o_vendorConfig").select("id", "models", "name").first();
|
const data = await u.db("o_vendorConfig").select("id", "models", "name").first();
|
||||||
if (!data) {
|
if (!data) {
|
||||||
return res.status(404).send({ error: "模型未找到" });
|
return res.status(404).send({ error: "模型未找到" });
|
||||||
}
|
|
||||||
const models = JSON.parse(data.models!);
|
|
||||||
if (type === "all") {
|
|
||||||
const allData = models.filter((item: { type: string }) => item.type !== "video").map((item: { name: string; modelName: string; type: string }) => ({
|
|
||||||
id: data.id,
|
|
||||||
label: item.name,
|
|
||||||
value: item.modelName,
|
|
||||||
type: item.type,
|
|
||||||
name: data.name,
|
|
||||||
}));
|
|
||||||
return res.status(200).send(success(allData));
|
|
||||||
}
|
|
||||||
const filteredData = models.filter((item: { type: string }) => item.type === type).map((item: { name: string; modelName: string; type: string }) => ({
|
|
||||||
id: data.id,
|
|
||||||
label: item.name,
|
|
||||||
value: item.modelName,
|
|
||||||
type: item.type,
|
|
||||||
name: data.name,
|
|
||||||
}));
|
|
||||||
res.status(200).send(success(filteredData));
|
|
||||||
}
|
}
|
||||||
|
const models = JSON.parse(data.models!);
|
||||||
|
if (type === "all") {
|
||||||
|
const allData = models
|
||||||
|
.filter((item: { type: string }) => item.type !== "video")
|
||||||
|
.map((item: { name: string; modelName: string; type: string }) => ({
|
||||||
|
id: data.id,
|
||||||
|
label: item.name,
|
||||||
|
value: item.modelName,
|
||||||
|
type: item.type,
|
||||||
|
name: data.name,
|
||||||
|
}));
|
||||||
|
return res.status(200).send(success(allData));
|
||||||
|
}
|
||||||
|
const filteredData = models
|
||||||
|
.filter((item: { type: string }) => item.type === type)
|
||||||
|
.map((item: { name: string; modelName: string; type: string }) => ({
|
||||||
|
id: data.id,
|
||||||
|
label: item.name,
|
||||||
|
value: item.modelName,
|
||||||
|
type: item.type,
|
||||||
|
name: data.name,
|
||||||
|
}));
|
||||||
|
res.status(200).send(success(filteredData));
|
||||||
|
},
|
||||||
);
|
);
|
||||||
|
|||||||
106
src/routes/production/editStoryboard/generateStoryboardImage.ts
Normal file
106
src/routes/production/editStoryboard/generateStoryboardImage.ts
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
import express from "express";
|
||||||
|
import u from "@/utils";
|
||||||
|
import { z } from "zod";
|
||||||
|
import { success } from "@/lib/responseFormat";
|
||||||
|
import { validateFields } from "@/middleware/middleware";
|
||||||
|
import axios from "axios";
|
||||||
|
const router = express.Router();
|
||||||
|
async function getImageBase64ForId(imageId: string | number) {
|
||||||
|
const imagePath = await u
|
||||||
|
.db("o_image")
|
||||||
|
.select("filePath")
|
||||||
|
.where({ id: Number(imageId) })
|
||||||
|
.first();
|
||||||
|
|
||||||
|
if (!imagePath || !imagePath.filePath) return ""; // 未找到图片路径
|
||||||
|
const url = await u.oss.getFileUrl(imagePath.filePath);
|
||||||
|
return await urlToBase64(url);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function urlToBase64(imageUrl: string): Promise<string> {
|
||||||
|
const response = await axios.get(imageUrl, { responseType: "arraybuffer" });
|
||||||
|
const contentType = response.headers["content-type"] || "image/png";
|
||||||
|
const base64 = Buffer.from(response.data, "binary").toString("base64");
|
||||||
|
return `data:${contentType};base64,${base64}`;
|
||||||
|
}
|
||||||
|
// 将图片ID和指令转换为base64数组和替换后的指令
|
||||||
|
async function convertDirectiveAndImages(images: Record<string, string>, directive: string) {
|
||||||
|
// step1: 列出所有别名
|
||||||
|
const aliasList = Object.keys(images);
|
||||||
|
// step2: 在指令中提取所有 @别名出现
|
||||||
|
const aliasRegex = /@[\u4e00-\u9fa5\w]+/g;
|
||||||
|
const referencedAliases = directive.match(aliasRegex) || [];
|
||||||
|
// step3: 检查别名
|
||||||
|
for (const alias of referencedAliases) {
|
||||||
|
if (!(alias in images)) {
|
||||||
|
throw new Error(`您引用了不存在的图片:${alias}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// step4: 构建别名与顺序编号映射
|
||||||
|
const aliasToIndex: Record<string, number> = {};
|
||||||
|
aliasList.forEach((alias, i) => {
|
||||||
|
aliasToIndex[alias] = i + 1;
|
||||||
|
});
|
||||||
|
// step5: 替换指令中的别名为"图N"
|
||||||
|
let prompt = directive;
|
||||||
|
for (const [alias, idx] of Object.entries(aliasToIndex)) {
|
||||||
|
// 转义alias可能含特殊字符
|
||||||
|
const reg = new RegExp(alias.replace(/([.*+?^${}()|\[\]\/\\])/g, "\\$1"), "g");
|
||||||
|
prompt = prompt.replace(reg, `图${idx}`);
|
||||||
|
}
|
||||||
|
// step6: 依次获取图片 base64 内容(区分id或者本身就是base64)
|
||||||
|
const base64Images: string[] = [];
|
||||||
|
|
||||||
|
for (const imageVal of Object.values(images)) {
|
||||||
|
// 判断是否为base64串
|
||||||
|
const isBase64 = typeof imageVal === "string" && /^data:image\//.test(imageVal);
|
||||||
|
if (isBase64) {
|
||||||
|
base64Images.push(imageVal);
|
||||||
|
} else if (typeof imageVal === "number") {
|
||||||
|
const base64 = await getImageBase64ForId(imageVal);
|
||||||
|
base64Images.push(base64);
|
||||||
|
} else if (imageVal.includes("http")) {
|
||||||
|
const base64 = await urlToBase64(imageVal);
|
||||||
|
base64Images.push(base64);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
prompt,
|
||||||
|
images: base64Images,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
export default router.post(
|
||||||
|
"/",
|
||||||
|
validateFields({
|
||||||
|
model: z.string(),
|
||||||
|
references: z.object().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 { prompt: userPrompt, images: base64Images } = await convertDirectiveAndImages(references, prompt);
|
||||||
|
const imageClass = await u.Ai.Image(model).run({
|
||||||
|
prompt: userPrompt,
|
||||||
|
imageBase64: base64Images,
|
||||||
|
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 }));
|
||||||
|
},
|
||||||
|
);
|
||||||
27
src/routes/production/editStoryboard/getStoryboardFlow.ts
Normal file
27
src/routes/production/editStoryboard/getStoryboardFlow.ts
Normal file
@ -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: [],
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
30
src/routes/production/editStoryboard/saveStoryboardFlow.ts
Normal file
30
src/routes/production/editStoryboard/saveStoryboardFlow.ts
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
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(),
|
||||||
|
imageUrl: z.number(),
|
||||||
|
}),
|
||||||
|
async (req, res) => {
|
||||||
|
const { edges, nodes, imageUrl } = req.body;
|
||||||
|
if (!imageUrl.includes("http")) {
|
||||||
|
return res.status(400).send({ message: "图片地址不合法" });
|
||||||
|
}
|
||||||
|
// if
|
||||||
|
const [id] = await u.db("o_storyboad").insert({
|
||||||
|
filePath: new URL(imageUrl).pathname,
|
||||||
|
});
|
||||||
|
await u.db("o_storyboardFlow").insert({
|
||||||
|
stroryboardId: id,
|
||||||
|
flowData: JSON.stringify({ edges, nodes }),
|
||||||
|
});
|
||||||
|
return res.status(200).send(success());
|
||||||
|
},
|
||||||
|
);
|
||||||
34
src/routes/production/editStoryboard/updateStoryboardFlow.ts
Normal file
34
src/routes/production/editStoryboard/updateStoryboardFlow.ts
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
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(),
|
||||||
|
imageUrl: z.number(),
|
||||||
|
}),
|
||||||
|
async (req, res) => {
|
||||||
|
const { edges, nodes, id, imageUrl } = req.body;
|
||||||
|
if (!imageUrl.includes("http")) {
|
||||||
|
return res.status(400).send({ message: "图片地址不合法" });
|
||||||
|
}
|
||||||
|
// if
|
||||||
|
await u
|
||||||
|
.db("o_storyboard")
|
||||||
|
.where("id", id)
|
||||||
|
.update({ filePath: new URL(imageUrl).pathname });
|
||||||
|
await u
|
||||||
|
.db("o_storyboardFlow")
|
||||||
|
.where("stroryboardId", id)
|
||||||
|
.update({
|
||||||
|
flowData: JSON.stringify({ edges, nodes }),
|
||||||
|
});
|
||||||
|
return res.status(200).send(success());
|
||||||
|
},
|
||||||
|
);
|
||||||
27
src/routes/production/getStoryboardData.ts
Normal file
27
src/routes/production/getStoryboardData.ts
Normal file
@ -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({
|
||||||
|
projectId: z.number(),
|
||||||
|
}),
|
||||||
|
async (req, res) => {
|
||||||
|
const { projectId } = req.body;
|
||||||
|
const storyboardData = await u.db("o_storyboard");
|
||||||
|
console.log("%c Line:16 🍖 storyboardData", "background:#ed9ec7", storyboardData);
|
||||||
|
const data = await Promise.all(
|
||||||
|
storyboardData.map(async (i) => {
|
||||||
|
return {
|
||||||
|
...i,
|
||||||
|
image: i.filePath ? await u.oss.getFileUrl(i.filePath!) : "",
|
||||||
|
};
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
res.status(200).send(success(data));
|
||||||
|
},
|
||||||
|
);
|
||||||
78
src/routes/production/workbench/generateVideo.ts
Normal file
78
src/routes/production/workbench/generateVideo.ts
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
import express from "express";
|
||||||
|
import u from "@/utils";
|
||||||
|
import { z } from "zod";
|
||||||
|
import { v4 as uuidv4 } from "uuid";
|
||||||
|
import { success } from "@/lib/responseFormat";
|
||||||
|
import { validateFields } from "@/middleware/middleware";
|
||||||
|
const router = express.Router();
|
||||||
|
|
||||||
|
export default router.post(
|
||||||
|
"/",
|
||||||
|
validateFields({
|
||||||
|
scriptId: z.number(),
|
||||||
|
projectId: z.number(),
|
||||||
|
storyboardId: z.number(),
|
||||||
|
prompt: z.string(),
|
||||||
|
data: z.array(z.string()).optional(),
|
||||||
|
model: z.string(),
|
||||||
|
duration: z.number(),
|
||||||
|
resolution: z.string(),
|
||||||
|
audio: z.boolean().optional(),
|
||||||
|
modeData: z.string(),
|
||||||
|
}),
|
||||||
|
async (req, res) => {
|
||||||
|
const { scriptId, projectId, storyboardId, prompt, data, model, duration, resolution, audio, modeData } = req.body;
|
||||||
|
try {
|
||||||
|
const relatedObjects = {
|
||||||
|
id: storyboardId,
|
||||||
|
projectId,
|
||||||
|
type: "视频",
|
||||||
|
};
|
||||||
|
const systemPrompt = `你是一个专业的视频生成引擎,能够根据用户提供的提示词、图片和参数生成高质量的视频内容。请严格按照用户的需求进行视频创作,确保输出的视频符合以下要求:
|
||||||
|
1. 视频内容必须与用户提供的提示词和图片相关联,准确反映用户的创意意图。
|
||||||
|
2. 视频质量应达到专业水平,画面清晰、流畅,符合用户指定的分辨率和时长要求。
|
||||||
|
3. 视频风格应与用户指定的模式数据相匹配,包括色彩、音乐、特效等元素。
|
||||||
|
4. 视频中应包含用户提供的图片,并在视频中适当展示,以增强视频的视觉效果。
|
||||||
|
5. 如果用户指定了音频,请确保视频中的音频与视频内容相匹配,符合用户的创意意图。`;
|
||||||
|
const videoPath = `/${projectId}/video/${uuidv4()}.mp4`;
|
||||||
|
const aiVideo = u.Ai.Video(model);
|
||||||
|
await aiVideo.run({
|
||||||
|
systemPrompt, // 系统提示词
|
||||||
|
projectId: projectId,
|
||||||
|
storyboardId: storyboardId,
|
||||||
|
prompt: prompt,
|
||||||
|
data: data,
|
||||||
|
modeData: modeData,
|
||||||
|
duration: duration,
|
||||||
|
resolution: resolution,
|
||||||
|
audio: audio,
|
||||||
|
taskClass: "视频生成",
|
||||||
|
describe: "根据提示词生成视频",
|
||||||
|
relatedObjects: JSON.stringify(relatedObjects),
|
||||||
|
});
|
||||||
|
await aiVideo.save(videoPath); // 保存视频
|
||||||
|
//保存视频信息到数据库
|
||||||
|
// await u.db("o_video").insert({
|
||||||
|
// resolution,
|
||||||
|
// prompt,
|
||||||
|
// filePath: videoPath,
|
||||||
|
// model,
|
||||||
|
// time: Date.now(),
|
||||||
|
// state: "生成成功",
|
||||||
|
// scriptId: scriptId,
|
||||||
|
// });
|
||||||
|
res.status(200).send(success("视频生成成功"));
|
||||||
|
} catch (error) {
|
||||||
|
// await u.db("o_video").insert({
|
||||||
|
// resolution,
|
||||||
|
// prompt,
|
||||||
|
// model,
|
||||||
|
// time: Date.now(),
|
||||||
|
// state: "生成失败",
|
||||||
|
// scriptId: scriptId,
|
||||||
|
// errorReason: error instanceof Error ? error.message : "未知错误",
|
||||||
|
// });
|
||||||
|
res.status(500).send({ error: "视频生成失败" });
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
@ -40,16 +40,9 @@ const vendorConfigSchema = z.object({
|
|||||||
modelName: z.string(),
|
modelName: z.string(),
|
||||||
type: z.literal("video"),
|
type: z.literal("video"),
|
||||||
mode: z.array(
|
mode: z.array(
|
||||||
z.enum([
|
z.union([
|
||||||
"singleImage",
|
z.enum(["singleImage", "multiImage", "gridImage", "startEndRequired", "endFrameOptional", "startFrameOptional", "text"]),
|
||||||
"multiImage",
|
z.array(z.enum(["audioReference", "videoReference", "textReference", "imageReference"])),
|
||||||
"gridImage",
|
|
||||||
"startEndRequired",
|
|
||||||
"endFrameOptional",
|
|
||||||
"startFrameOptional",
|
|
||||||
"text",
|
|
||||||
"audioReference",
|
|
||||||
"videoReference",
|
|
||||||
]),
|
]),
|
||||||
),
|
),
|
||||||
audio: z.union([z.literal("optional"), z.boolean()]),
|
audio: z.union([z.literal("optional"), z.boolean()]),
|
||||||
@ -100,16 +93,9 @@ export default router.post(
|
|||||||
modelName: z.string(),
|
modelName: z.string(),
|
||||||
type: z.literal("video"),
|
type: z.literal("video"),
|
||||||
mode: z.array(
|
mode: z.array(
|
||||||
z.enum([
|
z.union([
|
||||||
"singleImage",
|
z.enum(["singleImage", "multiImage", "gridImage", "startEndRequired", "endFrameOptional", "startFrameOptional", "text"]),
|
||||||
"multiImage",
|
z.array(z.enum(["audioReference", "videoReference", "textReference", "imageReference"])),
|
||||||
"gridImage",
|
|
||||||
"startEndRequired",
|
|
||||||
"endFrameOptional",
|
|
||||||
"startFrameOptional",
|
|
||||||
"text",
|
|
||||||
"audioReference",
|
|
||||||
"videoReference",
|
|
||||||
]),
|
]),
|
||||||
),
|
),
|
||||||
audio: z.union([z.literal("optional"), z.boolean()]),
|
audio: z.union([z.literal("optional"), z.boolean()]),
|
||||||
|
|||||||
8
src/types/database.d.ts
vendored
8
src/types/database.d.ts
vendored
@ -1,4 +1,4 @@
|
|||||||
// @db-hash feca77a2c2ec5b6a2989347f982558d5
|
// @db-hash bd46e7c381481a74efedc662a4f9049f
|
||||||
//该文件由脚本自动生成,请勿手动修改
|
//该文件由脚本自动生成,请勿手动修改
|
||||||
|
|
||||||
export interface memories {
|
export interface memories {
|
||||||
@ -166,6 +166,11 @@ export interface o_storyboard {
|
|||||||
'id'?: number;
|
'id'?: number;
|
||||||
'name'?: string | null;
|
'name'?: string | null;
|
||||||
}
|
}
|
||||||
|
export interface o_storyboardFlow {
|
||||||
|
'flowData': string;
|
||||||
|
'id'?: number;
|
||||||
|
'stroryboardId': number;
|
||||||
|
}
|
||||||
export interface o_storyboardScript {
|
export interface o_storyboardScript {
|
||||||
'id'?: number;
|
'id'?: number;
|
||||||
'scriptId'?: number | null;
|
'scriptId'?: number | null;
|
||||||
@ -254,6 +259,7 @@ export interface DB {
|
|||||||
"o_setting": o_setting;
|
"o_setting": o_setting;
|
||||||
"o_skills": o_skills;
|
"o_skills": o_skills;
|
||||||
"o_storyboard": o_storyboard;
|
"o_storyboard": o_storyboard;
|
||||||
|
"o_storyboardFlow": o_storyboardFlow;
|
||||||
"o_storyboardScript": o_storyboardScript;
|
"o_storyboardScript": o_storyboardScript;
|
||||||
"o_tasks": o_tasks;
|
"o_tasks": o_tasks;
|
||||||
"o_user": o_user;
|
"o_user": o_user;
|
||||||
|
|||||||
@ -112,13 +112,28 @@ class AiImage {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
interface VideoConfig {
|
||||||
|
projectId: number; // 项目ID
|
||||||
|
storyboardId: number; // 关联的分镜ID
|
||||||
|
systemPrompt?: string; // 系统提示词
|
||||||
|
prompt: string; //视频提示词
|
||||||
|
data: string[]; //输入的图片提示词
|
||||||
|
modeData: string; //模式
|
||||||
|
duration: number; // 视频时长,单位秒
|
||||||
|
resolution: string; // 视频分辨率
|
||||||
|
audio: boolean; // 是否需要配音
|
||||||
|
taskClass: string; // 任务分类
|
||||||
|
describe: string; // 任务描述
|
||||||
|
relatedObjects: string; // 相关对象信息,便于后续分析和追踪
|
||||||
|
}
|
||||||
|
|
||||||
class AiVideo {
|
class AiVideo {
|
||||||
private key: `${number}:${string}`;
|
private key: `${number}:${string}`;
|
||||||
private result: string = "";
|
private result: string = "";
|
||||||
constructor(key: `${number}:${string}`) {
|
constructor(key: `${number}:${string}`) {
|
||||||
this.key = key;
|
this.key = key;
|
||||||
}
|
}
|
||||||
async run(input: ImageConfig) {
|
async run(input: VideoConfig) {
|
||||||
return withTaskRecord(this.key, input.taskClass, input.describe, input.relatedObjects, input.projectId, async (modelName) => {
|
return withTaskRecord(this.key, input.taskClass, input.describe, input.relatedObjects, input.projectId, async (modelName) => {
|
||||||
const fn = await getVendorTemplateFn("videoRequest", modelName);
|
const fn = await getVendorTemplateFn("videoRequest", modelName);
|
||||||
this.result = await fn(input);
|
this.result = await fn(input);
|
||||||
@ -137,7 +152,7 @@ class AiAudio {
|
|||||||
constructor(key: `${number}:${string}`) {
|
constructor(key: `${number}:${string}`) {
|
||||||
this.key = key;
|
this.key = key;
|
||||||
}
|
}
|
||||||
async run(input: ImageConfig) {
|
async run(input: VideoConfig) {
|
||||||
return withTaskRecord(this.key, input.taskClass, input.describe, input.relatedObjects, input.projectId, async (modelName) => {
|
return withTaskRecord(this.key, input.taskClass, input.describe, input.relatedObjects, input.projectId, async (modelName) => {
|
||||||
const fn = await getVendorTemplateFn("ttsRequest", modelName);
|
const fn = await getVendorTemplateFn("ttsRequest", modelName);
|
||||||
this.result = await fn(input);
|
this.result = await fn(input);
|
||||||
|
|||||||
@ -2525,6 +2525,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"
|
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==
|
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:
|
guid-typescript@^1.0.9:
|
||||||
version "1.0.9"
|
version "1.0.9"
|
||||||
resolved "https://registry.npmmirror.com/guid-typescript/-/guid-typescript-1.0.9.tgz#e35f77003535b0297ea08548f5ace6adb1480ddc"
|
resolved "https://registry.npmmirror.com/guid-typescript/-/guid-typescript-1.0.9.tgz#e35f77003535b0297ea08548f5ace6adb1480ddc"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user