forked from AlistGo/alist
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paths3.go
39 lines (34 loc) · 900 Bytes
/
s3.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package server
import (
"context"
"path"
"strings"
"github.com/alist-org/alist/v3/internal/conf"
"github.com/alist-org/alist/v3/server/common"
"github.com/alist-org/alist/v3/server/s3"
"github.com/gin-gonic/gin"
)
func S3(g *gin.RouterGroup) {
if !conf.Conf.S3.Enable {
g.Any("/*path", func(c *gin.Context) {
common.ErrorStrResp(c, "S3 server is not enabled", 403)
})
return
}
if conf.Conf.S3.Port != -1 {
g.Any("/*path", func(c *gin.Context) {
common.ErrorStrResp(c, "S3 server bound to single port", 403)
})
return
}
h, _ := s3.NewServer(context.Background())
g.Any("/*path", func(c *gin.Context) {
adjustedPath := strings.TrimPrefix(c.Request.URL.Path, path.Join(conf.URL.Path, "/s3"))
c.Request.URL.Path = adjustedPath
gin.WrapH(h)(c)
})
}
func S3Server(g *gin.RouterGroup) {
h, _ := s3.NewServer(context.Background())
g.Any("/*path", gin.WrapH(h))
}