Skip to content

Commit

Permalink
Add GetForDomain extension
Browse files Browse the repository at this point in the history
  • Loading branch information
ImoutoChan committed Jan 23, 2025
1 parent be1b060 commit 721fee9
Show file tree
Hide file tree
Showing 12 changed files with 31 additions and 25 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ jobs:
- name: Echo version
run: echo ${{ steps.gitversion.outputs.majorMinorPatch }}

- name: Setup .NET Core SDK '7.x.x'
- name: Setup .NET Core SDK '9.x.x'
uses: actions/setup-dotnet@3447fd6a9f9e57506b15f895c5b76d3b197dc7c2 # v3.2.0
with:
dotnet-version: '7.x.x'
dotnet-version: '9.x.x'
include-prerelease: true

- name: Update project version
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ jobs:
- name: Echo version
run: echo ${{ steps.gitversion.outputs.majorMinorPatch }}

- name: Setup .NET Core SDK '7.x.x'
- name: Setup .NET Core SDK '9.x.x'
uses: actions/setup-dotnet@v2
with:
dotnet-version: '7.x.x'
dotnet-version: '9.x.x'
include-prerelease: true

- name: Update project version
Expand Down
2 changes: 1 addition & 1 deletion Imouto.BooruParser.Tests/Imouto.BooruParser.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
Expand Down
5 changes: 5 additions & 0 deletions Imouto.BooruParser/Extensions/FlurlExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Flurl;
using Flurl.Http;
using Flurl.Http.Configuration;
using HtmlAgilityPack;

namespace Imouto.BooruParser.Extensions;
Expand All @@ -16,4 +18,7 @@ public static async Task<HtmlDocument> GetHtmlDocumentAsync(
doc.LoadHtml(str);
return doc;
}

public static IFlurlClient GetForDomain(this IFlurlClientCache cache, Url baseUrl)
=> cache.GetOrAdd(baseUrl, baseUrl);
}
3 changes: 1 addition & 2 deletions Imouto.BooruParser/Imouto.BooruParser.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
Expand All @@ -21,7 +21,6 @@
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<PackageTags>booru search parser danbooru sankakuchannel yande.re yandere gelbooru imageboard image art animeart anime</PackageTags>
<Version>4.0.0-rc3</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Flurl;
using Flurl.Http;
using Flurl.Http.Configuration;
using Imouto.BooruParser.Extensions;
using Microsoft.Extensions.Options;

namespace Imouto.BooruParser.Implementations.Danbooru;
Expand All @@ -13,7 +14,7 @@ public class DanbooruApiLoader : IBooruApiLoader, IBooruApiAccessor

