feat: Add support for thumbnail inclusion in AI processing and enhance UI bindings
This commit is contained in:
parent
cb41c42bb5
commit
7e105e3738
9 changed files with 235 additions and 27 deletions
|
|
@ -34,6 +34,7 @@ public class AiExtractionService : IAiExtractionService
|
|||
|| f.EndsWith(".png", StringComparison.OrdinalIgnoreCase)
|
||||
|| f.EndsWith(".bmp", StringComparison.OrdinalIgnoreCase)
|
||||
|| f.EndsWith(".gif", StringComparison.OrdinalIgnoreCase))
|
||||
.Where(f => request.IncludeThumbnails || !Path.GetFileName(f).StartsWith("tn_", StringComparison.OrdinalIgnoreCase))
|
||||
.ToList();
|
||||
|
||||
var extractedResults = new List<AiResultItem>();
|
||||
|
|
@ -44,6 +45,7 @@ public class AiExtractionService : IAiExtractionService
|
|||
var processed = 0;
|
||||
var total = imageFiles.Count;
|
||||
var failed = 0;
|
||||
Exception? firstFailure = null;
|
||||
|
||||
foreach (var file in imageFiles)
|
||||
{
|
||||
|
|
@ -58,6 +60,7 @@ public class AiExtractionService : IAiExtractionService
|
|||
catch (Exception ex)
|
||||
{
|
||||
failed++;
|
||||
firstFailure ??= ex;
|
||||
_logger.LogWarning(ex, "Error processing AI OCR for {File}", file);
|
||||
}
|
||||
|
||||
|
|
@ -72,7 +75,7 @@ public class AiExtractionService : IAiExtractionService
|
|||
|
||||
if (imageFiles.Count > 0 && failed == imageFiles.Count)
|
||||
{
|
||||
throw new InvalidOperationException($"AI OCR failed for all {imageFiles.Count} image(s). See previous log entries for details.");
|
||||
throw new InvalidOperationException($"AI OCR failed for all {imageFiles.Count} image(s). See previous log entries for details.", firstFailure);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(request.CsvOutputPath))
|
||||
|
|
@ -89,8 +92,9 @@ public class AiExtractionService : IAiExtractionService
|
|||
sw.WriteLine("Path,Text");
|
||||
foreach (var r in extractedResults)
|
||||
{
|
||||
var csvFileName = Path.GetFileName(r.Path ?? string.Empty);
|
||||
var safeText = (r.Text ?? string.Empty).Replace("\"", "\"\"");
|
||||
sw.WriteLine($"\"{r.Path}\",\"{safeText}\"");
|
||||
sw.WriteLine($"\"{csvFileName}\",\"{safeText}\"");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue