diff --git a/SmartImage.Lib/Engines/BaseSearchEngine.cs b/SmartImage.Lib/Engines/BaseSearchEngine.cs index 619e5c20..b7e1e44b 100644 --- a/SmartImage.Lib/Engines/BaseSearchEngine.cs +++ b/SmartImage.Lib/Engines/BaseSearchEngine.cs @@ -33,8 +33,6 @@ protected BaseSearchEngine(string baseUrl) public virtual TimeSpan Timeout { get; set; } = TimeSpan.FromSeconds(3); - protected virtual bool Redirect { get; set; } = true; - public virtual SearchResult GetResult(ImageQuery query) { var rawUrl = GetRawResultUri(query, out var r); @@ -73,7 +71,9 @@ public async Task GetResultAsync(ImageQuery query) return await task; } - public Uri GetRawResultUri(ImageQuery query, out IRestResponse res) + + + public virtual Uri GetRawResultUri(ImageQuery query, out IRestResponse res) { var uri = new Uri(BaseUrl + query.UploadUri); @@ -82,7 +82,7 @@ public Uri GetRawResultUri(ImageQuery query, out IRestResponse res) return null; }*/ - res = Network.GetResponse(uri.ToString(), (int) Timeout.TotalMilliseconds, Method.GET, Redirect); + res = Network.GetResponse(uri.ToString(), (int) Timeout.TotalMilliseconds, Method.GET, true); if (!res.IsSuccessful && res.StatusCode!= HttpStatusCode.Redirect) { Debug.WriteLine($"{Name} is unavailable or timed out after {Timeout:g} | {uri} {res.StatusCode}", C_WARN); diff --git a/SmartImage.Lib/Engines/ClientSearchEngine.cs b/SmartImage.Lib/Engines/ClientSearchEngine.cs index e24ce18a..7f1cea54 100644 --- a/SmartImage.Lib/Engines/ClientSearchEngine.cs +++ b/SmartImage.Lib/Engines/ClientSearchEngine.cs @@ -30,7 +30,7 @@ protected ClientSearchEngine(string baseUrl, string endpointUrl) : base(baseUrl) protected RestClient Client { get; } - protected override bool Redirect { get; set; } + [DebuggerHidden] public override SearchResult GetResult(ImageQuery query) diff --git a/SmartImage.Lib/Engines/Impl/Ascii2DEngine.cs b/SmartImage.Lib/Engines/Impl/Ascii2DEngine.cs index 40abaa33..f716df29 100644 --- a/SmartImage.Lib/Engines/Impl/Ascii2DEngine.cs +++ b/SmartImage.Lib/Engines/Impl/Ascii2DEngine.cs @@ -31,7 +31,27 @@ public Ascii2DEngine() : base("https://ascii2d.net/search/url/") public override string Name => EngineOption.ToString(); - protected override bool Redirect => false; + public override Uri GetRawResultUri(ImageQuery query, out IRestResponse res) + { + // todo + + var uri = new Uri(BaseUrl + query.UploadUri); + + /*if (!Network.IsAlive(uri, (int) Timeout.TotalMilliseconds)) { + Debug.WriteLine($"{Name} is unavailable or timed out after {Timeout:g} | {uri}", C_WARN); + return null; + }*/ + + res = Network.GetResponse(uri.ToString(), (int)Timeout.TotalMilliseconds, Method.GET, false); + + if (!res.IsSuccessful && res.StatusCode != HttpStatusCode.Redirect) + { + Debug.WriteLine($"{Name} is unavailable or timed out after {Timeout:g} | {uri} {res.StatusCode}", LogCategories.C_WARN); + return null; + } + + return uri; + } private Uri ConvertToDetailUri(Uri url) { diff --git a/SmartImage.Lib/Engines/InterpretedSearchEngine.cs b/SmartImage.Lib/Engines/InterpretedSearchEngine.cs index 2e325f6d..6107a3c6 100644 --- a/SmartImage.Lib/Engines/InterpretedSearchEngine.cs +++ b/SmartImage.Lib/Engines/InterpretedSearchEngine.cs @@ -18,7 +18,6 @@ protected InterpretedSearchEngine(string baseUrl) : base(baseUrl) { } public abstract override string Name { get; } - protected override bool Redirect { get; set; } [DebuggerHidden] public override SearchResult GetResult(ImageQuery query) {