Skip to content

Commit ae946ce

Browse files
committed
...
1 parent 4f8636a commit ae946ce

File tree

3 files changed

+24
-11
lines changed

3 files changed

+24
-11
lines changed

SmartImage.Lib 3/Engines/BaseSearchEngine.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public abstract class BaseSearchEngine : IDisposable
2727
/// </summary>
2828
public virtual string Name => EngineOption.ToString();
2929

30-
public string BaseUrl { get; protected set; }
30+
public virtual Url BaseUrl { get; }
3131

3232
protected TimeSpan Timeout { get; set; } = TimeSpan.FromSeconds(3);
3333

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

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ public sealed class EHentaiEngine : WebSearchEngine, ILoginEngine, INotifyProper
4040
};
4141

4242
private string m_password;
43-
4443
private string m_username;
4544

4645
#region Url
@@ -52,7 +51,7 @@ public sealed class EHentaiEngine : WebSearchEngine, ILoginEngine, INotifyProper
5251

5352
private static readonly Url ExHentai_Image_Lookup = Url.Combine(EXHENTAI_URI, "upld", "image_lookup.php");
5453

55-
private Url Base
54+
public override Url BaseUrl
5655
{
5756
get { return IsLoggedIn ? EXHENTAI_URI : EHENTAI_URI; }
5857
}
@@ -86,6 +85,7 @@ public EHentaiEngine() : base(EHENTAI_URI)
8685
m_client = new HttpClient(m_clientHandler);
8786
Cookies = new CookieJar();
8887
IsLoggedIn = false;
88+
8989
}
9090

9191
/*
@@ -103,8 +103,11 @@ protected override async Task<IDocument> GetDocumentAsync(object origin, SearchQ
103103
{
104104
const string name = "a.jpg";
105105

106-
string t = await query.GetFilePathOrTemp(name);
106+
(string t, bool b) = await query.GetFilePathOrTemp(name);
107107

108+
if (b) {
109+
Trace.WriteLine($"allocated {t}", nameof(GetDocumentAsync));
110+
}
108111
var data = new MultipartFormDataContent()
109112
{
110113
{ new FileContent(t), "sfile", name },
@@ -146,6 +149,7 @@ protected override async Task<IDocument> GetDocumentAsync(object origin, SearchQ
146149
m_clientHandler.CookieContainer.Add(new Cookie(c.Name, c.Value, c.Path, c.Domain));
147150
}
148151

152+
Debug.WriteLine($"{Lookup}", nameof(GetDocumentAsync));
149153
var req = new HttpRequestMessage(HttpMethod.Post, Lookup)
150154
{
151155
Content = data,
@@ -170,7 +174,7 @@ protected override async Task<IDocument> GetDocumentAsync(object origin, SearchQ
170174

171175
private async Task<IFlurlResponse> GetSessionAsync()
172176
{
173-
return await Base.WithCookies(Cookies)
177+
return await EXHENTAI_URI.WithCookies(Cookies)
174178
.WithHeaders(new
175179
{
176180
User_Agent = HttpUtilities.UserAgent
@@ -285,7 +289,13 @@ private static EhResult GetEhResult(INode n)
285289
// ReSharper restore InconsistentNaming
286290
}
287291

288-
public override void Dispose() { }
292+
public override void Dispose()
293+
{
294+
m_client.Dispose();
295+
m_clientHandler.Dispose();
296+
Cookies.Clear();
297+
IsLoggedIn = false;
298+
}
289299

290300
public string Username
291301
{
@@ -348,11 +358,11 @@ public async Task<bool> LoginAsync()
348358
}
349359

350360
var res2 = await GetSessionAsync();
351-
BaseUrl = Base;
361+
352362
return IsLoggedIn = res2.ResponseMessage.IsSuccessStatusCode;
353363
}
354364

355-
#region
365+
#region
356366

357367
private void OnPropertyChanged([CallerMemberName] string propertyName = null)
358368
{

SmartImage.Lib 3/SearchQuery.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,11 @@ public override int GetHashCode()
160160
#endregion
161161

162162
[MustUseReturnValue]
163-
public async Task<string> GetFilePathOrTemp(string fn = null)
163+
public async Task<(string,bool)> GetFilePathOrTemp(string fn = null)
164164
{
165165
string t;
166166
fn ??= Path.GetTempFileName();
167-
167+
bool b;
168168
if (!Uni.IsFile) {
169169
t = Path.Combine(Path.GetTempPath(), fn);
170170

@@ -178,11 +178,14 @@ public async Task<string> GetFilePathOrTemp(string fn = null)
178178
await Uni.Stream.CopyToAsync(fs);
179179
fs.Flush();
180180
}
181+
182+
b = true;
181183
}
182184
else {
183185
t = Uni.Value.ToString();
186+
b = false;
184187
}
185188

186-
return t;
189+
return (t,b);
187190
}
188191
}

0 commit comments

Comments
 (0)