Skip to content

Commit e41d578

Browse files
committed
create objects manager delete method
1 parent 0f7df77 commit e41d578

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

.changeset/loud-singers-listen.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@squarecloud/blob": minor
3+
---
4+
5+
Add `BlobObjectsManager#delete` method for deleting blobs

src/managers/objects.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@ import type { PutObjectResponse, PutObjectType } from "../types/put";
88
export class BlobObjectsManager {
99
constructor(private readonly client: SquareCloudBlob) {}
1010

11+
/**
12+
* Uploads an object to the storage.
13+
*
14+
* @param object - An object to upload
15+
*
16+
* @example
17+
* ```js
18+
* await blob.objects.put({ file: "path/to/file.jpeg", name: "my_image" });
19+
* ```
20+
*/
1121
async put(object: PutObjectType) {
1222
const payload = putObjectPayloadSchema.parse(object);
1323
const file = await this.parseFile(payload.file);
@@ -23,6 +33,27 @@ export class BlobObjectsManager {
2333
return assertPutObjectResponse(response);
2434
}
2535

36+
/**
37+
* Deletes multiple objects.
38+
*
39+
* @param objects - An array of object IDs
40+
*
41+
* @example
42+
* ```js
43+
* await blob.objects.delete("ID/prefix/name1_xxx-xxx.zip", "ID/prefix/name_xxx-xxx-xxx.png");
44+
* ```
45+
*/
46+
async delete(...objects: string[] | string[][]) {
47+
const ids = objects.flat();
48+
49+
const response = await this.client.api.request("delete", {
50+
method: "DELETE",
51+
body: { objects: ids },
52+
});
53+
54+
return response.status === "success";
55+
}
56+
2657
private async parseFile(file: string | Buffer) {
2758
let result: Buffer | undefined;
2859

0 commit comments

Comments
 (0)