再次修复删除资产图片问题
This commit is contained in:
parent
7c118ccfc0
commit
1c48ade83d
@ -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: "删除资产成功" }));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user