From 1c48ade83dc851118d3e73d3932b68ac675631c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E5=B8=85?= <2944435683> Date: Sat, 4 Apr 2026 17:23:58 +0800 Subject: [PATCH] =?UTF-8?q?=E5=86=8D=E6=AC=A1=E4=BF=AE=E5=A4=8D=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E8=B5=84=E4=BA=A7=E5=9B=BE=E7=89=87=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/routes/assets/delAssets.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/routes/assets/delAssets.ts b/src/routes/assets/delAssets.ts index d5195df..cbca48f 100644 --- a/src/routes/assets/delAssets.ts +++ b/src/routes/assets/delAssets.ts @@ -13,7 +13,19 @@ export default router.post( async (req, res) => { const { id } = req.body; const assetsData = await u.db("o_image").where("assetsId", id); - await Promise.all(assetsData.map((i) => i.filePath && u.oss.deleteFile(i.filePath))); + await Promise.all( + assetsData.map((i) => + i.filePath + ? u.oss.deleteFile(i.filePath).catch((e) => { + if (e?.code !== "ENOENT") throw e; + }) + : Promise.resolve(), + ), + ); + const imageIds = assetsData.map((i) => i.id).filter(Boolean); + if (imageIds.length > 0) { + await u.db("o_assets").whereIn("imageId", imageIds).update({ imageId: null }); + } await u.db("o_image").where({ assetsId: id }).delete(); await u.db("o_assets").where({ id }).delete(); res.status(200).send(success({ message: "删除资产成功" }));