@@ -32,6 +32,8 @@ type minioClient struct {
32
32
BucketName string
33
33
Source string
34
34
EndPoint string
35
+ Protocol string
36
+ FrontBase string
35
37
}
36
38
37
39
func (m * MinIO ) Upload (ctx context.Context , fileHeader * multipart.FileHeader ) (* dto.AttachmentDTO , error ) {
@@ -41,7 +43,7 @@ func (m *MinIO) Upload(ctx context.Context, fileHeader *multipart.FileHeader) (*
41
43
}
42
44
43
45
fd , err := newURLFileDescriptor (
44
- withBaseURL (minioClientInstance .EndPoint + "/" + minioClientInstance .BucketName ),
46
+ withBaseURL (minioClientInstance .Protocol + minioClientInstance . EndPoint + "/" + minioClientInstance .BucketName ),
45
47
withSubURLPath (minioClientInstance .Source ),
46
48
withShouldRenameURLOption (commonRenamePredicateFunc (ctx , consts .AttachmentTypeMinIO )),
47
49
withOriginalNameURLOption (fileHeader .Filename ),
@@ -103,14 +105,17 @@ func (m *MinIO) GetFilePath(ctx context.Context, relativePath string) (string, e
103
105
if err != nil {
104
106
return "" , err
105
107
}
106
- base := minioClientInstance .EndPoint + "/" + minioClientInstance .BucketName
108
+ base := minioClientInstance .Protocol + minioClientInstance .EndPoint + "/" + minioClientInstance .BucketName
109
+ if minioClientInstance .FrontBase != "" {
110
+ base = minioClientInstance .FrontBase
111
+ }
107
112
fullPath , _ := url .JoinPath (base , relativePath )
108
113
fullPath , _ = url .PathUnescape (fullPath )
109
114
return fullPath , nil
110
115
}
111
116
112
117
func (m * MinIO ) getMinioClient (ctx context.Context ) (* minioClient , error ) {
113
- getClientProperty := func (propertyValue * string , property property.Property , e error ) error {
118
+ getClientProperty := func (propertyValue * string , property property.Property , allowEmpty bool , e error ) error {
114
119
if e != nil {
115
120
return e
116
121
}
@@ -122,25 +127,37 @@ func (m *MinIO) getMinioClient(ctx context.Context) (*minioClient, error) {
122
127
if ! ok {
123
128
return xerr .WithStatus (nil , xerr .StatusBadRequest ).WithErrMsgf ("wrong property type" )
124
129
}
125
- if strValue == "" {
130
+ if ! allowEmpty && strValue == "" {
126
131
return xerr .WithStatus (nil , xerr .StatusInternalServerError ).WithMsg ("property not found: " + property .KeyValue )
127
132
}
128
133
* propertyValue = strValue
129
134
return nil
130
135
}
131
- var endPoint , bucketName , accessKey , accessSecret , source , region string
132
- err := getClientProperty (& endPoint , property .MinioEndpoint , nil )
133
- err = getClientProperty (& bucketName , property .MinioBucketName , err )
134
- err = getClientProperty (& accessKey , property .MinioAccessKey , err )
135
- err = getClientProperty (& accessSecret , property .MinioAccessSecret , err )
136
- err = getClientProperty (& source , property .MinioSource , err )
137
- err = getClientProperty (& region , property .MinioRegion , err )
136
+ var endPoint , bucketName , accessKey , accessSecret , protocol , source , region , frontBase string
137
+ err := getClientProperty (& endPoint , property .MinioEndpoint , false , nil )
138
+ err = getClientProperty (& bucketName , property .MinioBucketName , false , err )
139
+ err = getClientProperty (& accessKey , property .MinioAccessKey , false , err )
140
+ err = getClientProperty (& accessSecret , property .MinioAccessSecret , false , err )
141
+ err = getClientProperty (& protocol , property .MinioProtocol , false , err )
142
+ err = getClientProperty (& source , property .MinioSource , true , err )
143
+ err = getClientProperty (& region , property .MinioRegion , true , err )
144
+ err = getClientProperty (& frontBase , property .MinioFrontBase , true , err )
138
145
if err != nil {
139
146
return nil , err
140
147
}
148
+ secure := func () bool {
149
+ switch protocol {
150
+ case "https://" :
151
+ return true
152
+ case "http://" :
153
+ return false
154
+ default :
155
+ return true
156
+ }
157
+ }()
141
158
client , err := minio .New (endPoint , & minio.Options {
142
159
Creds : credentials .NewStaticV4 (accessKey , accessSecret , "" ),
143
- Secure : true ,
160
+ Secure : secure ,
144
161
Region : region ,
145
162
})
146
163
if err != nil {
@@ -153,5 +170,7 @@ func (m *MinIO) getMinioClient(ctx context.Context) (*minioClient, error) {
153
170
minioClientInstance .BucketName = bucketName
154
171
minioClientInstance .Source = source
155
172
minioClientInstance .EndPoint = endPoint
173
+ minioClientInstance .Protocol = protocol
174
+ minioClientInstance .FrontBase = frontBase
156
175
return minioClientInstance , nil
157
176
}
0 commit comments