public DanbooruApiLoader(IFlurlClientCache factory, IOptions<DanbooruSettings> options)
{
_flurlClient = factory.GetOrAdd(new Url(BaseUrl), new Url(BaseUrl)).BeforeCall(x => SetAuthParameters(x, options));
_flurlClient = factory.GetForDomain(new Url(BaseUrl)).BeforeCall(x => SetAuthParameters(x, options));
_botUserAgent = options.Value.BotUserAgent ?? throw new Exception("UserAgent is required to make api calls");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class GelbooruApiLoader : IBooruApiLoader

public GelbooruApiLoader(IFlurlClientCache factory, IOptions<GelbooruSettings> options)
=> _flurlClient = factory
.GetOrAdd(new Url(BaseUrl), new Url(BaseUrl))
.GetForDomain(new Url(BaseUrl))
.BeforeCall(_ => DelayWithThrottler(options));

public async Task<Post> GetPostAsync(string postId)
Expand Down
4 changes: 2 additions & 2 deletions Imouto.BooruParser/Implementations/Rule34/Rule34ApiLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class Rule34ApiLoader : IBooruApiLoader

public Rule34ApiLoader(IFlurlClientCache factory, IOptions<Rule34Settings> options)
{
_flurlHtmlClient = factory.GetOrAdd(new Url(HtmlBaseUrl), new Url(HtmlBaseUrl))
_flurlHtmlClient = factory.GetForDomain(new Url(HtmlBaseUrl))
.WithHeader("Connection", "keep-alive")
.WithHeader("sec-ch-ua", "\"Chromium\";v=\"106\", \"Google Chrome\";v=\"106\", \"Not;A=Brand\";v=\"99\"")
.WithHeader("sec-ch-ua-mobile", "?0")
Expand All @@ -32,7 +32,7 @@ public Rule34ApiLoader(IFlurlClientCache factory, IOptions<Rule34Settings> optio
.WithHeader("Accept-Language", "en")
.BeforeCall(_ => DelayWithThrottler(options));

_flurlJsonClient = factory.GetOrAdd(new Url(JsonBaseUrl), new Url(JsonBaseUrl))
_flurlJsonClient = factory.GetForDomain(new Url(JsonBaseUrl))
.WithHeader("Connection", "keep-alive")
.WithHeader("sec-ch-ua", "\"Chromium\";v=\"106\", \"Google Chrome\";v=\"106\", \"Not;A=Brand\";v=\"99\"")
.WithHeader("sec-ch-ua-mobile", "?0")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public SankakuApiLoader(
ISankakuAuthManager sankakuAuthManager)
{
_sankakuAuthManager = sankakuAuthManager;
_flurlClient = factory.GetOrAdd(new Url(ApiBaseUrl), new Url(ApiBaseUrl))
_flurlClient = factory.GetForDomain(new Url(ApiBaseUrl))
.WithHeader("Connection", "keep-alive")
.WithHeader("sec-ch-ua", "\"Chromium\";v=\"106\", \"Google Chrome\";v=\"106\", \"Not;A=Brand\";v=\"99\"")
.WithHeader("sec-ch-ua-mobile", "?0")
Expand All @@ -38,7 +38,7 @@ public SankakuApiLoader(
.WithHeader("Accept-Language", "en")
.BeforeCall(x => SetAuthParameters(x, options))!;

_htmlFlurlClient = factory.GetOrAdd(new Url(HtmlBaseUrl), new Url(HtmlBaseUrl))
_htmlFlurlClient = factory.GetForDomain(new Url(HtmlBaseUrl))
.WithHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7")
.WithHeader("Accept-Encoding", "gzip, deflate, br")
.WithHeader("Accept-Language", "en,en-US;q=0.9")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Flurl;
using Flurl.Http;
using Flurl.Http.Configuration;
using Imouto.BooruParser.Extensions;
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Options;

Expand All @@ -27,7 +28,7 @@ public SankakuAuthManager(
_memoryCache = memoryCache;
_options = options;
_factory = factory;
_flurlClient = factory.GetOrAdd(new Url(BaseUrl), new Url(BaseUrl));
_flurlClient = factory.GetForDomain(new Url(BaseUrl));
}

public async ValueTask<string?> GetTokenAsync()
Expand Down Expand Up @@ -64,7 +65,7 @@ public async Task<IReadOnlyCollection<FlurlCookie>> GetSankakuChannelSessionAsyn

var cookieJar = new CookieJar();

var loginClient = factory.GetOrAdd("https://login.sankakucomplex.com", "https://login.sankakucomplex.com")
var loginClient = factory.GetForDomain("https://login.sankakucomplex.com")
.WithHeader("sec-ch-ua", "\"Chromium\";v=\"106\", \"Google Chrome\";v=\"106\", \"Not;A=Brand\";v=\"99\"")
.WithHeader("sec-ch-ua-mobile", "?0")
.WithHeader("sec-ch-ua-platform", "\"Windows\"")
Expand Down Expand Up @@ -182,7 +183,7 @@ private async Task<Tokens> SankakuFullLoginAsync()

var cookieJar = new CookieJar();

var loginClient = factory.GetOrAdd("https://login.sankakucomplex.com", "https://login.sankakucomplex.com")
var loginClient = factory.GetForDomain("https://login.sankakucomplex.com")
.WithHeader("sec-ch-ua", "\"Chromium\";v=\"106\", \"Google Chrome\";v=\"106\", \"Not;A=Brand\";v=\"99\"")
.WithHeader("sec-ch-ua-mobile", "?0")
.WithHeader("sec-ch-ua-platform", "\"Windows\"")
Expand All @@ -196,7 +197,7 @@ private async Task<Tokens> SankakuFullLoginAsync()
.WithHeader("Sec-Fetch-Dest", "document")
.WithHeader("Accept-Language", "en");

var capiClient = factory.GetOrAdd("https://capi-v2.sankakucomplex.com", "https://capi-v2.sankakucomplex.com")
var capiClient = factory.GetForDomain("https://capi-v2.sankakucomplex.com")
.WithHeader("sec-ch-ua", "\"Chromium\";v=\"106\", \"Google Chrome\";v=\"106\", \"Not;A=Brand\";v=\"99\"")
.WithHeader("sec-ch-ua-mobile", "?0")
.WithHeader("sec-ch-ua-platform", "\"Windows\"")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class YandereApiLoader : IBooruApiLoader, IBooruApiAccessor

public YandereApiLoader(IFlurlClientCache factory, IOptions<YandereSettings> options)
{
_flurlClient = factory.GetOrAdd(new Url(BaseUrl), new Url(BaseUrl)).BeforeCall(x => SetAuthParameters(x, options));
_flurlClient = factory.GetForDomain(new Url(BaseUrl)).BeforeCall(x => SetAuthParameters(x, options));
}

public async Task<Post> GetPostAsync(string postId)
Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ Install-Package Imouto.BooruParser
```xml
<PackageReference Include="Imouto.BooruParser" Version="3.*" />
```
# Version 4.0.0 RC1
* I'm bumping major version because I had to change public API. Sankaku now has string ids on different entities,
and we have to adjust for it. Most public API types now have a generic id parameter. It's string for sankaku and int
for every other booru. If you're not interested in sankaku you can just assume that ids are int as it was before.
* Technical: FluentAssertion is replaced with AwesomeAssertions, you know why.
* Technical: Flurl is upgraded to the latest 4 version, it has some breaking changes, but I've adjusted for them, we see
how it goes.
# Version 4.0.0
* I'm bumping the major version due to changes in the public API. Sankaku now uses string Ids for various entities,
and we have to adjust for it. Most public API types now have a string Id parameter.
* Technical: FluentAssertion has been replaced with AwesomeAssertions, you know why.
* Technical: Flurl has been upgraded to version 4, it has some breaking changes, but I've adjusted for them, we'll see
how it goes.
* Technical: Upgraded to net9.0

# Version 3.3.0
* Sankaku is child of devil and was broken once again. Removed old auth chan. part as now all logins goes throw beta.
Expand Down

0 comments on commit 721fee9

Please sign in to comment.