feat: add util function delete folder minio
This commit is contained in:
parent
8474a6c869
commit
b167a612b4
1 changed files with 22 additions and 0 deletions
|
|
@ -10,6 +10,28 @@ const minio = new Client({
|
||||||
|
|
||||||
export default minio;
|
export default minio;
|
||||||
|
|
||||||
|
export async function deleteFolder(bucket: string, path: string, wait = false) {
|
||||||
|
return new Promise<string[]>((resolve, reject) => {
|
||||||
|
const item: string[] = [];
|
||||||
|
|
||||||
|
const stream = minio.listObjectsV2(bucket, path);
|
||||||
|
|
||||||
|
stream.on("data", (v) => v && v.name && item.push(v.name));
|
||||||
|
stream.on("end", () => resolve(item));
|
||||||
|
stream.on("error", () => reject(new Error("MinIO error.")));
|
||||||
|
}).then(async (list) => {
|
||||||
|
const promises = list.map(async (v) =>
|
||||||
|
minio.removeObject(bucket, v, {
|
||||||
|
forceDelete: true,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (wait) await Promise.allSettled(promises);
|
||||||
|
|
||||||
|
return list;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// minio typescript does not support include version
|
// minio typescript does not support include version
|
||||||
type BucketItemWithVersion = {
|
type BucketItemWithVersion = {
|
||||||
name: string;
|
name: string;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue