Skip to content

Commit

Permalink
fix(Assets): infinite loop on file delete
Browse files Browse the repository at this point in the history
  • Loading branch information
jakeaturner committed Oct 3, 2024
1 parent acb60b5 commit 44f4f4d
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions server/api/projectfiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1084,20 +1084,23 @@ async function removeProjectFilesInternal(projectID: string, fileIDs: string[])
throw new Error("Missing Cloudflare credentials");
}

const parentFiles = await ProjectFile.find({
projectID,
fileID: { $in: fileIDs },
}).lean() as ProjectFileInterface[];

async function resolveAllChildren(searchFileIDs: string[]): Promise<ProjectFileInterface[]> {
const files = (await ProjectFile.find({
fileID: {
$in: searchFileIDs
},
const files = await ProjectFile.find({
projectID,
}).lean()) as ProjectFileInterface[];
parent: { $in: searchFileIDs },
}).lean() as ProjectFileInterface[];
if (!files?.length) return [];

const children = await resolveAllChildren(files.map((f) => f.fileID));
const children = await resolveAllChildren(files.map((o) => o.fileID).filter((o) => o));
return files.concat(children);
}

const objsToDelete = await resolveAllChildren(fileIDs);
const objsToDelete = (await resolveAllChildren(fileIDs)).concat(parentFiles);
const allFileIds = objsToDelete.map((o => o.fileID));

const filesToDelete = objsToDelete
Expand Down

0 comments on commit 44f4f4d

Please sign in to comment.