@@ -6,24 +6,40 @@ import (
66 "strings"
77
88 "github.com/alist-org/alist/v3/internal/conf"
9- "github.com/alist-org/alist/v3/internal/setting"
109 "github.com/alist-org/alist/v3/server/common"
1110 "github.com/alist-org/alist/v3/server/s3"
1211 "github.com/gin-gonic/gin"
1312)
1413
1514func S3 (g * gin.RouterGroup ) {
16- if ! setting . GetBool ( conf .S3Enabled ) {
15+ if ! conf .Conf . S3 . Enable {
1716 g .Any ("/*path" , func (c * gin.Context ) {
1817 common .ErrorStrResp (c , "S3 server is not enabled" , 403 )
1918 })
2019 return
2120 }
22- h , _ := s3 .NewServer (context .Background (), []string {setting .GetStr (conf .S3AccessKeyId ) + "," + setting .GetStr (conf .S3SecretAccessKey )})
21+ if conf .Conf .S3 .Port != - 1 {
22+ g .Any ("/*path" , func (c * gin.Context ) {
23+ common .ErrorStrResp (c , "S3 server bound to single port" , 403 )
24+ })
25+ return
26+ }
27+ h , _ := s3 .NewServer (context .Background ())
2328
2429 g .Any ("/*path" , func (c * gin.Context ) {
2530 adjustedPath := strings .TrimPrefix (c .Request .URL .Path , path .Join (conf .URL .Path , "/s3" ))
2631 c .Request .URL .Path = adjustedPath
2732 gin .WrapH (h )(c )
2833 })
2934}
35+
36+ func S3Server (g * gin.RouterGroup ) {
37+ if ! conf .Conf .S3 .Enable {
38+ g .Any ("/*path" , func (c * gin.Context ) {
39+ common .ErrorStrResp (c , "S3 server is not enabled" , 403 )
40+ })
41+ return
42+ }
43+ h , _ := s3 .NewServer (context .Background ())
44+ g .Any ("/*path" , gin .WrapH (h ))
45+ }
0 commit comments