53 lines
1.1 KiB
Go
53 lines
1.1 KiB
Go
package bucket
|
|
|
|
import (
|
|
"encoding/xml"
|
|
"fmt"
|
|
"net/url"
|
|
|
|
"github.com/minio/minio-go/v6"
|
|
"github.com/minio/minio-go/v6/pkg/s3utils"
|
|
)
|
|
|
|
type list struct {
|
|
prefix string
|
|
maxKeys int
|
|
startAfter string
|
|
}
|
|
|
|
func newList(prefix string, maxKeys int, startAfter string) list {
|
|
return list{
|
|
prefix: prefix,
|
|
maxKeys: maxKeys,
|
|
startAfter: startAfter,
|
|
}
|
|
}
|
|
|
|
func (l list) Path() *url.URL {
|
|
params := make(url.Values)
|
|
params.Set("list-type", "2")
|
|
params.Set("metadata", "true")
|
|
params.Set("encoding-type", "url")
|
|
params.Set("prefix", l.prefix)
|
|
params.Set("delimiter", "")
|
|
params.Set("max-keys", fmt.Sprintf("%d", l.maxKeys))
|
|
params.Set("start-after", l.startAfter)
|
|
return &url.URL{
|
|
Path: "/",
|
|
RawQuery: s3utils.QueryEncode(params),
|
|
}
|
|
}
|
|
|
|
func BucketListUnmarshal(buf []byte) ([]Photo, error) {
|
|
list := minio.ListBucketV2Result{}
|
|
err := xml.Unmarshal(buf, &list)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
photos := make([]Photo, 0, len(list.Contents))
|
|
for _, o := range list.Contents {
|
|
photos = append(photos, Photo(o.Key))
|
|
}
|
|
return photos, nil
|
|
}
|