@@ -2,7 +2,6 @@ import type { SquareCloudBlob } from "..";
22import { BlobObject } from "../structures/object" ;
33import type { CreateObjectResponse , CreateObjectType } from "../types/create" ;
44import type { ListObjectsResponse } from "../types/list" ;
5- import { MimeTypeUtil } from "../utils/mimetype" ;
65import { parsePathLike } from "../utils/path-like" ;
76import { assertCreateObjectResponse } from "../validation/assertions/create" ;
87import { assertListObjectsResponse } from "../validation/assertions/list" ;
@@ -16,7 +15,7 @@ export class ObjectsManager {
1615 *
1716 * @example
1817 * ```js
19- * const objects = await blob.objects.list();
18+ * blob.objects.list();
2019 * ```
2120 */
2221 async list ( ) {
@@ -28,17 +27,19 @@ export class ObjectsManager {
2827 return [ ] ;
2928 }
3029
31- return list . objects . map (
32- ( object ) =>
33- new BlobObject ( {
34- idOrUrl : object . id ,
35- size : object . size ,
36- createdAt : new Date ( object . created_at ) ,
37- expiresAt : object . expires_at
38- ? new Date ( object . expires_at )
39- : undefined ,
40- } ) ,
41- ) ;
30+ return list . objects . map ( ( objectData ) => {
31+ const createdAt = new Date ( objectData . created_at ) ;
32+ const expiresAt = objectData . expires_at
33+ ? new Date ( objectData . expires_at )
34+ : undefined ;
35+
36+ return new BlobObject ( {
37+ idOrUrl : objectData . id ,
38+ size : objectData . size ,
39+ createdAt,
40+ expiresAt,
41+ } ) ;
42+ } ) ;
4243 }
4344
4445 /**
@@ -48,27 +49,31 @@ export class ObjectsManager {
4849 *
4950 * @example
5051 * ```js
51- * await blob.objects.create({ file: "path/to/file.jpeg", name: "my_image" });
52+ * // Basic usage with absolute path
53+ * blob.objects.create({
54+ * file: "path/to/file.jpeg",
55+ * name: "my_image"
56+ * });
57+ *
58+ * // Advanced usage with Buffer
59+ * blob.objects.create({
60+ * file: Buffer.from("content"),
61+ * name: "my_image",
62+ * mimeType: "image/jpeg"
63+ * })
5264 * ```
5365 */
5466 async create ( object : CreateObjectType ) {
5567 const payload = createObjectPayloadSchema . parse ( object ) ;
5668 const file = await parsePathLike ( payload . file ) ;
57- const mimeType =
58- typeof object . file === "string"
59- ? MimeTypeUtil . fromExtension ( object . file . split ( "." ) [ 1 ] )
60- : object . mimeType ;
69+ const type = payload . mimeType || object . mimeType ;
6170
6271 const formData = new FormData ( ) ;
63- formData . append ( "file" , new Blob ( [ file ] , { type : mimeType } ) ) ;
72+ formData . append ( "file" , new Blob ( [ file ] , { type } ) ) ;
6473
6574 const { response } = await this . client . api . request < CreateObjectResponse > (
6675 "objects" ,
67- {
68- method : "POST" ,
69- body : formData ,
70- params : payload . params ,
71- } ,
76+ { method : "POST" , body : formData , params : payload . params } ,
7277 ) ;
7378
7479 const objectData = assertCreateObjectResponse ( response ) ;
@@ -86,15 +91,16 @@ export class ObjectsManager {
8691 *
8792 * @example
8893 * ```js
89- * await blob.objects.delete("ID/prefix/name1_xxx-xxx.mp4", "ID/prefix/name_xxx-xxx-xxx.png");
94+ * blob.objects.delete([
95+ * "userId/prefix/name1_xxx-xxx.mp4",
96+ * "userId/prefix/name_xxx-xxx-xxx.png"
97+ * ]);
9098 * ```
9199 */
92- async delete ( ...objects : string [ ] | string [ ] [ ] ) {
93- const ids = objects . flat ( ) ;
94-
100+ async delete ( objects : string [ ] ) {
95101 const { status } = await this . client . api . request ( "objects" , {
96102 method : "DELETE" ,
97- body : { objects : ids } ,
103+ body : { objects } ,
98104 } ) ;
99105
100106 return status === "success" ;
0 commit comments