Skip to content

Commit cf960d9

Browse files
committed
updates
1 parent 05d0944 commit cf960d9

File tree

13 files changed

+151
-110
lines changed

13 files changed

+151
-110
lines changed

SmartImage.Lib/Engines/Search/Base/BaseSearchEngine.cs

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
using System;
22
using System.Diagnostics;
3+
using System.Linq;
34
using System.Net;
45
using System.Net.Http;
56
using System.Threading;
67
using System.Threading.Tasks;
8+
using Flurl.Http;
79
using Kantan.Net;
10+
using Kantan.Text;
11+
using Novus.Utilities;
12+
using SmartImage.Lib.Properties;
813
using SmartImage.Lib.Searching;
914
using static Kantan.Diagnostics.LogCategories;
1015

@@ -32,7 +37,6 @@ protected BaseSearchEngine(string baseUrl)
3237
protected bool FollowRedirects { get; set; } = true;
3338

3439
public abstract EngineSearchType SearchType { get; }
35-
3640

3741

3842
public virtual SearchResult GetResult(ImageQuery query, CancellationToken? c = null)
@@ -57,14 +61,14 @@ public virtual SearchResult GetResult(ImageQuery query, CancellationToken? c = n
5761
sr.RawUri = sr.Origin.RawUri;
5862
sr.Status = ResultStatus.Success;
5963
}
60-
64+
6165
return sr;
6266
}
6367

6468

6569
public async Task<SearchResult> GetResultAsync(ImageQuery query, CancellationToken? c = null)
6670
{
67-
c??= CancellationToken.None;
71+
c ??= CancellationToken.None;
6872

6973
var task = Task.Run(delegate
7074
{
@@ -112,7 +116,6 @@ protected virtual SearchResultOrigin GetResultOrigin(ImageQuery query, Cancellat
112116
success = true;
113117
}
114118

115-
116119

117120
string content = null;
118121

@@ -126,14 +129,24 @@ protected virtual SearchResultOrigin GetResultOrigin(ImageQuery query, Cancellat
126129
{
127130
Response = res,
128131
// Content = content,
129-
Success = success,
130-
RawUri = rawUri,
131-
Query = query
132+
Success = success,
133+
RawUri = rawUri,
134+
Query = query
132135
};
133136

134137
return origin;
135138

136139
}
140+
141+
public static BaseSearchEngine[] GetAllSearchEngines()
142+
{
143+
var engines = typeof(BaseSearchEngine).GetAllSubclasses()
144+
.Select(Activator.CreateInstance)
145+
.Cast<BaseSearchEngine>()
146+
.ToArray();
147+
148+
return engines;
149+
}
137150
}
138151

139152
/// <summary>

SmartImage.Lib/Engines/Search/Base/WebClientSearchEngine.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@ protected WebClientSearchEngine(string baseUrl) : base(baseUrl) { }
1414
public abstract override SearchEngineOptions EngineOption { get; }
1515

1616
public abstract override EngineSearchType SearchType { get; }
17-
17+
1818
protected override object GetProcessingObject(SearchResult sr) => ParseContent(sr.Origin);
19-
2019

2120
protected virtual object ParseContent(SearchResultOrigin origin)
2221
{

SmartImage.Lib/Engines/Upload/Base/BaseUploadEngine.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
using System;
2+
using System.Linq;
23
using System.Threading.Tasks;
34
using Kantan.Numeric;
45
using Novus.OS;
6+
using Novus.Utilities;
57

68
namespace SmartImage.Lib.Engines.Upload.Base;
79

@@ -43,4 +45,12 @@ protected void Verify(string file)
4345
throw new ArgumentException($"File {file} is too large (max {MaxSize} MB) for {Name}");
4446
}
4547
}
48+
49+
public static BaseUploadEngine[] GetAllUploadEngines()
50+
{
51+
return typeof(BaseUploadEngine).GetAllSubclasses()
52+
.Select(Activator.CreateInstance)
53+
.Cast<BaseUploadEngine>()
54+
.ToArray();
55+
}
4656
}

SmartImage.Lib/Properties/Resources.Designer.cs

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

SmartImage.Lib/Properties/Resources.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,4 +144,7 @@
144144
<value>priority-engines</value>
145145
<comment>Config key: priority engines</comment>
146146
</data>
147+
<data name="U_DeprecatedEngines" xml:space="preserve">
148+
<value>https://raw.githubusercontent.com/Decimation/SmartImage/master/DEPRECATED_ENGINES</value>
149+
</data>
147150
</root>

SmartImage.Lib/SearchClient.cs

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -107,18 +107,21 @@ public SearchClient(SearchConfig config)
107107
/// <summary>
108108
/// Reloads <see cref="Config" /> and <see cref="Engines" /> accordingly.
109109
/// </summary>
110-
public void Reload()
110+
public void Reload(bool saveCfg = false)
111111
{
112112
if (Config.SearchEngines == SearchEngineOptions.None) {
113113
Config.SearchEngines = SearchEngineOptions.All;
114114
}
115115

116-
Engines = GetAllSearchEngines()
117-
.Where(e => Config.SearchEngines.HasFlag(e.EngineOption))
118-
.ToArray();
116+
Engines = BaseSearchEngine.GetAllSearchEngines()
117+
.Where(e => Config.SearchEngines.HasFlag(e.EngineOption))
118+
.ToArray();
119119

120120
Trace.WriteLine($"{nameof(SearchClient)}: Config:\n{Config}", C_DEBUG);
121121

122+
if (saveCfg) {
123+
Config.Save();
124+
}
122125
}
123126

124127
/// <summary>
@@ -339,22 +342,6 @@ public List<SearchResult> MaximizeResults<T>(Func<SearchResult, T> property)
339342
return res;
340343
}
341344

342-
public static BaseUploadEngine[] GetAllUploadEngines()
343-
{
344-
return typeof(BaseUploadEngine).GetAllSubclasses()
345-
.Select(Activator.CreateInstance)
346-
.Cast<BaseUploadEngine>()
347-
.ToArray();
348-
}
349-
350-
public static BaseSearchEngine[] GetAllSearchEngines()
351-
{
352-
return typeof(BaseSearchEngine).GetAllSubclasses()
353-
.Select(Activator.CreateInstance)
354-
.Cast<BaseSearchEngine>()
355-
.ToArray();
356-
}
357-
358345
/// <summary>
359346
/// Fires when <see cref="GetResultContinueCallback"/> returns
360347
/// </summary>

0 commit comments

Comments
 (0)