Skip to content

Commit fbc7b4f

Browse files
committed
Cookies
1 parent 777dfd5 commit fbc7b4f

File tree

4 files changed

+46
-20
lines changed

4 files changed

+46
-20
lines changed

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

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,18 @@ public sealed class EHentaiEngine : WebSearchEngine, IConfig, INotifyPropertyCha
4545
CookieContainer = new() { },
4646

4747
};
48-
48+
4949
public override Url BaseUrl => IsLoggedIn ? ExHentaiBase : EHentaiBase;
5050

5151
private Url LookupUrl => IsLoggedIn ? ExHentaiLookup : EHentaiLookup;
5252

53-
public CookieCollection Cookies { get; }
54-
5553
public override SearchEngineOptions EngineOption => SearchEngineOptions.EHentai;
5654

5755
protected override string NodesSelector => Serialization.S_EHentai;
5856

5957
public bool IsLoggedIn { get; private set; }
6058

61-
#region
59+
#region
6260

6361
private static readonly Url EHentaiIndex = "https://forums.e-hentai.org/index.php";
6462
public static readonly Url EHentaiBase = "https://e-hentai.org/";
@@ -74,7 +72,6 @@ static EHentaiEngine() { }
7472
public EHentaiEngine() : base(EHentaiBase)
7573
{
7674
m_client = new HttpClient(m_clientHandler);
77-
Cookies = new();
7875
IsLoggedIn = false;
7976
}
8077

@@ -136,6 +133,15 @@ public async Task<bool> LoginAsync(bool useEx = false)
136133
return x.Host.Contains(HOST_EX);
137134
});
138135

136+
/*var fcc = CookiesManager.Cookies.Where(x =>
137+
{
138+
if (!useEx) {
139+
return x.Domain.Contains(HOST_EH);
140+
}
141+
142+
return x.Domain.Contains(HOST_EX);
143+
});*/
144+
139145
/*var content = new MultipartFormDataContent()
140146
{
141147
{ new StringContent("1"), "CookieDate" },
@@ -158,10 +164,12 @@ public async Task<bool> LoginAsync(bool useEx = false)
158164
.WithCookies(out var cj)
159165
.PostAsync(content);*/
160166

161-
foreach (var fc in fcc) {
162-
Cookies.Add(fc.AsCookie());
167+
foreach (var cookie in fcc) {
168+
m_clientHandler.CookieContainer.Add(cookie.AsCookie());
163169
}
164170

171+
// foreach (var fc in fcc) { }
172+
165173
var res2 = await GetSessionAsync();
166174

167175
return IsLoggedIn = res2.ResponseMessage.IsSuccessStatusCode;
@@ -211,8 +219,8 @@ protected override async Task<IDocument> GetDocumentAsync(SearchResult sr, Searc
211219
// data.Add(new FileContent(f.FullName), "sfile", "a.jpg");
212220

213221
//todo
214-
m_clientHandler.CookieContainer.Add(Cookies);
215-
222+
/*m_clientHandler.CookieContainer.Add(Cookies);
223+
216224
Debug.WriteLine($"{LookupUrl}", nameof(GetDocumentAsync));
217225
218226
var req = new HttpRequestMessage(HttpMethod.Post, LookupUrl)
@@ -228,7 +236,23 @@ protected override async Task<IDocument> GetDocumentAsync(SearchResult sr, Searc
228236
229237
var content = await res.Content.ReadAsStringAsync(token);
230238
231-
sr.RawUrl = res.RequestMessage.RequestUri;
239+
sr.RawUrl = res.RequestMessage.RequestUri;*/
240+
241+
var req = new FlurlRequest(LookupUrl)
242+
{
243+
Content = data,
244+
Headers =
245+
{
246+
{ "User-Agent", HttpUtilities.UserAgent }
247+
},
248+
Verb = HttpMethod.Post,
249+
250+
};
251+
252+
var res = await Client.SendAsync(req, cancellationToken: token);
253+
var content = await res.GetStringAsync();
254+
255+
sr.RawUrl = res.ResponseMessage.RequestMessage.RequestUri;
232256

233257
if (content.Contains("Please wait a bit longer between each file search.")) {
234258
Debug.WriteLine($"cooldown", Name);
@@ -242,7 +266,7 @@ protected override async Task<IDocument> GetDocumentAsync(SearchResult sr, Searc
242266

243267
private Task<IFlurlResponse> GetSessionAsync()
244268
{
245-
return ExHentaiBase.WithCookies(Cookies)
269+
return ExHentaiBase.WithCookies(m_clientHandler.CookieContainer)
246270
.WithHeaders(new
247271
{
248272
User_Agent = HttpUtilities.UserAgent
@@ -293,7 +317,7 @@ public override void Dispose()
293317
{
294318
m_client.Dispose();
295319
m_clientHandler.Dispose();
296-
Cookies.Clear();
320+
297321
IsLoggedIn = false;
298322
}
299323

SmartImage.Lib 3/Model/IParseable.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,7 @@
22

33
public interface IParseable<out TResult, in TSource>
44
{
5-
public static abstract TResult Parse(TSource t);
5+
6+
public static abstract TResult Parse(TSource t);
7+
68
}

SmartImage.Lib 3/Utilities/CookiesManager.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
// Author: Deci | Project: SmartImage.Lib | Name: CookiesManager.cs
22

3+
using System.Diagnostics;
4+
using System.Net;
5+
using Flurl.Http;
36
using Kantan.Net.Web;
47

58
namespace SmartImage.Lib.Utilities;
69

710
public static class CookiesManager
811
{
9-
12+
[DebuggerHidden]
1013
public static async Task<List<IBrowserCookie>> ReadCookiesAsync()
1114
{
1215
using var ff = new FirefoxCookieReader();
@@ -25,7 +28,7 @@ public static async Task<bool> LoadCookiesAsync(bool force = false)
2528

2629
if (b) {
2730
Cookies = await ReadCookiesAsync();
28-
31+
2932
}
3033

3134
return Cookies != null;

SmartImage.Rdx/Program.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Configuration;
22
using System.Diagnostics;
33
using System.Reflection;
4+
using Flurl.Http;
45
using Kantan.Text;
56
using Microsoft.Extensions.DependencyInjection;
67
using Spectre.Console;
@@ -45,10 +46,6 @@ public static async Task<int> Main(string[] args)
4546

4647
#if DEBUG
4748
AConsole.WriteLine(args.QuickJoin());
48-
49-
foreach (string? s in ConfigurationManager.AppSettings) {
50-
AConsole.WriteLine(s);
51-
}
5249
#endif
5350

5451
Grid grd = CliFormat.CreateInfoGrid();
@@ -69,7 +66,7 @@ public static async Task<int> Main(string[] args)
6966

7067
try {
7168
var x = await app.RunAsync(args);
72-
69+
7370
return x;
7471
}
7572
catch (Exception e) {

0 commit comments

Comments
 (0)