Skip to content

Fix #2314 by ignoring deleted assets in zip download #2315

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 18 additions & 39 deletions server/controllers/project.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,48 +215,27 @@ function bundleExternalLibs(project) {
});
}

function addFileToZip(file, files, zip, path = '') {
return new Promise((resolve, reject) => {
if (file.fileType === 'folder') {
const newPath = file.name === 'root' ? path : `${path}${file.name}/`;
const numChildFiles = file.children.filter((f) => f.fileType !== 'folder')
.length;
let childrenAdded = 0;
if (numChildFiles === 0) {
zip.folder(file.name);
resolve();
}
file.children.forEach(async (fileId) => {
async function addFileToZip(file, files, zip) {
if (file.fileType === 'folder') {
const folderZip = file.name === 'root' ? zip : zip.folder(file.name);
await Promise.all(
file.children.map((fileId) => {
const childFile = files.find((f) => f.id === fileId);

try {
await addFileToZip(childFile, files, zip, newPath);
childrenAdded += 1;

if (childrenAdded === numChildFiles) {
resolve();
}
} catch (err) {
reject(err);
}
return addFileToZip(childFile, files, folderZip);
})
);
} else if (file.url) {
try {
const res = await axios.get(file.url, {
responseType: 'arraybuffer'
});
} else if (file.url) {
axios
.get(file.url, {
responseType: 'arraybuffer'
})
.then(({ data }) => {
zip.file(`${path}${file.name}`, data);
resolve();
})
.catch((err) => {
reject(err);
});
} else {
zip.file(`${path}${file.name}`, file.content);
resolve();
zip.file(file.name, res.data);
} catch (e) {
zip.file(file.name, new ArrayBuffer(0));
}
});
} else {
zip.file(file.name, file.content);
}
}

async function buildZip(project, req, res) {
Expand Down