Skip to content

Commit

Permalink
fix(storage): various typos, add content-type header (#25)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
jackmerrill authored Aug 9, 2023
1 parent 0111c50 commit 4ebd9f1
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ const (
defaultLimit = 100
defaultOffset = 0
defaultFileCacheControl = "3600"
defaultFileContent = "text/pain;charset=UTF-8"
defaultFileContent = "text/plain;charset=UTF-8"
defaultFileUpsert = false
defaultSortColumn = "name"
defaultSortOrder = "asc"
Expand Down Expand Up @@ -389,17 +389,19 @@ func (f *file) GetPublicUrl(filePath string) SignedUrlResponse {
// Remove deletes a file object
func (f *file) Remove(filePaths []string) FileResponse {
_json, _ := json.Marshal(map[string]interface{}{
"prefixex": filePaths,
"prefixes": filePaths,
})

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

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

req.Header.Set("Content-Type", "application/json")

client := &http.Client{}
res, err := client.Do(req)
if err != nil {
Expand All @@ -411,12 +413,16 @@ func (f *file) Remove(filePaths []string) FileResponse {
panic(err)
}

var response FileResponse
if err := json.Unmarshal(body, &response); err != nil {
panic(err)
if res.StatusCode != 200 {
var response FileResponse
if err := json.Unmarshal(body, &response); err != nil {
panic(err)
}

return response
}

return response
return FileResponse{}
}

// List list all file object
Expand Down

0 comments on commit 4ebd9f1

Please sign in to comment.