2024-03-02 07:35:10 +00:00
|
|
|
// Credits: https://pkg.go.dev/github.com/rclone/rclone@v1.65.2/cmd/serve/s3
|
|
|
|
// Package s3 implements a fake s3 server for alist
|
|
|
|
package s3
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"math/rand"
|
|
|
|
"net/http"
|
|
|
|
|
2024-05-09 06:28:59 +00:00
|
|
|
"github.com/alist-org/gofakes3"
|
2024-03-02 07:35:10 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Make a new S3 Server to serve the remote
|
2024-03-24 07:16:00 +00:00
|
|
|
func NewServer(ctx context.Context) (h http.Handler, err error) {
|
2024-03-02 07:35:10 +00:00
|
|
|
var newLogger logger
|
|
|
|
faker := gofakes3.New(
|
|
|
|
newBackend(),
|
|
|
|
// gofakes3.WithHostBucket(!opt.pathBucketMode),
|
|
|
|
gofakes3.WithLogger(newLogger),
|
|
|
|
gofakes3.WithRequestID(rand.Uint64()),
|
|
|
|
gofakes3.WithoutVersioning(),
|
2024-03-24 07:16:00 +00:00
|
|
|
gofakes3.WithV4Auth(authlistResolver()),
|
2024-03-02 07:35:10 +00:00
|
|
|
gofakes3.WithIntegrityCheck(true), // Check Content-MD5 if supplied
|
|
|
|
)
|
|
|
|
|
|
|
|
return faker.Server(), nil
|
|
|
|
}
|