feat: stand-alone port s3 server (#6242)
* feat: single port s3 server * fix: unable to PUT files if not in root dir
This commit is contained in:
22
server/s3.go
22
server/s3.go
@ -6,20 +6,25 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/alist-org/alist/v3/internal/conf"
|
||||
"github.com/alist-org/alist/v3/internal/setting"
|
||||
"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 !setting.GetBool(conf.S3Enabled) {
|
||||
if !conf.Conf.S3.Enable {
|
||||
g.Any("/*path", func(c *gin.Context) {
|
||||
common.ErrorStrResp(c, "S3 server is not enabled", 403)
|
||||
})
|
||||
return
|
||||
}
|
||||
h, _ := s3.NewServer(context.Background(), []string{setting.GetStr(conf.S3AccessKeyId) + "," + setting.GetStr(conf.S3SecretAccessKey)})
|
||||
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"))
|
||||
@ -27,3 +32,14 @@ func S3(g *gin.RouterGroup) {
|
||||
gin.WrapH(h)(c)
|
||||
})
|
||||
}
|
||||
|
||||
func S3Server(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
|
||||
}
|
||||
h, _ := s3.NewServer(context.Background())
|
||||
g.Any("/*path", gin.WrapH(h))
|
||||
}
|
||||
|
Reference in New Issue
Block a user