added support for multiple custom configs in subscriptions + remarks

Accepting both single config and multiple configs i.e:
{customConfig} or [{customConfig1}, {customConfig2} ...]

Furtheremore added an optional 'remarks' field to v2rayConfig class to keep remote customConfig name.
This commit is contained in:
Vahid Farid committed 2024-02-09 20:25:51 +03:30
1 parent 52273db482
commit cdaff4da06
2 files changed
+40 -8

No files matched your search

@@ -7,6 +7,7 @@ import android.text.TextUtils
import android.util.Log
import androidx.preference.PreferenceManager
import com.google.gson.Gson
import com.google.gson.GsonBuilder
import com.tencent.mmkv.MMKV
import com.v2ray.ang.AppConfig
import com.v2ray.ang.AppConfig.ANG_CONFIG
@@ -985,13 +986,32 @@ object AngConfigManager {
&& server.contains("outbounds")
&& server.contains("routing")
) {
val config = ServerConfig.create(EConfigType.CUSTOM)
config.remarks = System.currentTimeMillis().toString()
config.subscriptionId = subid
config.fullConfig = Gson().fromJson(server, V2rayConfig::class.java)
val key = MmkvManager.encodeServerConfig("", config)
serverRawStorage?.encode(key, server)
return 1
val gson = GsonBuilder().setPrettyPrinting().create()
val serverList: Array<V2rayConfig> = Gson().fromJson(server, Array<V2rayConfig>::class.java)
if (serverList.size > 0) {
var count = 0
for (srv in serverList) {
if (srv.inbounds != null && srv.outbounds != null && srv.routing != null) {
var config = ServerConfig.create(EConfigType.CUSTOM)
config.remarks = srv.remarks ?: "%04d-".format(count + 1) + System.currentTimeMillis().toString()
config.subscriptionId = subid
config.fullConfig = srv
var key = MmkvManager.encodeServerConfig("", config)
serverRawStorage?.encode(key, gson.toJson(srv))
count = count + 1
}
}
return count
} else { // For compatibility
val config = ServerConfig.create(EConfigType.CUSTOM)
config.subscriptionId = subid
config.fullConfig = Gson().fromJson(server, V2rayConfig::class.java)
config.remarks = System.currentTimeMillis().toString()
// config.remarks = config.fullConfig?.remarks ?: System.currentTimeMillis().toString()
val key = MmkvManager.encodeServerConfig("", config)
serverRawStorage?.encode(key, server)
return 1
}
} else {
return 0
}