查询素材数据插入片尾视频

This commit is contained in:
小帅 2026-03-30 22:54:44 +08:00
parent 553d0a360e
commit 06ae21eae1
4 changed files with 53 additions and 35 deletions

View File

@ -526,6 +526,7 @@ description: 专注于从剧本内容中提取所使用的资产(角色、场
table.text("state");
table.integer("scriptId");
table.integer("storyboardId");
table.integer("projectId");
table.primary(["id"]);
table.unique(["id"]);
},

View File

@ -1,32 +1,54 @@
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("/", async (req, res) => {
const list = await u.db("o_assets").leftJoin("o_image", "o_assets.id", "=", "o_image.assetsId").where("o_assets.type", "clip").select("*");
const data = await Promise.all(
list.map(async (item) => ({
...item,
filePath: item.filePath ? await u.oss.getFileUrl(item.filePath) : "",
})),
);
// 查询o_videoConfig表拿到已选中的videoId
const configRows = await u.db("o_videoConfig").select("videoId");
const selectedIds = new Set(configRows.map((row) => row.videoId));
export default router.post(
"/",
validateFields({
projectId: z.number(),
}),
async (req, res) => {
const { projectId } = req.body;
const list = await u
.db("o_assets")
.leftJoin("o_image", "o_assets.id", "=", "o_image.assetsId")
.where("o_assets.type", "clip")
.andWhere("projectId", projectId)
.select("*");
const data = await Promise.all(
list.map(async (item) => ({
...item,
filePath: item.filePath ? await u.oss.getFileUrl(item.filePath) : "",
})),
);
//拿到本地片尾视频并插入到data中
const ending = await u.oss.getFileUrl("/ending/1d7a2dfdd0c057823797fdf97677a7a0.mp4");
data.push({
id: 0,
name: "片尾",
filePath: ending,
type: "clip",
});
// 查询o_videoConfig表拿到已选中的videoId
const configRows = await u.db("o_videoConfig").select("videoId");
const selectedIds = new Set(configRows.map((row) => row.videoId));
// 查询o_video表
const videoRows = await u.db("o_video").where("state", "生成成功").select("*");
// 查询o_video表
const videoRows = await u.db("o_video").where("state", "生成成功").andWhere("projectId", projectId).select("*");
// 处理并返回结果
const video = await Promise.all(
videoRows.map(async (row) => ({
id: row.id,
filePath: row.filePath ? await u.oss.getFileUrl(row.filePath) : "",
selected: selectedIds.has(row.id),
storyboard: row.storyboardId,
})),
);
// 处理并返回结果
const video = await Promise.all(
videoRows.map(async (row) => ({
id: row.id,
filePath: row.filePath ? await u.oss.getFileUrl(row.filePath) : "",
selected: selectedIds.has(row.id),
storyboard: row.storyboardId,
})),
);
res.status(200).send(success({ data, video }));
});
res.status(200).send(success({ data, video }));
},
);

View File

@ -39,6 +39,7 @@ export default router.post(
state: "生成中",
scriptId,
storyboardId,
projectId,
};
const [videoId] = await u.db("o_video").insert(videoData);
//查询分镜是否已有配置

View File

@ -1,13 +1,6 @@
// @db-hash 24748d4ef971381a79c720c846f83847
// @db-hash 6be0a80e9c8f541987a4c1e907736237
//该文件由脚本自动生成,请勿手动修改
export interface _o_script_old_20260327 {
'content'?: string | null;
'createTime'?: number | null;
'id'?: number;
'name'?: string | null;
'projectId'?: number | null;
}
export interface memories {
'content': string;
'createTime': number;
@ -28,7 +21,7 @@ export interface o_agentDeploy {
'model'?: string | null;
'modelName'?: string | null;
'name'?: string | null;
'vendorId'?: number | null;
'vendorId'?: string | null;
}
export interface o_agentWorkData {
'createTime'?: number | null;
@ -54,6 +47,7 @@ export interface o_assets {
'name'?: string | null;
'projectId'?: number | null;
'prompt'?: string | null;
'promptState'?: string | null;
'remark'?: string | null;
'scriptId'?: number | null;
'startTime'?: number | null;
@ -173,7 +167,7 @@ export interface o_storyboard {
'filePath'?: string | null;
'frameMode'?: string | null;
'id'?: number;
'index'?: string | null;
'index'?: number | null;
'lines'?: string | null;
'mode'?: string | null;
'model'?: string | null;
@ -218,6 +212,7 @@ export interface o_video {
'errorReason'?: string | null;
'filePath'?: string | null;
'id'?: number;
'projectId'?: number | null;
'scriptId'?: number | null;
'state'?: string | null;
'storyboardId'?: number | null;
@ -239,7 +234,6 @@ export interface o_videoConfig {
}
export interface DB {
"_o_script_old_20260327": _o_script_old_20260327;
"memories": memories;
"o_agentDeploy": o_agentDeploy;
"o_agentWorkData": o_agentWorkData;