mirror of
https://github.com/strapi/strapi.git
synced 2025-11-01 18:33:55 +00:00
fix: filter folder by eq and startswith
This commit is contained in:
parent
1ff71db3f6
commit
008d82f8f7
@ -56,16 +56,22 @@ const deleteByIds = async (ids = []) => {
|
||||
// delete files
|
||||
const filesToDelete = await strapi.db.query(FILE_MODEL_UID).findMany({
|
||||
where: {
|
||||
$or: pathsToDelete.map((path) => ({ folderPath: { $startsWith: path } })),
|
||||
$or: pathsToDelete.flatMap((path) => [
|
||||
{ folderPath: { $eq: path } },
|
||||
{ folderPath: { $startsWith: `${path}/` } },
|
||||
]),
|
||||
},
|
||||
});
|
||||
|
||||
await Promise.all(filesToDelete.map((file) => getService('upload').remove(file)));
|
||||
|
||||
// delete folders
|
||||
// delete folders and subfolders
|
||||
const { count: totalFolderNumber } = await strapi.db.query(FOLDER_MODEL_UID).deleteMany({
|
||||
where: {
|
||||
$or: pathsToDelete.map((path) => ({ path: { $startsWith: path } })),
|
||||
$or: pathsToDelete.flatMap((path) => [
|
||||
{ path: { $eq: path } },
|
||||
{ path: { $startsWith: `${path}/` } },
|
||||
]),
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user