no message
This commit is contained in:
parent
c146edaf69
commit
1842fe74a8
@ -451,6 +451,7 @@ description: 专注于从剧本内容中提取所使用的资产(角色、场
|
||||
table.integer("imageId").unsigned().references("id").inTable("o_image");
|
||||
table.integer("assetsId");
|
||||
table.integer("projectId");
|
||||
table.integer("flowId"); //工作流id
|
||||
table.integer("startTime");
|
||||
table.string("promptState");
|
||||
table.primary(["id"]);
|
||||
@ -487,6 +488,7 @@ description: 专注于从剧本内容中提取所使用的资产(角色、场
|
||||
table.integer("trackId");
|
||||
table.text("reason");
|
||||
table.integer("projectId");
|
||||
table.integer("flowId"); //工作流id
|
||||
table.integer("index");
|
||||
table.integer("createTime");
|
||||
table.primary(["id"]);
|
||||
@ -560,8 +562,6 @@ description: 专注于从剧本内容中提取所使用的资产(角色、场
|
||||
builder: (table) => {
|
||||
table.integer("id").notNullable();
|
||||
table.text("flowData").notNullable();
|
||||
table.integer("storyboardId");
|
||||
table.integer("assetsId");
|
||||
table.primary(["id"]);
|
||||
table.unique(["id"]);
|
||||
},
|
||||
|
||||
@ -107,89 +107,41 @@ export default router.post(
|
||||
assets2StoryboardMap[i.storyboardId!].push(i.assetId!);
|
||||
});
|
||||
const flowData = JSON.parse(sqlData!.data ?? "{}");
|
||||
// 将原有 flowData.assets 按 id 建立索引,以便后续合并保留旧字段
|
||||
const existingAssetsMap: Record<number, any> = {};
|
||||
if (Array.isArray(flowData.assets)) {
|
||||
flowData.assets.forEach((a: any) => {
|
||||
existingAssetsMap[a.id] = a;
|
||||
});
|
||||
}
|
||||
flowData.assets = await Promise.all(
|
||||
assetsData.map(async (item) => {
|
||||
const existing = existingAssetsMap[item.id] ?? {};
|
||||
// 将原有 derive 按 id 建立索引
|
||||
const existingDeriveMap: Record<number, any> = {};
|
||||
if (Array.isArray(existing.derive)) {
|
||||
existing.derive.forEach((d: any) => {
|
||||
existingDeriveMap[d.id] = d;
|
||||
});
|
||||
}
|
||||
return {
|
||||
...existing,
|
||||
id: item.id,
|
||||
name: item.name ?? "",
|
||||
type: item.type ?? "",
|
||||
prompt: item.prompt ?? "",
|
||||
desc: item.describe ?? "",
|
||||
src: item.filePath && (await u.oss.getFileUrl(item.filePath!)),
|
||||
derive: await Promise.all(
|
||||
childAssetsData
|
||||
.filter((child) => child.assetsId === item.id)
|
||||
.map(async (child) => ({
|
||||
...(existingDeriveMap[child.id] ?? {}),
|
||||
id: child.id,
|
||||
assetsId: item.id,
|
||||
name: child.name ?? "",
|
||||
prompt: child.prompt,
|
||||
type: child.type,
|
||||
desc: child.describe ?? "",
|
||||
src: child.filePath && (await u.oss.getFileUrl(child.filePath!)),
|
||||
state: child.state ?? "未生成", //todo:矫正状态值
|
||||
})),
|
||||
),
|
||||
};
|
||||
}),
|
||||
assetsData.map(async (item) => ({
|
||||
id: item.id,
|
||||
name: item.name ?? "",
|
||||
type: item.type ?? "",
|
||||
prompt: item.prompt ?? "",
|
||||
desc: item.describe ?? "",
|
||||
src: item.filePath && (await u.oss.getFileUrl(item.filePath!)),
|
||||
derive: await Promise.all(
|
||||
childAssetsData
|
||||
.filter((child) => child.assetsId === item.id)
|
||||
.map(async (child) => ({
|
||||
id: child.id,
|
||||
assetsId: item.id,
|
||||
name: child.name ?? "",
|
||||
prompt: child.prompt,
|
||||
type: child.type,
|
||||
desc: child.describe ?? "",
|
||||
src: child.filePath && (await u.oss.getFileUrl(child.filePath!)),
|
||||
state: child.state ?? "未生成",
|
||||
})),
|
||||
),
|
||||
})),
|
||||
);
|
||||
// 将数据库 storyboardData 按 id 建立索引
|
||||
const dbStoryboardMap: Record<number, (typeof storyboardData)[number]> = {};
|
||||
storyboardData.forEach((i) => {
|
||||
dbStoryboardMap[i.id!] = i;
|
||||
});
|
||||
|
||||
// 用于构造单条 storyboard 的辅助函数
|
||||
const buildStoryboardItem = (i: (typeof storyboardData)[number], existing: any = {}) => ({
|
||||
...existing,
|
||||
id: i.id,
|
||||
index: i.index,
|
||||
duration: i.duration ? +i.duration : 0,
|
||||
prompt: i.prompt,
|
||||
associateAssetsIds: assets2StoryboardMap[i.id!] ?? [],
|
||||
src: i.filePath,
|
||||
state: i.state,
|
||||
});
|
||||
|
||||
// 保持旧数据顺序,新增的追加到最后
|
||||
const usedIds = new Set<number>();
|
||||
const orderedStoryboard: any[] = [];
|
||||
|
||||
// 1. 按旧数据顺序遍历,若数据库中仍存在则合并更新
|
||||
if (Array.isArray(flowData.storyboard)) {
|
||||
flowData.storyboard.forEach((s: any) => {
|
||||
const dbItem = dbStoryboardMap[s.id];
|
||||
if (dbItem) {
|
||||
orderedStoryboard.push(buildStoryboardItem(dbItem, s));
|
||||
usedIds.add(s.id);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 2. 数据库中新增的(旧数据中没有的)追加到最后
|
||||
storyboardData.forEach((i) => {
|
||||
if (!usedIds.has(i.id!)) {
|
||||
orderedStoryboard.push(buildStoryboardItem(i));
|
||||
}
|
||||
});
|
||||
flowData.storyboard = orderedStoryboard.sort((a, b) => (a.index ?? 0) - (b.index ?? 0));
|
||||
flowData.storyboard = storyboardData
|
||||
.map((i) => ({
|
||||
id: i.id,
|
||||
index: i.index,
|
||||
duration: i.duration ? +i.duration : 0,
|
||||
prompt: i.prompt,
|
||||
associateAssetsIds: assets2StoryboardMap[i.id!] ?? [],
|
||||
src: i.filePath,
|
||||
state: i.state,
|
||||
}))
|
||||
.sort((a, b) => (a.index ?? 0) - (b.index ?? 0));
|
||||
res.status(200).send(success(flowData));
|
||||
} catch (err) {
|
||||
res.status(400).send(error());
|
||||
|
||||
@ -24,17 +24,14 @@ export default router.post(
|
||||
episodesId: number;
|
||||
} = req.body;
|
||||
const sqlData = await u.db("o_agentWorkData").where("projectId", String(projectId)).andWhere("episodesId", String(episodesId)).first();
|
||||
// if (data.storyboard && data.storyboard.length)
|
||||
// await Promise.all(
|
||||
// data.storyboard.map(async (i, index) => {
|
||||
// await u
|
||||
// .db("o_storyboard")
|
||||
// .where("id", i.id)
|
||||
// .update({
|
||||
// index: index + 1,
|
||||
// });
|
||||
// }),
|
||||
// );
|
||||
if (data.storyboard && data.storyboard.length)
|
||||
await Promise.all(
|
||||
data.storyboard.map(async (i, index) => {
|
||||
await u.db("o_storyboard").where("id", i.id).update({
|
||||
index: index,
|
||||
});
|
||||
}),
|
||||
);
|
||||
if (!sqlData) {
|
||||
await u.db("o_agentWorkData").insert({
|
||||
projectId,
|
||||
|
||||
89
src/types/database.d.ts
vendored
89
src/types/database.d.ts
vendored
@ -1,19 +1,48 @@
|
||||
// @db-hash b1210691844e077e9df7dc16c802ce5a
|
||||
// @db-hash c145f43374602285beea82bbd51eaec8
|
||||
//该文件由脚本自动生成,请勿手动修改
|
||||
|
||||
export interface _o_project_old_20260331 {
|
||||
'artStyle'?: string | null;
|
||||
export interface _o_storyboard_old_20260331 {
|
||||
'camera'?: string | null;
|
||||
'createTime'?: number | null;
|
||||
'id'?: number | null;
|
||||
'imageModel'?: string | null;
|
||||
'imageQuality'?: string | null;
|
||||
'intro'?: string | null;
|
||||
'name'?: string | null;
|
||||
'projectType'?: string | null;
|
||||
'type'?: string | null;
|
||||
'userId'?: number | null;
|
||||
'videoModel'?: string | null;
|
||||
'videoRatio'?: string | null;
|
||||
'description'?: string | null;
|
||||
'duration'?: string | null;
|
||||
'filePath'?: string | null;
|
||||
'frameMode'?: string | null;
|
||||
'id'?: number;
|
||||
'index'?: number | null;
|
||||
'lines'?: string | null;
|
||||
'mode'?: string | null;
|
||||
'model'?: string | null;
|
||||
'prompt'?: string | null;
|
||||
'reason'?: string | null;
|
||||
'resolution'?: string | null;
|
||||
'scriptId'?: number | null;
|
||||
'sound'?: string | null;
|
||||
'state'?: string | null;
|
||||
'title'?: string | null;
|
||||
'videoPrompt'?: string | null;
|
||||
}
|
||||
export interface _o_storyboard_old_20260331_1 {
|
||||
'camera'?: string | null;
|
||||
'createTime'?: number | null;
|
||||
'description'?: string | null;
|
||||
'duration'?: string | null;
|
||||
'filePath'?: string | null;
|
||||
'frameMode'?: string | null;
|
||||
'id'?: number;
|
||||
'index'?: number | null;
|
||||
'lines'?: string | null;
|
||||
'mode'?: string | null;
|
||||
'model'?: string | null;
|
||||
'prompt'?: string | null;
|
||||
'reason'?: string | null;
|
||||
'resolution'?: string | null;
|
||||
'scriptId'?: number | null;
|
||||
'sound'?: string | null;
|
||||
'state'?: string | null;
|
||||
'title'?: string | null;
|
||||
'track'?: string | null;
|
||||
'videoPrompt'?: string | null;
|
||||
}
|
||||
export interface memories {
|
||||
'content': string;
|
||||
@ -87,6 +116,7 @@ export interface o_image {
|
||||
'filePath'?: string | null;
|
||||
'id'?: number;
|
||||
'model'?: string | null;
|
||||
'reason'?: string | null;
|
||||
'resolution'?: string | null;
|
||||
'state'?: string | null;
|
||||
'type'?: string | null;
|
||||
@ -127,7 +157,6 @@ export interface o_project {
|
||||
'imageModel'?: string | null;
|
||||
'imageQuality'?: string | null;
|
||||
'intro'?: string | null;
|
||||
'mode'?: string | null;
|
||||
'name'?: string | null;
|
||||
'projectType'?: string | null;
|
||||
'type'?: string | null;
|
||||
@ -175,25 +204,17 @@ export interface o_skillList {
|
||||
'updateTime': number;
|
||||
}
|
||||
export interface o_storyboard {
|
||||
'camera'?: string | null;
|
||||
'createTime'?: number | null;
|
||||
'description'?: string | null;
|
||||
'duration'?: string | null;
|
||||
'filePath'?: string | null;
|
||||
'frameMode'?: string | null;
|
||||
'id'?: number;
|
||||
'index'?: number | null;
|
||||
'lines'?: string | null;
|
||||
'mode'?: string | null;
|
||||
'model'?: string | null;
|
||||
'projectId'?: number | null;
|
||||
'prompt'?: string | null;
|
||||
'reason'?: string | null;
|
||||
'resolution'?: string | null;
|
||||
'scriptId'?: number | null;
|
||||
'sound'?: string | null;
|
||||
'state'?: string | null;
|
||||
'title'?: string | null;
|
||||
'videoPrompt'?: string | null;
|
||||
'trackId'?: number | null;
|
||||
}
|
||||
export interface o_tasks {
|
||||
'describe'?: string | null;
|
||||
@ -230,8 +251,22 @@ export interface o_video {
|
||||
'projectId'?: number | null;
|
||||
'scriptId'?: number | null;
|
||||
'state'?: string | null;
|
||||
'storyboardId'?: number | null;
|
||||
'time'?: number | null;
|
||||
'videoTrackId'?: number | null;
|
||||
}
|
||||
export interface o_videoConfig {
|
||||
'audio'?: number | null;
|
||||
'createTime'?: number | null;
|
||||
'data'?: string | null;
|
||||
'duration'?: number | null;
|
||||
'id'?: number;
|
||||
'mode'?: string | null;
|
||||
'model'?: string | null;
|
||||
'prompt'?: string | null;
|
||||
'resolution'?: string | null;
|
||||
'storyboardId'?: number | null;
|
||||
'updateTime'?: number | null;
|
||||
'videoId'?: number | null;
|
||||
}
|
||||
export interface o_videoTrack {
|
||||
'id'?: number;
|
||||
@ -241,7 +276,8 @@ export interface o_videoTrack {
|
||||
}
|
||||
|
||||
export interface DB {
|
||||
"_o_project_old_20260331": _o_project_old_20260331;
|
||||
"_o_storyboard_old_20260331": _o_storyboard_old_20260331;
|
||||
"_o_storyboard_old_20260331_1": _o_storyboard_old_20260331_1;
|
||||
"memories": memories;
|
||||
"o_agentDeploy": o_agentDeploy;
|
||||
"o_agentWorkData": o_agentWorkData;
|
||||
@ -267,5 +303,6 @@ export interface DB {
|
||||
"o_user": o_user;
|
||||
"o_vendorConfig": o_vendorConfig;
|
||||
"o_video": o_video;
|
||||
"o_videoConfig": o_videoConfig;
|
||||
"o_videoTrack": o_videoTrack;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user