feat(makhno): support string-based APN configuration

Allow APN configuration to be specified as a single string value
in addition to the existing boolean + host format. When 'apn' is
a string, it is used as the host and enabled is set automatically.
This commit is contained in:
baliasnyifeliks 2026-02-04 14:06:39 +02:00
parent e846ce65b3
commit 43808b819f
2 changed files with 21 additions and 6 deletions

View File

@ -17,14 +17,26 @@ namespace Shared.Engine
if (conf == null) if (conf == null)
return false; return false;
if (!conf.TryGetValue("apn", out var apnToken) || apnToken?.Type != JTokenType.Boolean) if (!conf.TryGetValue("apn", out var apnToken) || apnToken == null)
return false; return false;
if (apnToken.Type == JTokenType.Boolean)
{
enabled = apnToken.Value<bool>(); enabled = apnToken.Value<bool>();
host = conf.Value<string>("apn_host"); host = conf.Value<string>("apn_host");
return true; return true;
} }
if (apnToken.Type == JTokenType.String)
{
host = apnToken.Value<string>();
enabled = !string.IsNullOrWhiteSpace(host);
return true;
}
return false;
}
public static void ApplyInitConf(bool enabled, string host, BaseSettings init) public static void ApplyInitConf(bool enabled, string host, BaseSettings init)
{ {
if (init == null) if (init == null)

View File

@ -54,8 +54,11 @@ namespace Makhno
}; };
var conf = ModuleInvoke.Conf("Makhno", Makhno); var conf = ModuleInvoke.Conf("Makhno", Makhno);
bool hasApn = ApnHelper.TryGetInitConf(conf, out bool apnEnabled, out string apnHost); bool hasApn = ApnHelper.TryGetInitConf(conf, out bool apnEnabled, out string apnHost);
if (hasApn)
{
conf.Remove("apn"); conf.Remove("apn");
conf.Remove("apn_host"); conf.Remove("apn_host");
}
Makhno = conf.ToObject<OnlinesSettings>(); Makhno = conf.ToObject<OnlinesSettings>();
if (hasApn) if (hasApn)
ApnHelper.ApplyInitConf(apnEnabled, apnHost, Makhno); ApnHelper.ApplyInitConf(apnEnabled, apnHost, Makhno);