lampac/SISI/Controllers/Ebalovo/RootController.cs
lampac-talks f843f04fd4 chore: initial commit 154.3
Signed-off-by: lampac-talks <lampac-talks@users.noreply.github.com>
2026-01-30 16:23:09 +03:00

34 lines
1.1 KiB
C#

using System.Net;
namespace SISI.Controllers.Ebalovo
{
public static class RootController
{
async public static ValueTask<string> goHost(string host, WebProxy proxy = null)
{
if (!Regex.IsMatch(host, "^https?://www\\."))
return host;
var hybridCache = IHybridCache.Get(null);
string backhost = "https://web.epalovo.com";
string memkey = $"ebalovo:gohost:{host}";
if (hybridCache.TryGetValue(memkey, out string _host, inmemory: true))
return _host;
_host = await Http.GetLocation(host, timeoutSeconds: 5, proxy: proxy, allowAutoRedirect: true);
if (_host != null && !Regex.IsMatch(_host, "^https?://www\\."))
{
_host = Regex.Replace(_host, "/$", "");
hybridCache.Set(memkey, _host, DateTime.Now.AddHours(1), inmemory: true);
return _host;
}
else
{
hybridCache.Set(memkey, backhost, DateTime.Now.AddMinutes(20), inmemory: true);
return backhost;
}
}
}
}