Updated scanner to infer when it has reached the end of results.
This commit is contained in:
@@ -18,8 +18,11 @@ public sealed class ScanVoiceWorksHandler(
|
||||
IVoiceWorksScanner? scanner = scannerRepository.GetScanner(request.Locale);
|
||||
IVoiceWorkUpdater? updater = updaterRepository.GetUpdater(request.Locale);
|
||||
|
||||
if (scanner is null || updater is null)
|
||||
return new();
|
||||
if (scanner is null)
|
||||
throw new InvalidOperationException($"No scanner registered for locale {request.Locale}.");
|
||||
|
||||
if (updater is null)
|
||||
throw new InvalidOperationException($"No updater registered for locale {request.Locale}.");
|
||||
|
||||
VoiceWorkScanOptions options = new(
|
||||
PageNumber: request.PageNumber,
|
||||
@@ -29,15 +32,20 @@ public sealed class ScanVoiceWorksHandler(
|
||||
ExcludeAIGeneratedWorks: true
|
||||
);
|
||||
|
||||
IReadOnlyList<DLSiteWork> works = await scanner.ScanPageAsync(options, cancellationToken);
|
||||
VoiceWorkScanResult scanResult = await scanner.ScanPageAsync(options, cancellationToken);
|
||||
|
||||
if (works.Count == 0)
|
||||
return new();
|
||||
if (scanResult.EndOfResults)
|
||||
{
|
||||
return new ScanVoiceWorksResponse(
|
||||
Results: [],
|
||||
EndOfResults: true
|
||||
);
|
||||
}
|
||||
|
||||
string[] productIds = [.. works.Where(x => !string.IsNullOrWhiteSpace(x.ProductId)).Select(x => x.ProductId!)];
|
||||
string[] productIds = [.. scanResult.Works.Where(x => !string.IsNullOrWhiteSpace(x.ProductId)).Select(x => x.ProductId!)];
|
||||
VoiceWorkDetailCollection voiceWorkDetails = await dlsiteClient.GetVoiceWorkDetailsAsync(productIds, cancellationToken);
|
||||
|
||||
VoiceWorkIngest[] ingests = [.. works.Select(work =>
|
||||
VoiceWorkIngest[] ingests = [.. scanResult.Works.Select(work =>
|
||||
{
|
||||
voiceWorkDetails.TryGetValue(work.ProductId!, out VoiceWorkDetails? value);
|
||||
return VoiceWorkIngest.From(work, value);
|
||||
@@ -48,9 +56,9 @@ public sealed class ScanVoiceWorksHandler(
|
||||
|
||||
await searchUpdater.UpdateAsync(voiceWorkIds, cancellationToken);
|
||||
|
||||
return new()
|
||||
{
|
||||
Results = upsertResults
|
||||
};
|
||||
return new ScanVoiceWorksResponse(
|
||||
Results: upsertResults,
|
||||
EndOfResults: false
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user