video-flow-toon/src/utils/deleteOutline.ts
ACT丶流星雨 0798ae03ee no message
2026-01-29 18:28:32 +08:00

32 lines
1.2 KiB
TypeScript

import u from "@/utils";
export default async function deleteOutline(id: number, projectId: number) {
const targetOutlineData = await u.db("t_outline").where("id", id).select("data").first();
if (!targetOutlineData) throw new Error("大纲不存在");
//筛选出改大纲特有的资产
const allOutlineDataList = await u.db("t_outline").where("projectId", projectId).andWhere("id", "!=", id).select("data");
//找出目标ID大纲特有的资产名称
const allOutlineData = allOutlineDataList
.map((item) => {
const data = JSON.parse(item?.data || "[]");
return [...data.characters, ...data.props, ...data.scenes].map((item: any) => item.name);
})
.flat();
const targetOutLineNames = JSON.parse(targetOutlineData?.data || "[]");
const targetNames = [...targetOutLineNames.characters, ...targetOutLineNames.props, ...targetOutLineNames.scenes].map((item: any) => item.name);
const diffAssetsNames = targetNames.filter((item) => !allOutlineData.includes(item));
if (diffAssetsNames.length) {
await u.db("t_outline").where("id", id).del();
await u.db("t_assets").where("projectId", projectId).whereIn("name", diffAssetsNames).del();
await u.db("t_script").where("outlineId", id).del();
}
}