Skip to content

Commit 4ebd9f1

Browse files
authored
fix(storage): various typos, add content-type header (nedpals#25)
* fix(storage): defaultFileContent typo * fix(storage): another typo, add content-type header * fix(storage): return delete response if not status 200 * fix(storage): headers to header
1 parent 0111c50 commit 4ebd9f1

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

storage.go

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ const (
244244
defaultLimit = 100
245245
defaultOffset = 0
246246
defaultFileCacheControl = "3600"
247-
defaultFileContent = "text/pain;charset=UTF-8"
247+
defaultFileContent = "text/plain;charset=UTF-8"
248248
defaultFileUpsert = false
249249
defaultSortColumn = "name"
250250
defaultSortOrder = "asc"
@@ -389,17 +389,19 @@ func (f *file) GetPublicUrl(filePath string) SignedUrlResponse {
389389
// Remove deletes a file object
390390
func (f *file) Remove(filePaths []string) FileResponse {
391391
_json, _ := json.Marshal(map[string]interface{}{
392-
"prefixex": filePaths,
392+
"prefixes": filePaths,
393393
})
394394

395395
reqURL := fmt.Sprintf("%s/%s/object/%s", f.storage.client.BaseURL, StorageEndpoint, f.BucketId)
396-
req, err := http.NewRequest(http.MethodPost, reqURL, bytes.NewBuffer(_json))
396+
req, err := http.NewRequest(http.MethodDelete, reqURL, bytes.NewBuffer(_json))
397397
if err != nil {
398398
panic(err)
399399
}
400400

401401
injectAuthorizationHeader(req, f.storage.client.apiKey)
402402

403+
req.Header.Set("Content-Type", "application/json")
404+
403405
client := &http.Client{}
404406
res, err := client.Do(req)
405407
if err != nil {
@@ -411,12 +413,16 @@ func (f *file) Remove(filePaths []string) FileResponse {
411413
panic(err)
412414
}
413415

414-
var response FileResponse
415-
if err := json.Unmarshal(body, &response); err != nil {
416-
panic(err)
416+
if res.StatusCode != 200 {
417+
var response FileResponse
418+
if err := json.Unmarshal(body, &response); err != nil {
419+
panic(err)
420+
}
421+
422+
return response
417423
}
418424

419-
return response
425+
return FileResponse{}
420426
}
421427

422428
// List list all file object

0 commit comments

Comments
 (0)