Skip to content

Commit

Permalink
Add PreviewUrl to Post model
Browse files Browse the repository at this point in the history
  • Loading branch information
ImoutoChan committed Apr 21, 2024
1 parent 568a7b7 commit e0e92a8
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 6 deletions.
4 changes: 2 additions & 2 deletions Imouto.BooruParser.Tests/Loaders/Rule34LoaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public async Task ShouldReturnPost()
post.Id.Id.Should().Be(8548333);
post.Id.Md5Hash.Should().Be("42936037bc650b4d38bc9f6df355b0f1");
post.Notes.Should().BeEmpty();
post.Tags.Should().HaveCount(110);
post.Tags.Should().HaveCount(111);

foreach (var postTag in post.Tags)
{
Expand Down Expand Up @@ -65,7 +65,7 @@ public async Task ShouldReturnPostByMd5()
post.Id.Id.Should().Be(8548333);
post.Id.Md5Hash.Should().Be("42936037bc650b4d38bc9f6df355b0f1");
post.Notes.Should().BeEmpty();
post.Tags.Should().HaveCount(110);
post.Tags.Should().HaveCount(111);

foreach (var postTag in post.Tags)
{
Expand Down
4 changes: 2 additions & 2 deletions Imouto.BooruParser.Tests/Loaders/SankakuLoaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public async Task ShouldGetPostByMd5Async_dc9da74597ecd47b2848fb4d68fce77a()
post.Id.Id.Should().Be(34486935);
post.Id.Md5Hash.Should().Be("dc9da74597ecd47b2848fb4d68fce77a");
post.Notes.Should().BeEmpty();
post.Tags.Should().HaveCount(96);
post.Tags.Should().HaveCount(99);

foreach (var postTag in post.Tags)
{
Expand Down Expand Up @@ -374,7 +374,7 @@ public async Task ShouldLoadChildren()

var post = await loader.GetPostAsync(31729492);

post.ChildrenIds.Should().HaveCount(12);
post.ChildrenIds.Should().HaveCount(10);
post.ChildrenIds.Distinct().Should().HaveCount(post.ChildrenIds.Count);
post.ChildrenIds.First().Should().Be(new PostIdentity(32945185, "47e36f120f7ed20e2aaaba900310bb5b"));

Expand Down
1 change: 1 addition & 0 deletions Imouto.BooruParser/Api.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public record Post(
PostIdentity Id,
string? OriginalUrl,
string? SampleUrl,
string? PreviewUrl,
ExistState ExistState,
DateTimeOffset PostedAt,
Uploader UploaderId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public async Task<Post> GetPostAsync(int postId)
new PostIdentity(postId, post.Md5),
post.FileUrl,
post.LargeFileUrl ?? post.PreviewFileUrl,
post.PreviewFileUrl,
post.IsBanned || post.IsDeleted ? ExistState.MarkDeleted : ExistState.Exist,
post.CreatedAt.ToUniversalTime(),
new Uploader(post.UploaderId, post.Uploader.Name.Replace('_', ' ')),
Expand Down Expand Up @@ -60,6 +61,7 @@ await GetPoolsAsync(postId),
new PostIdentity(post.Id, post.Md5),
post.FileUrl,
post.LargeFileUrl ?? post.PreviewFileUrl,
post.PreviewFileUrl,
post.IsBanned || post.IsDeleted ? ExistState.MarkDeleted : ExistState.Exist,
post.CreatedAt,
new Uploader(post.UploaderId, post.Uploader.Name.Replace('_', ' ')),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public async Task<Post> GetPostAsync(int postId)

public async Task<SearchResult> SearchAsync(string tags)
{
//https://gelbooru.com/index.php?page=dapi&s=post&q=index&json=1&limit=20&tags=1girl
// https://gelbooru.com/index.php?page=dapi&s=post&q=index&json=1&limit=20&tags=1girl
var postJson = await _flurlClient.Request("index.php")
.SetQueryParams(new
{
Expand Down Expand Up @@ -211,6 +211,7 @@ private static Post CreatePost(GelbooruPost post, HtmlDocument postHtml)
new PostIdentity(post.Id, post.Md5),
post.FileUrl,
!string.IsNullOrWhiteSpace(post.SampleUrl) ? post.SampleUrl : post.FileUrl,
post.PreviewUrl,
ExistState.Exist,
ExtractDate(post),
new Uploader(post.CreatorId, post.Owner.Replace('_', ' ')),
Expand Down Expand Up @@ -255,6 +256,7 @@ private static Post CreatePost(GelbooruPost post, HtmlDocument postHtml)
new PostIdentity(id, md5),
url,
url,
url,
ExistState.MarkDeleted,
date,
new Uploader(-1, uploader.Replace('_', ' ')),
Expand Down
3 changes: 2 additions & 1 deletion Imouto.BooruParser/Implementations/Gelbooru/Models.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ public record GelbooruPost(
[property: JsonPropertyName("tags")] string Tags,
[property: JsonPropertyName("has_notes")] string HasNotes,
[property: JsonPropertyName("file_url")] string FileUrl,
[property: JsonPropertyName("sample_url")] string? SampleUrl
[property: JsonPropertyName("sample_url")] string? SampleUrl,
[property: JsonPropertyName("preview_url")] string? PreviewUrl
);

public record GelbooruPostPage(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ private static Post CreatePost(Rule34Post post, HtmlDocument postHtml)
new PostIdentity(post.Id, post.Hash),
post.FileUrl,
!string.IsNullOrWhiteSpace(post.SampleUrl) ? post.SampleUrl : post.FileUrl,
post.PreviewUrl,
ExistState.Exist,
DateTimeOffset.FromUnixTimeSeconds(post.Change),
new Uploader(-1, post.Owner.Replace('_', ' ')),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public async Task<Post> GetPostAsync(int postId)
new PostIdentity(postId, post.Md5),
post.FileUrl,
post.SampleUrl ?? post.FileUrl,
post.PreviewUrl,
ExistState.Exist,
DateTimeOffset.FromUnixTimeSeconds(post.CreatedAt.S),
new Uploader(post.Author.Id, post.Author.Name),
Expand Down Expand Up @@ -99,6 +100,7 @@ await GetTags(post),
new PostIdentity(post.Id, post.Md5),
post.FileUrl,
post.SampleUrl ?? post.FileUrl,
post.PreviewUrl,
ExistState.Exist,
DateTimeOffset.FromUnixTimeSeconds(post.CreatedAt.S),
new Uploader(post.Author.Id, post.Author.Name),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ private async Task<Post> GetPost(int postId, YanderePost post, HtmlDocument post
new PostIdentity(postId, post.Md5),
post.FileUrl,
post.SampleUrl ?? post.JpegUrl,
post.JpegUrl,
GetExistState(postHtml),
DateTimeOffset.FromUnixTimeSeconds(post.CreatedAt),
new Uploader(post.CreatorId ?? -1, post.Author),
Expand Down

0 comments on commit e0e92a8

Please sign in to comment.