Skip to content

Commit 5167220

Browse files
committed
Finishing touches; RepostSleuth fixes
1 parent 90a3d25 commit 5167220

6 files changed

Lines changed: 29 additions & 25 deletions

File tree

SmartImage.Lib/Engines/Search/RepostSleuthEngine.cs

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ namespace SmartImage.Lib.Engines.Search;
2020

2121
public sealed class RepostSleuthEngine : BaseSearchEngine, IDisposable
2222
{
23-
private const string URL_API = "https://api.repostsleuth.com/image";
23+
24+
private const string URL_API = "https://api.repostsleuth.com/api/image";
2425
private const string URL_QUERY = "https://repostsleuth.com/search?url=";
2526

2627
public Url Endpoint => URL_API;
@@ -41,7 +42,7 @@ public RepostSleuthEngine() : base(URL_QUERY)
4142

4243
public override void Dispose() { }
4344

44-
45+
4546
public override async Task<SearchResult> GetResultAsync(SearchQuery query, CancellationToken token = default)
4647
{
4748
var sr = await base.GetResultAsync(query, token);
@@ -51,24 +52,17 @@ public override async Task<SearchResult> GetResultAsync(SearchQuery query, Cance
5152
try {
5253
using var response = await Client.Request(Endpoint)
5354
.WithTimeout(Timeout)
54-
.SetQueryParams(new
55+
.PostMultipartAsync(buildContent: content =>
5556
{
56-
filter = true,
57-
url = query.Upload,
58-
same_sub = false,
59-
filter_author = true,
60-
only_older = false,
61-
include_crossposts = false,
62-
meme_filter = false,
63-
target_match_percent = 90,
64-
filter_dead_matches = false,
65-
target_days_old = 0
66-
}).GetAsync(cancellationToken: token).ConfigureAwait(false);
57+
var stream = query.Source.GetStream();
58+
content.AddFile("image", stream, query.Source.Name);
59+
}, cancellationToken: token);
6760

6861
if (response.StatusCode == 530) {
6962
goto ret;
7063
}
71-
var s = await response.GetStreamAsync().ConfigureAwait(false);
64+
65+
var s = await response.GetStringAsync().ConfigureAwait(false);
7266
obj = JsonSerializer.Deserialize<RepostSleuthResult>(s, JsOptions);
7367
}
7468
catch (JsonException e) {

SmartImage.Lib/Engines/Search/YandexEngine.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ public override async Task<SearchResult> GetResultAsync(SearchQuery query, Cance
9292
var ocr = jsonNode["initialState"]["cbirOcr"];
9393
var ocrText = ocr["hasText"].GetValue<bool>() ? ocr["plainText"] : null;
9494
sr.Overview = $"OCR: {ocrText}";
95-
9695
foreach (var site in sitesObj) {
9796
// site.Root = sr;
9897
var sri = site.ToItem(sr);
@@ -101,6 +100,8 @@ public override async Task<SearchResult> GetResultAsync(SearchQuery query, Cance
101100
sr.Results.Add(sri);
102101
}
103102

103+
// var sitesObjDistinct=sitesObj.DistinctBy(x=>x.OriginalImage.Url);
104+
104105
// sr.Results.AddRange(sitesObj);
105106

106107

SmartImage.Lib/Images/Uni/UniImage.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ public static async Task<UniImage> TryCreateAsync(object o, bool autoInit = true
250250
bool allocOk = false;
251251
bool allocImgOk = false;
252252

253-
(allocOk,allocImgOk) = await ui.AllocAll(ct);
253+
(allocOk, allocImgOk) = await ui.AllocAll(ct);
254254

255255
s_logger.LogTrace("{Value} :: {AllocOk} {AllocImgOk}", o, allocOk, allocImgOk);
256256

@@ -302,19 +302,20 @@ public bool TryDeleteFile()
302302
return !HasLocalFilePath;
303303
}
304304

305+
public virtual string Name { get; protected set;}
306+
305307
[MURV]
306308
public virtual string WriteImageToFile([CBN] string fn = null)
307309
{
308310
if (!HasImage) {
309311
throw new InvalidOperationException();
310312
}
311313

312-
fn ??= this switch
313-
{
314-
UniImageUrl uri => uri.Url.GetFileName(),
315-
UniImageFile file => file.LocalFileInfo.Name,
316-
_ => Path.GetRandomFileName()
317-
};
314+
if (HasLocalFilePath) {
315+
return LocalFilePath;
316+
}
317+
318+
fn ??= String.IsNullOrWhiteSpace(Name) ? Path.GetRandomFileName() : Name;
318319

319320
fn = Path.ChangeExtension(fn, ImageFormat.FileExtensions.First());
320321

SmartImage.Lib/Images/Uni/UniImageFile.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ internal UniImageFile(FileInfo fi) : base(fi.FullName, UniImageType.File)
2020

2121
public FileInfo LocalFileInfo { get; }
2222

23+
public override string Name => LocalFileInfo.Name;
24+
25+
2326
protected override async ValueTask<bool> AllocSourceAsync(CancellationToken ct = default)
2427
{
2528
if (HasBytes) {

SmartImage.Lib/Images/Uni/UniImageUrl.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using SixLabors.ImageSharp.PixelFormats;
1010
using SmartImage.Lib.Engines.Results;
1111
using SmartImage.Lib.Model;
12+
using System;
1213
using System.Collections.Concurrent;
1314
using System.Collections.Immutable;
1415
using System.Net;
@@ -30,6 +31,10 @@ internal UniImageUrl(Url url) : base(url?.ToString(), UniImageType.Uri)
3031
Url = url;
3132
}
3233

34+
35+
public override string Name => Url.GetFileName();
36+
37+
3338
/*public static async ValueTask<UniImageUrl> ScanAsync(Url u, ChannelWriter<UniImageUrl> cw, CancellationToken ct=default)
3439
{
3540
var ui = await TryCreateAsync(u,ct:ct);

SmartImage.Rdx/Commands/Search/SearchCommand.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ protected override void InitConfig(SearchCommandSettings scs)
131131
Client = new SearchClient(Config);
132132

133133
m_mainTable = CommandSettings.Interactive ? Renderables.CreateMainTable() : Renderables.CreateFullResultTable();
134-
134+
m_mainTable.Expand = true;
135135
}
136136

137137
public override async Task<int> ExecuteAsync(CommandContext context, SearchCommandSettings settings, CancellationToken cancellationToken)
@@ -161,7 +161,7 @@ public override async Task<int> ExecuteAsync(CommandContext context, SearchComma
161161
m_layout = new Layout("Root").SplitColumns(
162162
new Layout("L").SplitRows(
163163
new("LC", cfgPanel),
164-
new("LT", m_mainTable)
164+
new("LT", m_mainTable) { }
165165
),
166166
new Layout("R", ciPanel) { }
167167
);

0 commit comments

Comments
 (0)