Files
klz-cables.com/.pnpm-store/v10/files/c8/030c2ca642458eddd8b5fcb8a78d95d1a968c212181e4f6d76e51f053c3c0390c3c053145e37865fbff343475f1e02f017b00ce241d8f522c045122e3256e5
Marc Mintel 5397309103
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
fix(products): fix breadcrumbs and product filtering (backport from main)
2026-02-24 16:04:21 +01:00

37 lines
1.4 KiB
Plaintext

import fs from 'fs/promises';
import { ErrorDeletingFile } from '../errors/index.js';
import { fileExists } from './fileExists.js';
export const deleteAssociatedFiles = async ({ collectionConfig, doc, files = [], overrideDelete, req })=>{
if (!collectionConfig.upload) {
return;
}
if (overrideDelete || files.length > 0) {
const { staticDir: staticPath } = collectionConfig.upload;
const fileToDelete = `${staticPath}/${doc.filename}`;
try {
if (await fileExists(fileToDelete)) {
await fs.unlink(fileToDelete);
}
} catch (ignore) {
throw new ErrorDeletingFile(req.t);
}
if (doc.sizes) {
const sizes = Object.values(doc.sizes);
// Since forEach will not wait until unlink is finished it could
// happen that two operations will try to delete the same file.
// To avoid this it is recommended to use "sync" instead
for (const size of sizes){
const sizeToDelete = `${staticPath}/${size.filename}`;
try {
if (await fileExists(sizeToDelete)) {
await fs.unlink(sizeToDelete);
}
} catch (ignore) {
throw new ErrorDeletingFile(req.t);
}
}
}
}
};
//# sourceMappingURL=deleteAssociatedFiles.js.map