mirror of
https://github.com/collinbarrett/FilterLists.git
synced 2026-03-11 09:04:27 +00:00
rm 'weasel word' - 'Info'
This commit is contained in:
parent
b4d294a520
commit
b9b9625bbd
14 changed files with 62 additions and 59 deletions
|
|
@ -1,9 +1,10 @@
|
|||
using System.Net.Http;
|
||||
|
||||
namespace FilterLists.Agent.Core
|
||||
namespace FilterLists.Agent.Core.List
|
||||
{
|
||||
public interface IListRepository
|
||||
{
|
||||
//TODO: expose GetList() method rather than HttpClient
|
||||
HttpClient HttpClient { get; }
|
||||
}
|
||||
}
|
||||
11
src/FilterLists.Agent/Core/List/IListUrlRepository.cs
Normal file
11
src/FilterLists.Agent/Core/List/IListUrlRepository.cs
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FilterLists.Agent.Core.List
|
||||
{
|
||||
public interface IListUrlRepository
|
||||
{
|
||||
Task<IEnumerable<ListUrl>> GetAllAsync(CancellationToken cancellationToken);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,10 +1,10 @@
|
|||
using System;
|
||||
using JetBrains.Annotations;
|
||||
|
||||
namespace FilterLists.Agent.Core.ListInfo
|
||||
namespace FilterLists.Agent.Core.List
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public class ListInfo
|
||||
public class ListUrl
|
||||
{
|
||||
public int Id { get; [UsedImplicitly] private set; }
|
||||
public Uri ViewUrl { get; [UsedImplicitly] private set; }
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FilterLists.Agent.Core.ListInfo
|
||||
{
|
||||
public interface IListInfoRepository
|
||||
{
|
||||
Task<IEnumerable<ListInfo>> GetAllAsync(CancellationToken cancellationToken);
|
||||
}
|
||||
}
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using FilterLists.Agent.Core.ListInfo;
|
||||
using FilterLists.Agent.Core.List;
|
||||
|
||||
namespace FilterLists.Agent.Extensions
|
||||
{
|
||||
|
|
@ -35,7 +35,7 @@ public static IEnumerable<Uri> DistributeByHost(this IEnumerable<Uri> listInfo)
|
|||
return listInfoList.Where(u => !u.IsValidUrl()).Concat(distributedLists);
|
||||
}
|
||||
|
||||
public static IEnumerable<ListInfo> DistributeByHost(this IEnumerable<ListInfo> listInfo)
|
||||
public static IEnumerable<ListUrl> DistributeByHost(this IEnumerable<ListUrl> listInfo)
|
||||
{
|
||||
return listInfo.GroupBy(l => l.ViewUrl.Host)
|
||||
.SelectMany((g, gi) => g.Select((l, i) => new {Index = i, GroupIndex = gi, ListInfo = l}))
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using FilterLists.Agent.Core.ListInfo;
|
||||
using FilterLists.Agent.Core.List;
|
||||
using MediatR;
|
||||
|
||||
namespace FilterLists.Agent.Features.Lists
|
||||
|
|
@ -14,12 +14,12 @@ public class Command : IRequest
|
|||
public class Handler : AsyncRequestHandler<Command>
|
||||
{
|
||||
private readonly IMediator _mediator;
|
||||
private readonly IListInfoRepository _repo;
|
||||
private readonly IListUrlRepository _repo;
|
||||
|
||||
public Handler(IMediator mediator, IListInfoRepository listInfoRepository)
|
||||
public Handler(IMediator mediator, IListUrlRepository listUrlRepository)
|
||||
{
|
||||
_mediator = mediator;
|
||||
_repo = listInfoRepository;
|
||||
_repo = listUrlRepository;
|
||||
}
|
||||
|
||||
protected override async Task Handle(Command request, CancellationToken cancellationToken)
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Threading.Tasks.Dataflow;
|
||||
using FilterLists.Agent.Core.ListInfo;
|
||||
using FilterLists.Agent.Core.List;
|
||||
using FilterLists.Agent.Extensions;
|
||||
using MediatR;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
|
@ -15,20 +15,20 @@ public static class DownloadLists
|
|||
{
|
||||
public class Command : IRequest
|
||||
{
|
||||
public Command(IEnumerable<ListInfo> listInfo)
|
||||
public Command(IEnumerable<ListUrl> listInfo)
|
||||
{
|
||||
ListInfo = listInfo;
|
||||
}
|
||||
|
||||
public IEnumerable<ListInfo> ListInfo { get; }
|
||||
public IEnumerable<ListUrl> ListInfo { get; }
|
||||
}
|
||||
|
||||
public class Handler : AsyncRequestHandler<Command>
|
||||
{
|
||||
private const int MaxDegreeOfParallelism = 5;
|
||||
|
||||
private static readonly Dictionary<string, Func<ListInfo, IRequest>> CommandsByExtension
|
||||
= new Dictionary<string, Func<ListInfo, IRequest>>
|
||||
private static readonly Dictionary<string, Func<ListUrl, IRequest>> CommandsByExtension
|
||||
= new Dictionary<string, Func<ListUrl, IRequest>>
|
||||
{
|
||||
{"", l => new DownloadRawText.Command(l)},
|
||||
{".7z", l => new DownloadSevenZip.Command(l)},
|
||||
|
|
@ -76,9 +76,9 @@ protected override async Task Handle(Command request, CancellationToken cancella
|
|||
await downloader.Completion;
|
||||
}
|
||||
|
||||
private ActionBlock<ListInfo> BuildDownloader(CancellationToken cancellationToken)
|
||||
private ActionBlock<ListUrl> BuildDownloader(CancellationToken cancellationToken)
|
||||
{
|
||||
return new ActionBlock<ListInfo>(
|
||||
return new ActionBlock<ListUrl>(
|
||||
async l =>
|
||||
{
|
||||
var errorMessage = $"Error downloading list {l.Id} from {l.ViewUrl}.";
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using FilterLists.Agent.Core;
|
||||
using FilterLists.Agent.Core.ListInfo;
|
||||
using FilterLists.Agent.Core.List;
|
||||
using FilterLists.Agent.Extensions;
|
||||
using MediatR;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
|
@ -15,12 +15,12 @@ public static class DownloadRawText
|
|||
{
|
||||
public class Command : IRequest
|
||||
{
|
||||
public Command(ListInfo listInfo)
|
||||
public Command(ListUrl listUrl)
|
||||
{
|
||||
ListInfo = listInfo;
|
||||
ListUrl = listUrl;
|
||||
}
|
||||
|
||||
public ListInfo ListInfo { get; }
|
||||
public ListUrl ListUrl { get; }
|
||||
}
|
||||
|
||||
public class Handler : AsyncRequestHandler<Command>
|
||||
|
|
@ -38,10 +38,10 @@ public Handler(IListRepository listRepository, ILogger<Handler> logger)
|
|||
|
||||
protected override async Task Handle(Command request, CancellationToken cancellationToken)
|
||||
{
|
||||
var sourceExtension = request.ListInfo.ViewUrl.GetExtension();
|
||||
var sourceExtension = request.ListUrl.ViewUrl.GetExtension();
|
||||
var destinationExtension = _extensionsToRewrite.Contains(sourceExtension) ? ".txt" : sourceExtension;
|
||||
var destinationPath = Path.Combine(RepoDirectory, $"{request.ListInfo.Id}{destinationExtension}");
|
||||
using (var response = await _httpClient.GetAsync(request.ListInfo.ViewUrl, cancellationToken))
|
||||
var destinationPath = Path.Combine(RepoDirectory, $"{request.ListUrl.Id}{destinationExtension}");
|
||||
using (var response = await _httpClient.GetAsync(request.ListUrl.ViewUrl, cancellationToken))
|
||||
{
|
||||
if (response.IsSuccessStatusCode)
|
||||
using (var input = await response.Content.ReadAsStreamAsync())
|
||||
|
|
@ -51,7 +51,7 @@ protected override async Task Handle(Command request, CancellationToken cancella
|
|||
}
|
||||
else
|
||||
_logger.LogError(
|
||||
$"Error downloading list {request.ListInfo.Id} from {request.ListInfo.ViewUrl}. {response.StatusCode}");
|
||||
$"Error downloading list {request.ListUrl.Id} from {request.ListUrl.ViewUrl}. {response.StatusCode}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using FilterLists.Agent.Core;
|
||||
using FilterLists.Agent.Core.ListInfo;
|
||||
using FilterLists.Agent.Core.List;
|
||||
using MediatR;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SharpCompress.Archives;
|
||||
|
|
@ -16,12 +16,12 @@ public static class DownloadSevenZip
|
|||
{
|
||||
public class Command : IRequest
|
||||
{
|
||||
public Command(ListInfo listInfo)
|
||||
public Command(ListUrl listUrl)
|
||||
{
|
||||
ListInfo = listInfo;
|
||||
ListUrl = listUrl;
|
||||
}
|
||||
|
||||
public ListInfo ListInfo { get; }
|
||||
public ListUrl ListUrl { get; }
|
||||
}
|
||||
|
||||
public class Handler : AsyncRequestHandler<Command>
|
||||
|
|
@ -38,8 +38,8 @@ public Handler(IListRepository listRepository, ILogger<Handler> logger)
|
|||
|
||||
protected override async Task Handle(Command request, CancellationToken cancellationToken)
|
||||
{
|
||||
var destinationDirectoryPath = Path.Combine(RepoDirectory, $"{request.ListInfo.Id}");
|
||||
using (var response = await _httpClient.GetAsync(request.ListInfo.ViewUrl, cancellationToken))
|
||||
var destinationDirectoryPath = Path.Combine(RepoDirectory, $"{request.ListUrl.Id}");
|
||||
using (var response = await _httpClient.GetAsync(request.ListUrl.ViewUrl, cancellationToken))
|
||||
{
|
||||
if (response.IsSuccessStatusCode)
|
||||
using (var input = await response.Content.ReadAsStreamAsync())
|
||||
|
|
@ -52,7 +52,7 @@ protected override async Task Handle(Command request, CancellationToken cancella
|
|||
}
|
||||
else
|
||||
_logger.LogError(
|
||||
$"Error downloading list {request.ListInfo.Id} from {request.ListInfo.ViewUrl}. {response.StatusCode}");
|
||||
$"Error downloading list {request.ListUrl.Id} from {request.ListUrl.ViewUrl}. {response.StatusCode}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using FilterLists.Agent.Core;
|
||||
using FilterLists.Agent.Core.ListInfo;
|
||||
using FilterLists.Agent.Core.List;
|
||||
using MediatR;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SharpCompress.Common;
|
||||
|
|
@ -15,12 +15,12 @@ public static class DownloadZip
|
|||
{
|
||||
public class Command : IRequest
|
||||
{
|
||||
public Command(ListInfo listInfo)
|
||||
public Command(ListUrl listUrl)
|
||||
{
|
||||
ListInfo = listInfo;
|
||||
ListUrl = listUrl;
|
||||
}
|
||||
|
||||
public ListInfo ListInfo { get; }
|
||||
public ListUrl ListUrl { get; }
|
||||
}
|
||||
|
||||
public class Handler : AsyncRequestHandler<Command>
|
||||
|
|
@ -37,8 +37,8 @@ public Handler(IListRepository listRepository, ILogger<Handler> logger)
|
|||
|
||||
protected override async Task Handle(Command request, CancellationToken cancellationToken)
|
||||
{
|
||||
var destinationDirectoryPath = Path.Combine(RepoDirectory, $"{request.ListInfo.Id}");
|
||||
using (var response = await _httpClient.GetAsync(request.ListInfo.ViewUrl, cancellationToken))
|
||||
var destinationDirectoryPath = Path.Combine(RepoDirectory, $"{request.ListUrl.Id}");
|
||||
using (var response = await _httpClient.GetAsync(request.ListUrl.ViewUrl, cancellationToken))
|
||||
{
|
||||
if (response.IsSuccessStatusCode)
|
||||
using (var input = await response.Content.ReadAsStreamAsync())
|
||||
|
|
@ -51,7 +51,7 @@ protected override async Task Handle(Command request, CancellationToken cancella
|
|||
}
|
||||
else
|
||||
_logger.LogError(
|
||||
$"Error downloading list {request.ListInfo.Id} from {request.ListInfo.ViewUrl}. {response.StatusCode}");
|
||||
$"Error downloading list {request.ListUrl.Id} from {request.ListUrl.ViewUrl}. {response.StatusCode}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
using CommandLine;
|
||||
using FilterLists.Agent.AppSettings;
|
||||
using FilterLists.Agent.Core;
|
||||
using FilterLists.Agent.Core.List;
|
||||
using FilterLists.Agent.Infrastructure.FilterListsApi;
|
||||
using FilterLists.Agent.Infrastructure.GitHub;
|
||||
using LibGit2Sharp;
|
||||
|
|
|
|||
|
|
@ -1,31 +1,31 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using FilterLists.Agent.Core.ListInfo;
|
||||
using FilterLists.Agent.Core.List;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using RestSharp;
|
||||
|
||||
namespace FilterLists.Agent.Infrastructure.FilterListsApi
|
||||
{
|
||||
public class ListInfoRepository : IListInfoRepository
|
||||
public class ListUrlRepository : IListUrlRepository
|
||||
{
|
||||
private readonly IRestClient _apiClient;
|
||||
private readonly IStringLocalizer<ListInfoRepository> _localizer;
|
||||
private readonly ILogger<ListInfoRepository> _logger;
|
||||
private readonly IStringLocalizer<ListUrlRepository> _localizer;
|
||||
private readonly ILogger<ListUrlRepository> _logger;
|
||||
|
||||
public ListInfoRepository(IRestClient apiClient, IStringLocalizer<ListInfoRepository> stringLocalizer,
|
||||
ILogger<ListInfoRepository> logger)
|
||||
public ListUrlRepository(IRestClient apiClient, IStringLocalizer<ListUrlRepository> stringLocalizer,
|
||||
ILogger<ListUrlRepository> logger)
|
||||
{
|
||||
_apiClient = apiClient;
|
||||
_localizer = stringLocalizer;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<ListInfo>> GetAllAsync(CancellationToken cancellationToken)
|
||||
public async Task<IEnumerable<ListUrl>> GetAllAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
var listsRequest = new RestRequest("lists");
|
||||
var response = await _apiClient.ExecuteTaskAsync<IEnumerable<ListInfo>>(listsRequest, cancellationToken);
|
||||
var response = await _apiClient.ExecuteTaskAsync<IEnumerable<ListUrl>>(listsRequest, cancellationToken);
|
||||
if (response.ErrorException != null)
|
||||
_logger.LogError(response.ErrorException,
|
||||
_localizer["Error retrieving response from the FilterLists API."]);
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
using FilterLists.Agent.AppSettings;
|
||||
using FilterLists.Agent.Core.ListInfo;
|
||||
using FilterLists.Agent.Core.List;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Options;
|
||||
using RestSharp;
|
||||
|
|
@ -15,7 +15,7 @@ public static void AddFilterListsApiResources(this IServiceCollection services)
|
|||
var filterListsApiSettings = b.GetService<IOptions<FilterListsApiSettings>>().Value;
|
||||
return new RestClient(filterListsApiSettings.BaseUrl) {UserAgent = "FilterLists.Agent"};
|
||||
});
|
||||
services.AddTransient<IListInfoRepository, ListInfoRepository>();
|
||||
services.AddTransient<IListUrlRepository, ListUrlRepository>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -2,6 +2,7 @@
|
|||
using System.Net.Http;
|
||||
using System.Net.Http.Headers;
|
||||
using FilterLists.Agent.Core;
|
||||
using FilterLists.Agent.Core.List;
|
||||
using JetBrains.Annotations;
|
||||
|
||||
namespace FilterLists.Agent.Infrastructure
|
||||
|
|
|
|||
Loading…
Reference in a new issue