ACT丶流星雨 0798ae03ee no message
2026-01-29 18:28:32 +08:00

60 lines
2.0 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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;
const scriptData = await u.db("t_script").where("projectId", id).select("id");
const scriptIds = scriptData.map((item: any) => item.id);
const assetsData = await u.db("t_assets").where("projectId", id).select("id");
const assetsIds = assetsData.map((item: any) => item.id);
const videoData = await u.db("t_video").whereIn("scriptId", scriptIds).select("id");
const videoIds = videoData.map((item: any) => item.id);
await u.db("t_project").where("id", id).delete();
await u.db("t_novel").where("projectId", id).delete();
await u.db("t_storyline").where("projectId", id).delete();
await u.db("t_outline").where("projectId", id).delete();
await u.db("t_script").where("projectId", id).delete();
await u.db("t_assets").where("projectId", id).delete();
const tempAssetsQuery = u.db("t_image").where("projectId", id);
if (assetsIds.length > 0) {
tempAssetsQuery.orWhereIn("assetsId", assetsIds);
}
if (scriptIds.length > 0) {
tempAssetsQuery.orWhereIn("scriptId", scriptIds);
}
if (videoIds.length > 0) {
tempAssetsQuery.orWhereIn("videoId", videoIds);
}
await tempAssetsQuery.delete();
await u.db("t_video").whereIn("scriptId", scriptIds).delete();
await u.db("t_chatHistory").where("projectId", id).delete();
try {
await u.oss.deleteDirectory(`${id}/`);
console.log(`项目 ${id} 的OSS文件夹删除成功`);
} catch (error: any) {
console.log(`项目 ${id} 没有对应的OSS文件夹跳过删除`);
}
res.status(200).send(success({ message: "删除项目成功" }));
}
);