mirror of
https://github.com/collinbarrett/FilterLists.git
synced 2026-03-11 09:04:27 +00:00
refactor(archival): ♻ persist archives w/o extension, misc rens
This commit is contained in:
parent
d7a036388f
commit
b6e619acb7
4 changed files with 24 additions and 17 deletions
|
|
@ -34,18 +34,18 @@ public class Handler : IRequestHandler<Command, Unit>
|
|||
private readonly IHttpContentClient _client;
|
||||
private readonly IDirectoryApi _directory;
|
||||
private readonly ILogger _logger;
|
||||
private readonly ITxtFileRepository _repo;
|
||||
private readonly IFileRepository _repo;
|
||||
|
||||
public Handler(
|
||||
IHttpContentClient httpContentClient,
|
||||
IDirectoryApi directoryApi,
|
||||
ILogger<Handler> logger,
|
||||
ITxtFileRepository txtFileRepository)
|
||||
IFileRepository fileRepository)
|
||||
{
|
||||
_client = httpContentClient;
|
||||
_directory = directoryApi;
|
||||
_logger = logger;
|
||||
_repo = txtFileRepository;
|
||||
_repo = fileRepository;
|
||||
}
|
||||
|
||||
public async Task<Unit> Handle(Command request, CancellationToken cancellationToken)
|
||||
|
|
@ -67,7 +67,7 @@ public async Task<Unit> Handle(Command request, CancellationToken cancellationTo
|
|||
}
|
||||
else
|
||||
{
|
||||
_logger.LogInformation("List {ListId} has no URLs to archive", request.ListId);
|
||||
_logger.LogWarning("List {ListId} has no URLs to archive", request.ListId);
|
||||
}
|
||||
|
||||
return Unit.Value;
|
||||
|
|
@ -89,7 +89,7 @@ private IFile GetFileToArchive(
|
|||
CancellationToken cancellationToken)
|
||||
{
|
||||
var segmentsAsync = GetSegmentsAsync(segmentUrls, cancellationToken);
|
||||
var target = $"{listId.ToString(CultureInfo.InvariantCulture).PadLeft(5, '0')}.txt";
|
||||
var target = listId.ToString(CultureInfo.InvariantCulture).PadLeft(5, '0');
|
||||
return new File(segmentsAsync, target);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ public interface IHttpContentClient : IDisposable
|
|||
internal sealed class HttpContentClient : IHttpContentClient
|
||||
{
|
||||
private readonly HttpClient _httpClient;
|
||||
private readonly ICollection<HttpResponseMessage> _httpResponseMessages = new List<HttpResponseMessage>();
|
||||
private readonly ICollection<HttpResponseMessage> _httpResponseMessages = new HashSet<HttpResponseMessage>();
|
||||
private readonly ILogger _logger;
|
||||
|
||||
public HttpContentClient(HttpClient httpClient, ILogger<HttpContentClient> logger)
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ public static void AddPersistenceServices(this IServiceCollection services, ICon
|
|||
|
||||
return new Repository(gitOptions.RepositoryPath);
|
||||
});
|
||||
services.AddTransient<ITxtFileRepository, GitTxtFileRepository>();
|
||||
services.AddTransient<IFileRepository, GitFileRepository>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,20 +13,20 @@
|
|||
|
||||
namespace FilterLists.Archival.Infrastructure.Persistence
|
||||
{
|
||||
public interface ITxtFileRepository : IUnitOfWork
|
||||
public interface IFileRepository : IUnitOfWork
|
||||
{
|
||||
Task AddFileAsync(IFile file, CancellationToken cancellationToken);
|
||||
}
|
||||
|
||||
internal sealed class GitTxtFileRepository : ITxtFileRepository
|
||||
internal sealed class GitFileRepository : IFileRepository
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly GitOptions _options;
|
||||
private readonly IRepository _repo;
|
||||
private readonly ICollection<FileInfo> _writtenFiles = new HashSet<FileInfo>();
|
||||
|
||||
public GitTxtFileRepository(
|
||||
ILogger<GitTxtFileRepository> logger,
|
||||
public GitFileRepository(
|
||||
ILogger<GitFileRepository> logger,
|
||||
IOptions<GitOptions> gitOptions,
|
||||
IRepository repository)
|
||||
{
|
||||
|
|
@ -70,13 +70,20 @@ public async Task AddFileAsync(IFile file, CancellationToken cancellationToken)
|
|||
|
||||
public void Commit()
|
||||
{
|
||||
var fileNames = _writtenFiles.Select(f => f.Name).ToList();
|
||||
var signature = new Signature(_options.UserName, _options.UserEmail, DateTime.UtcNow);
|
||||
var message = $"feat(archives): archive {fileNames.Count} file(s){Environment.NewLine}{string.Join(Environment.NewLine, fileNames)}";
|
||||
Commands.Stage(_repo, fileNames);
|
||||
_repo.Commit(message, signature, signature);
|
||||
if (_writtenFiles.Count > 0)
|
||||
{
|
||||
var fileNames = _writtenFiles.Select(f => f.Name).ToList();
|
||||
var signature = new Signature(_options.UserName, _options.UserEmail, DateTime.UtcNow);
|
||||
var message = $"feat(archives): archive {fileNames.Count} file(s){Environment.NewLine}{string.Join(Environment.NewLine, fileNames)}";
|
||||
Commands.Stage(_repo, fileNames);
|
||||
_repo.Commit(message, signature, signature);
|
||||
|
||||
_logger.LogInformation("Committed {@FileNames}", fileNames);
|
||||
_logger.LogInformation("Committed {@FileNames}", fileNames);
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogInformation("No written files to commit");
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
Loading…
Reference in a new issue