From 640c16d8dcff57c57ad01765bf8ff6bda61ce986 Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Tue, 19 Nov 2024 10:45:01 +0800 Subject: [PATCH] Improve Fmt --- .../main/java/com/v2ray/ang/fmt/FmtBase.kt | 31 +++++++++++++++++++ .../main/java/com/v2ray/ang/fmt/TrojanFmt.kt | 25 +-------------- .../main/java/com/v2ray/ang/fmt/VlessFmt.kt | 28 +---------------- .../main/java/com/v2ray/ang/fmt/VmessFmt.kt | 18 +---------- 4 files changed, 34 insertions(+), 68 deletions(-) diff --git a/V2rayNG/app/src/main/java/com/v2ray/ang/fmt/FmtBase.kt b/V2rayNG/app/src/main/java/com/v2ray/ang/fmt/FmtBase.kt index 1b07a8ad..7f4e243d 100644 --- a/V2rayNG/app/src/main/java/com/v2ray/ang/fmt/FmtBase.kt +++ b/V2rayNG/app/src/main/java/com/v2ray/ang/fmt/FmtBase.kt @@ -1,5 +1,6 @@ package com.v2ray.ang.fmt +import com.v2ray.ang.AppConfig import com.v2ray.ang.dto.NetworkType import com.v2ray.ang.dto.ProfileItem import com.v2ray.ang.extension.isNotNullEmpty @@ -29,6 +30,36 @@ open class FmtBase { .associate { it.split("=").let { (k, v) -> k to Utils.urlDecode(v) } } } + fun getItemFormQuery(config: ProfileItem, queryParam: Map, allowInsecure: Boolean) { + config.network = queryParam["type"] ?: "tcp" + config.headerType = queryParam["headerType"] + config.host = queryParam["host"] + config.path = queryParam["path"] + + config.seed = queryParam["seed"] + config.quicSecurity = queryParam["quicSecurity"] + config.quicKey = queryParam["key"] + config.mode = queryParam["mode"] + config.serviceName = queryParam["serviceName"] + config.authority = queryParam["authority"] + config.xhttpMode = queryParam["mode"] + config.xhttpExtra = queryParam["extra"] + + config.security = queryParam["security"] + config.insecure = if (queryParam["allowInsecure"].isNullOrEmpty()) { + allowInsecure + } else { + queryParam["allowInsecure"].orEmpty() == "1" + } + config.sni = queryParam["sni"] + config.fingerPrint = queryParam["fp"] + config.alpn = queryParam["alpn"] + config.publicKey = queryParam["pbk"] + config.shortId = queryParam["sid"] + config.spiderX = queryParam["spx"] + config.flow = queryParam["flow"] + } + fun getQueryDic(config: ProfileItem): HashMap { val dicQuery = HashMap() dicQuery["security"] = config.security?.ifEmpty { "none" }.orEmpty() diff --git a/V2rayNG/app/src/main/java/com/v2ray/ang/fmt/TrojanFmt.kt b/V2rayNG/app/src/main/java/com/v2ray/ang/fmt/TrojanFmt.kt index 59c0ddb1..d5aea773 100644 --- a/V2rayNG/app/src/main/java/com/v2ray/ang/fmt/TrojanFmt.kt +++ b/V2rayNG/app/src/main/java/com/v2ray/ang/fmt/TrojanFmt.kt @@ -28,31 +28,8 @@ object TrojanFmt : FmtBase() { } else { val queryParam = getQueryParam(uri) - config.network = queryParam["type"] ?: "tcp" - config.headerType = queryParam["headerType"] - config.host = queryParam["host"] - config.path = queryParam["path"] - - config.seed = queryParam["seed"] - config.quicSecurity = queryParam["quicSecurity"] - config.quicKey = queryParam["key"] - config.mode = queryParam["mode"] - config.serviceName = queryParam["serviceName"] - config.authority = queryParam["authority"] - + getItemFormQuery(config, queryParam, allowInsecure) config.security = queryParam["security"] ?: AppConfig.TLS - config.insecure = if (queryParam["allowInsecure"].isNullOrEmpty()) { - allowInsecure - } else { - queryParam["allowInsecure"].orEmpty() == "1" - } - config.sni = queryParam["sni"] - config.fingerPrint = queryParam["fp"] - config.alpn = queryParam["alpn"] - config.publicKey = queryParam["pbk"] - config.shortId = queryParam["sid"] - config.spiderX = queryParam["spx"] - config.flow = queryParam["flow"] } return config diff --git a/V2rayNG/app/src/main/java/com/v2ray/ang/fmt/VlessFmt.kt b/V2rayNG/app/src/main/java/com/v2ray/ang/fmt/VlessFmt.kt index e4e3bd55..07e80ed8 100644 --- a/V2rayNG/app/src/main/java/com/v2ray/ang/fmt/VlessFmt.kt +++ b/V2rayNG/app/src/main/java/com/v2ray/ang/fmt/VlessFmt.kt @@ -26,33 +26,7 @@ object VlessFmt : FmtBase() { config.password = uri.userInfo config.method = queryParam["encryption"] ?: "none" - config.network = queryParam["type"] ?: "tcp" - config.headerType = queryParam["headerType"] - config.host = queryParam["host"] - config.path = queryParam["path"] - - config.seed = queryParam["seed"] - config.quicSecurity = queryParam["quicSecurity"] - config.quicKey = queryParam["key"] - config.mode = queryParam["mode"] - config.serviceName = queryParam["serviceName"] - config.authority = queryParam["authority"] - config.xhttpMode = queryParam["mode"] - config.xhttpExtra = queryParam["extra"] - - config.security = queryParam["security"] - config.insecure = if (queryParam["allowInsecure"].isNullOrEmpty()) { - allowInsecure - } else { - queryParam["allowInsecure"].orEmpty() == "1" - } - config.sni = queryParam["sni"] - config.fingerPrint = queryParam["fp"] - config.alpn = queryParam["alpn"] - config.publicKey = queryParam["pbk"] - config.shortId = queryParam["sid"] - config.spiderX = queryParam["spx"] - config.flow = queryParam["flow"] + getItemFormQuery(config, queryParam, allowInsecure) return config } diff --git a/V2rayNG/app/src/main/java/com/v2ray/ang/fmt/VmessFmt.kt b/V2rayNG/app/src/main/java/com/v2ray/ang/fmt/VmessFmt.kt index 1fc7a66f..2f2b8562 100644 --- a/V2rayNG/app/src/main/java/com/v2ray/ang/fmt/VmessFmt.kt +++ b/V2rayNG/app/src/main/java/com/v2ray/ang/fmt/VmessFmt.kt @@ -137,23 +137,7 @@ object VmessFmt : FmtBase() { config.password = uri.userInfo config.method = AppConfig.DEFAULT_SECURITY - config.network = NetworkType.fromString(queryParam["type"]).name - config.headerType = queryParam["headerType"] - config.host = queryParam["host"] - config.path = queryParam["path"] - - config.seed = queryParam["seed"] - config.quicSecurity = queryParam["quicSecurity"] - config.quicKey = queryParam["key"] - config.mode = queryParam["mode"] - config.serviceName = queryParam["serviceName"] - config.authority = queryParam["authority"] - - config.security = queryParam["security"] - config.insecure = if ((queryParam["allowInsecure"].orEmpty()) == "1") true else allowInsecure - config.sni = queryParam["sni"] - config.fingerPrint = queryParam["fp"] - config.alpn = queryParam["alpn"] + getItemFormQuery(config, queryParam, allowInsecure) return config }