Updated scanner logic, and added initial scanner tests.

This commit is contained in:
2025-09-14 21:12:00 -04:00
parent 39274165cb
commit 646cf41476
16 changed files with 412 additions and 192 deletions

View File

@@ -6,12 +6,12 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.8" />
</ItemGroup>
<ItemGroup>
<Folder Include="Tags\Queries\Ports\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.9" />
</ItemGroup>
</Project>

View File

@@ -8,8 +8,8 @@ public class DLSiteWork
public string? ProductUrl { get; set; }
public string? ProductId { get; set; }
public DateOnly? AnnouncedDate { get; set; }
public DateTime? ExpectedDate { get; set; }
public DateTime? SalesDate { get; set; }
public DateOnly? ExpectedDate { get; set; }
public DateOnly? SalesDate { get; set; }
public int? Downloads { get; set; }
public byte? StarRating { get; set; }
public int? Votes { get; set; }

View File

@@ -0,0 +1,3 @@
namespace JSMR.Application.Scanning.Contracts;
public record VoiceWorkScanOptions(int PageNumber, int PageSize, string[] ExcludedMakerIds, bool ExcludePartiallyAIGeneratedWorks, bool ExcludeAIGeneratedWorks);

View File

@@ -4,5 +4,5 @@ namespace JSMR.Application.Scanning.Ports;
public interface IVoiceWorksScanner
{
Task<IReadOnlyList<DLSiteWork>> ScanPageAsync(ScanVoiceWorksRequest request, CancellationToken cancellationToken = default);
Task<IReadOnlyList<DLSiteWork>> ScanPageAsync(VoiceWorkScanOptions request, CancellationToken cancellationToken = default);
}

View File

@@ -1,26 +1,53 @@
using JSMR.Application.Scanning.Ports;
using JSMR.Application.Common.Caching;
using JSMR.Application.Integrations.DLSite.Models;
using JSMR.Application.Integrations.Ports;
using JSMR.Application.Scanning.Contracts;
using JSMR.Application.Scanning.Ports;
using Microsoft.Extensions.DependencyInjection;
namespace JSMR.Application.Scanning;
public sealed class ScanVoiceWorksHandler(IVoiceWorksScanner scanner)
public sealed class ScanVoiceWorksHandler(IServiceProvider serviceProvider, IDLSiteClient dlsiteClient, ISpamCircleCache spamCircleCache)
{
//public async Task<ScanVoiceWorksResponse> HandleAsync(ScanVoiceWorksRequest request, CancellationToken cancellationToken)
//{
// var works = await scanner.ScanPageAsync(request, cancellationToken);
public async Task<ScanVoiceWorksResponse> HandleAsync(ScanVoiceWorksRequest request, CancellationToken cancellationToken)
{
IVoiceWorksScanner? scanner = serviceProvider.GetKeyedService<IVoiceWorksScanner>(request.Locale);
// if (works.Count == 0)
// return new ScanVoiceWorksResponse();
if (scanner is null)
return new();
// var ingests = works.Select(VoiceWorkIngest.From).ToList();
// var upsert = await _writer.UpsertAsync(ingests, ct);
VoiceWorkScanOptions options = new(
PageNumber: request.PageNumber,
PageSize: request.PageSize,
ExcludedMakerIds: await spamCircleCache.GetAsync(cancellationToken),
ExcludePartiallyAIGeneratedWorks: true,
ExcludeAIGeneratedWorks: true
);
// // only update search text for affected rows
// await _search.UpdateAsync(upsert.AffectedVoiceWorkIds, ct);
IReadOnlyList<DLSiteWork> works = await scanner.ScanPageAsync(options, cancellationToken);
// return new ScanVoiceWorksResponse
// {
// Inserted = upsert.Inserted,
// Updated = upsert.Updated
// };
//}
if (works.Count == 0)
return new();
string[] productIds = [.. works.Where(x => !string.IsNullOrWhiteSpace(x.ProductId)).Select(x => x.ProductId!)];
VoiceWorkDetailCollection voiceWorkDetails = await dlsiteClient.GetVoiceWorkDetailsAsync(productIds, cancellationToken);
// TODO
/*
var ingests = works.Select(VoiceWorkIngest.From).ToList();
var upsert = await _writer.UpsertAsync(ingests, ct);
// only update search text for affected rows
await _search.UpdateAsync(upsert.AffectedVoiceWorkIds, ct);
return new ScanVoiceWorksResponse
{
Inserted = upsert.Inserted,
Updated = upsert.Updated
};
*/
return new();
}
}

View File

@@ -2,4 +2,4 @@
namespace JSMR.Application.Scanning;
public sealed record ScanVoiceWorksRequest(int PageNumber, int PageSize, Locale Locale);
public sealed record ScanVoiceWorksRequest(int PageNumber, int PageSize, Locale Locale, string[] ExcludedMakerIds);