import { StorageInstance as storage } from '../shared.js';
/**
* ### Delete File or File Version from bucket
* @method module:cpb-storage/file.delete
* @async
* @param {?string} [bucket=process.env.BUCKET || 'custom-product-builder'] - storage bucket
* @param {!string} name - filepath to delete
* @param {?number} [generation] - file generation; if given only that file version will be deleted
* @returns {Promise<void>}
*/
export default async function DeleteFile({ bucket = process.env.BUCKET || 'custom-product-builder', path, generation } = {}) {
if (!path) throw new TypeError('!path');
async function deleteFile() {
const prev = {};
if (generation) prev.generation = generation;
console.info(`[storage/file/delete][${bucket}/${path}/${generation}] DELETING...`);
return await storage.bucket(bucket).file(path, prev).delete();
}
return await deleteFile().catch(console.error);
}