chore: support s3 proxy

This commit is contained in:
hstyi
2025-06-25 17:30:40 +08:00
committed by hstyi
parent cee0c863f8
commit 00dfb4ce39
2 changed files with 36 additions and 1 deletions

View File

@@ -3,7 +3,7 @@ plugins {
}
project.version = "0.0.2"
project.version = "0.0.3"
dependencies {

View File

@@ -1,12 +1,18 @@
package app.termora.plugins.s3
import app.termora.AuthenticationType
import app.termora.DynamicIcon
import app.termora.Icons
import app.termora.ProxyType
import app.termora.protocol.PathHandler
import app.termora.protocol.PathHandlerRequest
import app.termora.protocol.TransferProtocolProvider
import io.minio.MinioClient
import okhttp3.*
import org.apache.commons.lang3.StringUtils
import java.net.InetSocketAddress
import java.net.Proxy
import java.time.Duration
class S3ProtocolProvider private constructor() : TransferProtocolProvider {
@@ -32,6 +38,35 @@ class S3ProtocolProvider private constructor() : TransferProtocolProvider {
if (StringUtils.isNotBlank(region)) {
builder.region(region)
}
if (host.proxy.type != ProxyType.No) {
val httpClient = OkHttpClient.Builder()
.connectTimeout(Duration.ofSeconds(10))
.callTimeout(Duration.ofSeconds(60))
.writeTimeout(Duration.ofSeconds(60))
.readTimeout(Duration.ofSeconds(60))
if (host.proxy.type == ProxyType.HTTP) {
httpClient.proxy(Proxy(Proxy.Type.HTTP, InetSocketAddress(host.proxy.host, host.proxy.port)))
} else if (host.proxy.type == ProxyType.SOCKS5) {
httpClient.proxy(Proxy(Proxy.Type.SOCKS, InetSocketAddress(host.proxy.host, host.proxy.port)))
}
if (host.proxy.authenticationType != AuthenticationType.No) {
httpClient.proxyAuthenticator(object : Authenticator {
override fun authenticate(route: Route?, response: Response): Request? {
val credential = Credentials.basic(host.proxy.username, host.proxy.password)
return response.request.newBuilder()
.header("Proxy-Authorization", credential)
.build()
}
})
}
builder.httpClient(httpClient.build(), true)
}
// val delimiter = host.options.extras["s3.delimiter"] ?: "/"
val defaultPath = host.options.sftpDefaultDirectory
val minioClient = builder.build()