@@ -51,11 +51,20 @@ func (c *Client) GetBucket(id string) (Bucket, BucketResponseError) {
51
51
}
52
52
53
53
func (c * Client ) CreateBucket (id string , options BucketOptions ) (Bucket , BucketResponseError ) {
54
- jsonBody , _ := json . Marshal ( map [string ]interface {}{
54
+ bodyData := map [string ]interface {}{
55
55
"id" : id ,
56
56
"name" : id ,
57
57
"public" : options .Public ,
58
- })
58
+ }
59
+ // We only set the file size limit if it's not empty
60
+ if len (options .FileSizeLimit ) > 0 {
61
+ bodyData ["file_size_limit" ] = options .FileSizeLimit
62
+ }
63
+ // We only set the allowed mime types if it's not empty
64
+ if len (options .AllowedMimeTypes ) > 0 {
65
+ bodyData ["allowed_mime_types" ] = options .AllowedMimeTypes
66
+ }
67
+ jsonBody , _ := json .Marshal (bodyData )
59
68
res , err := c .session .Post (c .clientTransport .baseUrl .String ()+ "/bucket" ,
60
69
"application/json" ,
61
70
bytes .NewBuffer (jsonBody ))
@@ -74,11 +83,20 @@ func (c *Client) CreateBucket(id string, options BucketOptions) (Bucket, BucketR
74
83
}
75
84
76
85
func (c * Client ) UpdateBucket (id string , options BucketOptions ) (MessageResponse , BucketResponseError ) {
77
- jsonBody , _ := json . Marshal ( map [string ]interface {}{
86
+ bodyData := map [string ]interface {}{
78
87
"id" : id ,
79
88
"name" : id ,
80
89
"public" : options .Public ,
81
- })
90
+ }
91
+ // We only set the file size limit if it's not empty
92
+ if len (options .FileSizeLimit ) > 0 {
93
+ bodyData ["file_size_limit" ] = options .FileSizeLimit
94
+ }
95
+ // We only set the allowed mime types if it's not empty
96
+ if len (options .AllowedMimeTypes ) > 0 {
97
+ bodyData ["allowed_mime_types" ] = options .AllowedMimeTypes
98
+ }
99
+ jsonBody , _ := json .Marshal (bodyData )
82
100
request , err := http .NewRequest (http .MethodPut , c .clientTransport .baseUrl .String ()+ "/bucket/" + id , bytes .NewBuffer (jsonBody ))
83
101
res , err := c .session .Do (request )
84
102
if err != nil {
@@ -138,14 +156,18 @@ type BucketResponseError struct {
138
156
}
139
157
140
158
type Bucket struct {
141
- Id string `json:"id"`
142
- Name string `json:"name"`
143
- Owner string `json:"owner"`
144
- Public bool `json:"public"`
145
- CreatedAt string `json:"created_at"`
146
- UpdatedAt string `json:"updated_at"`
159
+ Id string `json:"id"`
160
+ Name string `json:"name"`
161
+ Owner string `json:"owner"`
162
+ Public bool `json:"public"`
163
+ FileSizeLimit string `json:"file_size_limit"`
164
+ AllowedMimeTypes []string `json:"allowed_mine_types"`
165
+ CreatedAt string `json:"created_at"`
166
+ UpdatedAt string `json:"updated_at"`
147
167
}
148
168
149
169
type BucketOptions struct {
150
- Public bool
170
+ Public bool
171
+ FileSizeLimit string
172
+ AllowedMimeTypes []string
151
173
}
0 commit comments