feat: extract file listing

This commit is contained in:
Guillermo Marcel 2025-03-28 22:42:56 -03:00
parent 513a9d6d45
commit bd5044be42

View File

@ -19,7 +19,7 @@ public class AutoScanApp
private readonly IScheduler _scheduler; private readonly IScheduler _scheduler;
private readonly IChainerListenerFactory _chainerListenerFactory; private readonly IChainerListenerFactory _chainerListenerFactory;
public Func<AutoScanOptions, Task>? OnScanCompleted { get; set; } public Func<Task>? OnScanCompleted { get; set; }
public AutoScanApp(IOptions<AutoScanOptions> options, ILogger<AutoScanApp> logger, IScheduler scheduler, IChainerListenerFactory chainerListenerFactory) public AutoScanApp(IOptions<AutoScanOptions> options, ILogger<AutoScanApp> logger, IScheduler scheduler, IChainerListenerFactory chainerListenerFactory)
{ {
@ -72,7 +72,7 @@ public class AutoScanApp
.AddJob(downloaderJob) .AddJob(downloaderJob)
.AddJob(scannerJob) .AddJob(scannerJob)
.AddJob(cleanJob) .AddJob(cleanJob)
.OnFinish(async () => await OnScanCompleted?.Invoke(_options)) .OnFinish(async () => await OnScanCompleted?.Invoke())
.Build(); .Build();
_scheduler.ListenerManager.AddJobListener(chainer, GroupMatcher<JobKey>.GroupEquals(GROUP_NAME)); _scheduler.ListenerManager.AddJobListener(chainer, GroupMatcher<JobKey>.GroupEquals(GROUP_NAME));
@ -90,6 +90,24 @@ public class AutoScanApp
await _scheduler.TriggerJob(jobKey); await _scheduler.TriggerJob(jobKey);
} }
public string[] GetLastScanPictures()
{
if (_options.Scanner?.DetectionFolder is null)
return [];
return Directory.GetFiles(_options.Scanner.DetectionFolder , "*.jpg");
}
public string? GetVideoPath(string name)
{
var path = Path.Combine(_options.Scanner.DetectionFolder, name + ".avi");
if (!File.Exists(path))
{
_logger.LogWarning("File {Path} does not exist", path);
return null;
}
return path;
}
private string CronFromAt(string at) private string CronFromAt(string at)
{ {