feat(extension): Maven 仓库搜索器将使用全局代理下载扩展包.

改动后, 配置的全局代理将适用于 MavenRepositoryExtensionFinder.
This commit is contained in:
LamGC 2022-02-22 01:32:02 +08:00
parent 13472d952e
commit 692fe5b8f9
Signed by: LamGC
GPG Key ID: 6C5AE2A913941E1D
2 changed files with 16 additions and 2 deletions

View File

@ -7,6 +7,7 @@ import mu.KotlinLogging
import net.lamgc.scalabot.util.ArtifactSerializer
import net.lamgc.scalabot.util.ProxyTypeSerializer
import org.eclipse.aether.artifact.Artifact
import org.eclipse.aether.repository.Proxy
import org.telegram.telegrambots.bots.DefaultBotOptions
import java.io.File
import java.nio.charset.StandardCharsets
@ -58,7 +59,17 @@ internal data class ProxyConfig(
val type: DefaultBotOptions.ProxyType = DefaultBotOptions.ProxyType.NO_PROXY,
val host: String = "127.0.0.1",
val port: Int = 1080
)
) {
fun toAetherProxy(): Proxy? {
return if (type == DefaultBotOptions.ProxyType.HTTP) {
Proxy(Proxy.TYPE_HTTP, host, port)
} else {
null
}
}
}
internal data class MetricsConfig(
val enable: Boolean = false,

View File

@ -25,7 +25,10 @@ internal class ExtensionLoader(
private val finders: Set<ExtensionPackageFinder> = setOf(
FileNameFinder,
MavenMetaInformationFinder,
MavenRepositoryExtensionFinder(LocalRepository("${System.getProperty("user.home")}/.m2/repository"))
MavenRepositoryExtensionFinder(
LocalRepository("${System.getProperty("user.home")}/.m2/repository"),
proxy = Const.config.proxy.toAetherProxy()
)
)
fun getExtensions(): Set<LoadedExtensionEntry> {