Skip to content

Commit

Permalink
Merge pull request #31 from damoxc/fix-index
Browse files Browse the repository at this point in the history
Fix empty object name error
  • Loading branch information
daichirata authored Mar 18, 2024
2 parents ef9ab67 + 29a2128 commit c556b25
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,23 @@ func wrapper(fn func(w http.ResponseWriter, r *http.Request)) http.HandlerFunc {
}

func fetchObjectAttrs(ctx context.Context, bucket, object string) (*storage.ObjectAttrs, error) {
var err error
var indexAppended bool
if object == "" && *defaultIndex != "" {
object, err = url.JoinPath(object, *defaultIndex)
if err != nil {
return nil, err
}
indexAppended = true
}

attrs, err := client.Bucket(bucket).Object(strings.TrimSuffix(object, "/")).Attrs(ctx)
if err != nil {
if errors.Is(err, storage.ErrObjectNotExist) {
if *defaultIndex == "" {
if *defaultIndex == "" || indexAppended {
return nil, err
}
object, err := url.JoinPath(object, *defaultIndex)
object, err = url.JoinPath(object, *defaultIndex)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit c556b25

Please sign in to comment.