Skip to content

Commit

Permalink
Quick update
Browse files Browse the repository at this point in the history
  • Loading branch information
Decimation committed Jul 20, 2021
1 parent bd76034 commit a2bb4d5
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 7 deletions.
8 changes: 4 additions & 4 deletions SmartImage.Lib/Engines/BaseSearchEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -73,7 +71,9 @@ public async Task<SearchResult> 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);

Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion SmartImage.Lib/Engines/ClientSearchEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
22 changes: 21 additions & 1 deletion SmartImage.Lib/Engines/Impl/Ascii2DEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
1 change: 0 additions & 1 deletion SmartImage.Lib/Engines/InterpretedSearchEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down

0 comments on commit a2bb4d5

Please sign in to comment.