diff --git a/JacRed/ModInit.cs b/JacRed/ModInit.cs index d2d4967b..8c9cd1f4 100644 --- a/JacRed/ModInit.cs +++ b/JacRed/ModInit.cs @@ -27,16 +27,26 @@ public static ModInit conf if (cacheconf.Item2 != lastWriteTime) { + var jss = new JsonSerializerSettings { Error = (se, ev) => + { + ev.ErrorContext.Handled = true; + Console.WriteLine("module/JacRed.conf - " + ev.ErrorContext.Error + "\n\n"); + }}; + string json = File.ReadAllText("module/JacRed.conf"); + if (json.Contains("\"version\"")) { - cacheconf.Item1 = JsonConvert.DeserializeObject(json); + cacheconf.Item1 = JsonConvert.DeserializeObject(json, jss); } else { - cacheconf.Item1 = new ModInit() { Red = JsonConvert.DeserializeObject(json) }; + cacheconf.Item1 = new ModInit() { Red = JsonConvert.DeserializeObject(json, jss) }; } + if (cacheconf.Item1 == null) + cacheconf.Item1 = new ModInit(); + cacheconf.Item2 = lastWriteTime; } diff --git a/Online/OnlineApi.cs b/Online/OnlineApi.cs index c5ef6cc0..80e3739e 100644 --- a/Online/OnlineApi.cs +++ b/Online/OnlineApi.cs @@ -416,7 +416,7 @@ async Task checkSearch(ConcurrentBag<(string code, int index, bool work)> links, string res = await HttpClient.Get($"http://{AppInit.conf.localhost}:{AppInit.conf.listenport}/lite/{uri}{(uri.Contains("?") ? "&" : "?")}id={id}&imdb_id={imdb_id}&kinopoisk_id={kinopoisk_id}&title={HttpUtility.UrlEncode(title)}&original_title={HttpUtility.UrlEncode(original_title)}&original_language={original_language}&source={source}&year={year}&serial={serial}&account_email={HttpUtility.UrlEncode(account_email)}&checksearch=true", timeoutSeconds: 10, addHeaders: new List<(string name, string val)>() { - ("Host", host) + ("xhost", host) }); bool work = !string.IsNullOrWhiteSpace(res) && res.Contains("data-json="); diff --git a/SISI/BookmarkController.cs b/SISI/BookmarkController.cs index 1db1c06d..311c0d3c 100644 --- a/SISI/BookmarkController.cs +++ b/SISI/BookmarkController.cs @@ -37,13 +37,15 @@ string getvideLink(PlaylistItem pl) return $"{host}/{pl.bookmark.site}/vidosik?uri={HttpUtility.UrlEncode(pl.bookmark.href)}"; } + string localhost = $"http://{AppInit.conf.localhost}:{AppInit.conf.listenport}"; + return new JsonResult(new { list = bookmarks.Skip((pg * pageSize) - pageSize).Take(pageSize).Select(pl => new { pl.name, video = getvideLink(pl), - picture = HostImgProxy(0, AppInit.conf.sisi.heightPicture, pl.bookmark.image.StartsWith("bookmarks/") ? $"{host}/{pl.bookmark.image}" : pl.bookmark.image), + picture = HostImgProxy(0, AppInit.conf.sisi.heightPicture, pl.bookmark.image.StartsWith("bookmarks/") ? $"{localhost}/{pl.bookmark.image}" : pl.bookmark.image), pl.time, pl.json, pl.quality, diff --git a/Shared/AppInit.cs b/Shared/AppInit.cs index e8c6c1fa..2d99f870 100644 --- a/Shared/AppInit.cs +++ b/Shared/AppInit.cs @@ -29,7 +29,16 @@ public static AppInit conf if (cacheconf.Item2 != lastWriteTime) { - cacheconf.Item1 = JsonConvert.DeserializeObject(File.ReadAllText("init.conf")); + var jss = new JsonSerializerSettings { Error = (se, ev) => + { + ev.ErrorContext.Handled = true; + Console.WriteLine("init.conf - " + ev.ErrorContext.Error + "\n\n"); + }}; + + cacheconf.Item1 = JsonConvert.DeserializeObject(File.ReadAllText("init.conf"), jss); + if (cacheconf.Item1 == null) + cacheconf.Item1 = new AppInit(); + cacheconf.Item2 = lastWriteTime; if (cacheconf.Item1 != null) @@ -71,7 +80,16 @@ public static AppInit conf } } - public static string Host(HttpContext httpContext) => $"{httpContext.Request.Scheme}://{(string.IsNullOrWhiteSpace(conf.listenhost) ? httpContext.Request.Host.Value : conf.listenhost)}"; + public static string Host(HttpContext httpContext) + { + if (!string.IsNullOrWhiteSpace(conf.listenhost)) + return $"{httpContext.Request.Scheme}://{conf.listenhost}"; + + if (httpContext.Request.Headers.TryGetValue("xhost", out var xhost)) + return $"{httpContext.Request.Scheme}://{xhost}"; + + return $"{httpContext.Request.Scheme}://{httpContext.Request.Host.Value}"; + } #endregion #region modules @@ -81,9 +99,18 @@ static AppInit() { if (File.Exists("module/manifest.json")) { - modules = new List(); + var jss = new JsonSerializerSettings { Error = (se, ev) => + { + ev.ErrorContext.Handled = true; + Console.WriteLine("module/manifest.json - " + ev.ErrorContext.Error + "\n\n"); + }}; - foreach (var mod in JsonConvert.DeserializeObject>(File.ReadAllText("module/manifest.json"))) + var mods = JsonConvert.DeserializeObject>(File.ReadAllText("module/manifest.json"), jss); + if (mods == null) + return; + + modules = new List(); + foreach (var mod in mods) { if (!mod.enable || mod.dll == "Jackett.dll") continue; diff --git a/Shared/Engine/BaseController.cs b/Shared/Engine/BaseController.cs index 8b75756e..1c049318 100644 --- a/Shared/Engine/BaseController.cs +++ b/Shared/Engine/BaseController.cs @@ -18,7 +18,7 @@ public class BaseController : Controller, IDisposable { IServiceScope serviceScope; - public static string appversion => "86"; + public static string appversion => "87"; public IMemoryCache memoryCache { get; private set; } diff --git a/TorrServer/ApiController.cs b/TorrServer/ApiController.cs index 1ae18b83..246c2053 100644 --- a/TorrServer/ApiController.cs +++ b/TorrServer/ApiController.cs @@ -149,28 +149,27 @@ async public Task TorAPI() return; } - using (HttpClient client = new HttpClient()) - { - client.Timeout = TimeSpan.FromSeconds(15); + MemoryStream mem = new MemoryStream(); + await HttpContext.Request.Body.CopyToAsync(mem); + string requestJson = Encoding.UTF8.GetString(mem.ToArray()); - #region Данные запроса - MemoryStream mem = new MemoryStream(); - await HttpContext.Request.Body.CopyToAsync(mem); - string requestJson = Encoding.UTF8.GetString(mem.ToArray()); - #endregion + if (requestJson.Contains("\"get\"")) + { + using (HttpClient client = new HttpClient()) + { + client.Timeout = TimeSpan.FromSeconds(15); + client.DefaultRequestHeaders.Add("Authorization", $"Basic {Engine.CORE.CrypTo.Base64($"ts:{ModInit.tspass}")}"); - var response = await client.PostAsync($"http://127.0.0.1:{ModInit.tsport}/settings", new StringContent("{\"action\":\"get\"}", Encoding.UTF8, "application/json")); - string settingsJson = await response.Content.ReadAsStringAsync(); + var response = await client.PostAsync($"http://127.0.0.1:{ModInit.tsport}/settings", new StringContent("{\"action\":\"get\"}", Encoding.UTF8, "application/json")); + string settingsJson = await response.Content.ReadAsStringAsync(); - if (requestJson.Trim() == "{\"action\":\"get\"}") - { await HttpContext.Response.WriteAsync(settingsJson); return; } - - await HttpContext.Response.WriteAsync(string.Empty); - return; } + + await HttpContext.Response.WriteAsync(string.Empty); + return; } #endregion