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: "删除资产成功" }));