Skip to content

Commit bcfae70

Browse files
committed
Fix IQDB; server work
1 parent 7fba08c commit bcfae70

File tree

14 files changed

+133
-94
lines changed

14 files changed

+133
-94
lines changed

SmartImage.Lib/Clients/HydrusClient.cs

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,15 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.ComponentModel;
4-
using System.Diagnostics.CodeAnalysis;
5-
using System.Text.Json;
6-
using System.Linq;
7-
using System.Runtime.CompilerServices;
8-
using System.Security.Authentication;
9-
using System.Security.Cryptography;
10-
using System.Security.Policy;
11-
using System.Text;
1+
using System.ComponentModel;
122
using System.Text.Json;
133
using System.Text.Json.Nodes;
144
using System.Text.Json.Serialization;
15-
using System.Text.Json.Serialization.Metadata;
16-
using System.Threading.Tasks;
175
using Flurl.Http;
18-
using Novus.Streams;
19-
using SmartImage.Lib.Utilities;
206

217
namespace SmartImage.Lib.Clients;
228

239
public class HydrusClient : INotifyPropertyChanged, IDisposable
2410
{
25-
private const string HDR_HYDRUS_KEY = "Hydrus-Client-API-Access-Key";
11+
12+
private const string HDR_HYDRUS_KEY = "Hydrus-Client-API-Access-Key";
2613

2714
public FlurlClient Client { get; }
2815

@@ -147,7 +134,8 @@ public string Key
147134
get => m_key;
148135
set
149136
{
150-
if (value == m_key) return;
137+
if (value == m_key)
138+
return;
151139

152140
m_key = value;
153141
OnPropertyChanged();
@@ -162,7 +150,8 @@ public string EndpointUrl
162150
get => m_endpointUrl;
163151
set
164152
{
165-
if (value == m_endpointUrl) return;
153+
if (value == m_endpointUrl)
154+
return;
166155

167156
m_endpointUrl = value;
168157
OnPropertyChanged();
@@ -185,7 +174,8 @@ protected virtual void OnPropertyChanged([CMN] string propertyName = null)
185174

186175
protected bool SetField<T>(ref T field, T value, [CMN] string propertyName = null)
187176
{
188-
if (EqualityComparer<T>.Default.Equals(field, value)) return false;
177+
if (EqualityComparer<T>.Default.Equals(field, value))
178+
return false;
189179

190180
field = value;
191181
OnPropertyChanged(propertyName);
@@ -194,7 +184,9 @@ protected bool SetField<T>(ref T field, T value, [CMN] string propertyName = nul
194184

195185
public static string HyEncode(object o)
196186
{
187+
#pragma warning disable IL2026
197188
return Url.Encode(JsonSerializer.Serialize(o));
189+
#pragma warning restore IL2026
198190
}
199191

200192
}
@@ -278,7 +270,7 @@ public static implicit operator HydrusQuery(string[] s)
278270

279271
}
280272

281-
#pragma warning disable IL2026
273+
// #pragma warning disable IL2026
282274

283275
public partial class HydrusFileRelationship
284276
{
@@ -311,7 +303,9 @@ public static Dictionary<string, HydrusFileRelationship> Deserialize(JsonNode v)
311303
{
312304
var vs = ((JsonNode) v)["file_relationships"];
313305

306+
#pragma warning disable IL2026
314307
var re = JsonSerializer.Deserialize<Dictionary<string, HydrusFileRelationship>>(vs.ToString());
308+
#pragma warning restore IL2026
315309

316310
return re;
317311
}

SmartImage.Lib/Engines/Impl/Search/EHentaiEngine.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ public async ValueTask<bool> ApplyCookiesAsync(ICookiesProvider provider, Cancel
206206
* https://gitlab.com/NekoInverter/EhViewer/-/blob/master/app/src/main/java/com/hippo/ehviewer/client/EhCookieStore.java
207207
*/
208208

209-
public async ValueTask ApplyConfigAsync(SearchConfig cfg)
209+
public ValueTask ApplyConfigAsync(SearchConfig cfg)
210210
{
211211
/*if (this is { IsLoggedIn: true }/* && !(Username != cfg.EhUsername && Password != cfg.EhPassword)#1#) {
212212
Debug.WriteLine($"{Name} is already logged in", nameof(ApplyConfigAsync));
@@ -215,6 +215,8 @@ public async ValueTask ApplyConfigAsync(SearchConfig cfg)
215215
}*/
216216
//
217217

218+
219+
return ValueTask.CompletedTask;
218220
}
219221

220222
#region

SmartImage.Lib/Engines/Impl/Search/IqdbEngine.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ private async Task<IDocument> GetDocumentAsync(SearchQuery query, CancellationTo
7575
7676
return;
7777
}, cancellationToken: ct);*/
78+
7879
var response = await Client.Request(URL_QUERY)
7980
.OnError(r =>
8081
{
@@ -90,6 +91,7 @@ private async Task<IDocument> GetDocumentAsync(SearchQuery query, CancellationTo
9091
.SetQueryParam("url", query.Upload)
9192
.WithTimeout(Timeout)
9293
.GetAsync(cancellationToken: ct);
94+
9395
if (response != null) {
9496
var s = await response.GetStringAsync();
9597

SmartImage.Lib/Engines/Impl/Search/TinEyeEngine.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public override async Task<SearchResult> GetResultAsync(SearchQuery query, Cance
6060
try {
6161
var str = await response.GetStringAsync();
6262

63-
tinEyeRoot = JsonSerializer.Deserialize<TinEyeRoot>(str);
63+
tinEyeRoot = (TinEyeRoot) JsonSerializer.Deserialize(str, typeof(TinEyeRoot), TinEyeContext.Default);
6464

6565
// tinEyeRoot = await req.GetJsonAsync<TinEyeRoot>();
6666
}
@@ -241,6 +241,14 @@ public class TinEyeRoot
241241
[JsonPropertyName("query_source")]
242242
public string QuerySource { get; set; }
243243

244+
}
245+
246+
[JsonSerializable(typeof(TinEyeRoot))]
247+
public partial class TinEyeContext : JsonSerializerContext
248+
{
249+
250+
251+
244252
}
245253

246254
public class TinEyeMatch

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ public static async Task<UploadResult> UploadAutoAsync(BaseUploadEngine engine,
144144

145145
public abstract Task<UploadResult> UploadFileAsync(string file, CancellationToken ct = default);
146146

147+
// public abstract Task<UploadResult> UploadFileAsync(Stream file, CancellationToken ct = default);
148+
147149
protected virtual async Task<UploadResult> ProcessResultAsync(IFlurlResponse response,
148150
CancellationToken ct = default)
149151
{

SmartImage.Lib/Images/Uni/UniImage.cs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,15 @@
33

44
global using MURV = JetBrains.Annotations.MustUseReturnValueAttribute;
55
using System.Diagnostics;
6-
using System.Drawing.Imaging;
7-
using System.IO.MemoryMappedFiles;
8-
using System.Text;
9-
using System.Threading.Channels;
10-
using CoenM.ImageHash.HashAlgorithms;
11-
using JetBrains.Annotations;
126
using Novus.FileTypes;
137
using Novus.FileTypes.Uni;
148
using Novus.Streams;
159
using Novus.Win32;
16-
using CoenM.ImageHash.HashAlgorithms;
1710
using CoenM.ImageHash;
1811
using Kantan.Diagnostics;
1912
using SixLabors.ImageSharp;
2013
using SixLabors.ImageSharp.Formats;
2114
using SixLabors.ImageSharp.Formats.Png;
22-
using SixLabors.ImageSharp.PixelFormats;
2315
using SixLabors.ImageSharp.Processing;
2416
using SmartImage.Lib.Results.Data;
2517

@@ -71,7 +63,7 @@ public long Size
7163
}
7264

7365
[MN]
74-
public string ValueString => Value?.ToString();
66+
public virtual string ValueString => Value?.ToString();
7567

7668
[MN]
7769
public string FilePath { get; protected set; }

SmartImage.Lib/Images/Uni/UniImageStream.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ namespace SmartImage.Lib.Images.Uni;
88
public class UniImageStream : UniImage
99
{
1010

11+
1112
internal UniImageStream(object value, Stream str)
1213
: base(value, str, UniImageType.Stream) { }
1314

SmartImage.Lib/Results/SearchResult.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Diagnostics;
44
using System.Net;
55
using System.Runtime.CompilerServices;
6+
using System.Text.Json.Serialization;
67
using System.Threading.Channels;
78
using AngleSharp.Html.Parser;
89
using Flurl.Http;
@@ -201,4 +202,4 @@ public void Dispose()
201202
}
202203
}
203204

204-
}
205+
}

SmartImage.Lib/SearchClient.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
using static System.Runtime.InteropServices.JavaScript.JSType;
3636
using SmartImage.Lib.Utilities.Diagnostics;
3737

38+
#pragma warning disable CS0162, CS2255
3839
namespace SmartImage.Lib;
3940

4041
public sealed class SearchClient : IDisposable
@@ -62,8 +63,7 @@ public SearchClient(SearchConfig cfg)
6263

6364
}
6465

65-
static SearchClient()
66-
{ }
66+
static SearchClient() { }
6767

6868
[ModuleInitializer]
6969
public static void Init()
@@ -112,7 +112,7 @@ public void OpenChannel()
112112
/// </summary>
113113
/// <param name="query">Search query</param>
114114
/// <param name="scheduler"></param>
115-
/// <param name="token">Cancellation token passed to <see cref="WebSearchEngine{T}.GetResultAsync(SmartImage.Lib.SearchQuery,System.Threading.CancellationToken)"/></param>
115+
/// <param name="token">Cancellation token passed to <see cref="WebSearchEngine.GetResultAsync(SearchQuery,CancellationToken)"/></param>
116116
public async Task<SearchResult[]> RunSearchAsync(SearchQuery query,
117117
TaskScheduler scheduler = default,
118118
CancellationToken token = default)
@@ -158,8 +158,9 @@ public async Task<SearchResult[]> RunSearchAsync(SearchQuery query,
158158
tasks.Remove(task);
159159

160160
if (task.IsFaulted) {
161-
Trace.WriteLine($"{task} faulted!",LogCategories.C_ERROR);
161+
Trace.WriteLine($"{task} faulted!", LogCategories.C_ERROR);
162162
}
163+
163164
SearchResult result = await task;
164165

165166
results[i] = result;
@@ -228,13 +229,13 @@ private void ProcessResult(SearchResult result)
228229
public static void OpenResult([MN] Url url1)
229230
{
230231
#if (DEBUG && !TEST) || UNITTEST
231-
#pragma warning disable CA1822, CS0162
232+
#pragma warning disable CA1822
232233

233234
// ReSharper disable once MemberCanBeMadeStatic.Local
234235
s_logger.LogDebug("Not opening result {result}", url1);
235236
return;
236237

237-
#pragma warning restore CS0162, CA1822
238+
#pragma warning restore CA1822
238239
#endif
239240

240241
if (url1 == null) {
@@ -306,7 +307,7 @@ public async ValueTask LoadEnginesAsync(CancellationToken token = default)
306307
}
307308

308309
if (Config.FlareSolverr && !FlareSolverrClient.Value.IsInitialized) {
309-
310+
310311

311312
var ok = FlareSolverrClient.Value.Configure(Config.FlareSolverrApiUrl);
312313

@@ -360,4 +361,4 @@ public void Dispose()
360361
ResultChannel?.Writer.Complete();
361362
}
362363

363-
}
364+
}

SmartImage.Lib/SearchQuery.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,9 @@ public async Task<Url> UploadAsync(BaseUploadEngine engine = null, CancellationT
7676
return Upload;
7777
}
7878

79-
string fu = Source.ValueString;
8079

8180
if (Source.IsUri) {
82-
Upload = fu;
81+
Upload = Source.ValueString;
8382

8483
// Size = BaseSearchEngine.NA_SIZE;
8584
// var fmt = await ISImage.DetectFormatAsync(Stream);
@@ -89,6 +88,13 @@ public async Task<Url> UploadAsync(BaseUploadEngine engine = null, CancellationT
8988
else {
9089
// fu = await test(fu);
9190

91+
string fu;
92+
93+
if (Source.IsFile)
94+
fu = Source.ValueString;
95+
else
96+
fu = Source.WriteToFile();
97+
9298
engine ??= BaseUploadEngine.Default;
9399

94100
UploadResult u = await engine.UploadFileAsync(fu, ct);

0 commit comments

Comments
 (0)