Skip to content

Commit

Permalink
Some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Fazzani committed Dec 29, 2024
1 parent 760cf6b commit 1be0c88
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 23 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
</a>

<p align="center">
Automatically categorize your requested movies and tv shows from your watching providers.
Prevents Sonarr/Radarr from downloading media already available for your region on streaming services (e.g., Netflix, Amazon Prime Video)
<br />
<a href="https://github.com/Fazzani/Proxarr/issues/new?labels=bug&template=bug-report.yml">:boom: Report Bug :boom:</a>
·
Expand Down Expand Up @@ -127,9 +127,12 @@ docker run -itd --rm -e LOG_LEVEL=Debug -p 8880:8880 -v ${PWD}/config:/app/confi
## Roadmap

- [ ] Add more providers (JustWatch, Reelgood, etc)
- [ ] Global error handling
- [ ] Add more tests
- [ ] Improve logging and error handling
- [ ] Improve logging
- [ ] Add Api versioning
- [ ] HealthCheck: change log level to debug
- [ ] Add security

See the [open issues](https://github.com/Fazzani/Proxarr/issues) for a full list of proposed features (and known issues).

Expand Down
15 changes: 1 addition & 14 deletions src/Proxarr.Api/Configuration/AppConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public sealed class AppConfiguration

public string FULL_SCAN_CRON { get; set; } = "0 6 * * 1";

public List<ClientInstance> Clients { get; set; }
public List<ClientConfiguration> Clients { get; set; }

Check warning on line 15 in src/Proxarr.Api/Configuration/AppConfiguration.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Clients' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 15 in src/Proxarr.Api/Configuration/AppConfiguration.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Clients' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

private Dictionary<string, string[]> _watchProviders;

Check warning on line 17 in src/Proxarr.Api/Configuration/AppConfiguration.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable field '_watchProviders' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.

Expand Down Expand Up @@ -57,17 +57,4 @@ private Dictionary<string, string[]> InitProviders()
return dict;
}
}

public sealed class ClientInstance
{
/// <summary>
/// The name of the application (Sonarr or Radarr)
/// </summary>
public required string Application { get; set; }
public required string BaseUrl { get; set; }
public required string ApiKey { get; set; }

public bool IsSonarr => Application.Equals("Sonarr", StringComparison.OrdinalIgnoreCase);
public bool IsRadarr => Application.Equals("Radarr", StringComparison.OrdinalIgnoreCase);
}
}
9 changes: 9 additions & 0 deletions src/Proxarr.Api/Configuration/ClientConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,16 @@
public sealed class ClientConfiguration
{
public const string SECTION_NAME = $"{AppConfiguration.SECTION_NAME}:Clients";

/// <summary>
/// Must be Sonarr or Radarr
/// </summary>
public required string Application { get; set; }
public required string ApiKey { get; set; }
public required string BaseUrl { get; set; }


public bool IsSonarr => Application.Equals("Sonarr", StringComparison.OrdinalIgnoreCase);
public bool IsRadarr => Application.Equals("Radarr", StringComparison.OrdinalIgnoreCase);
}
}
15 changes: 9 additions & 6 deletions src/Proxarr.Api/Core/ApiKeyDelegatingHandler.cs
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@
using Proxarr.Api.Configuration;
using Microsoft.Extensions.Options;
using Proxarr.Api.Configuration;

namespace Proxarr.Api.Core
{
public class ApiKeyDelegatingHandler : DelegatingHandler
{
private const string API_KEY_HEADER_NAME = "X-API-KEY";

private readonly IConfiguration _configuration;
private readonly AppConfiguration _configuration;
private readonly ILogger<ApiKeyDelegatingHandler> _logger;

public ApiKeyDelegatingHandler(IConfiguration configuration)
public ApiKeyDelegatingHandler(IOptions<AppConfiguration> configuration, ILogger<ApiKeyDelegatingHandler> logger)
{
_configuration = configuration;
_configuration = configuration?.Value ?? throw new ArgumentNullException(nameof(configuration));
_logger = logger;
}

protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
if (!request.Headers.Contains(API_KEY_HEADER_NAME) && request.RequestUri != null)
{
var key = $"{request.RequestUri.Scheme}://{request.RequestUri.Host}";
var clients = _configuration.GetSection(ClientConfiguration.SECTION_NAME).Get<List<ClientConfiguration>>();
var clientConfig = clients?.FirstOrDefault(x => x.BaseUrl.Equals(key, StringComparison.OrdinalIgnoreCase));
var clientConfig = _configuration.Clients?.FirstOrDefault(x => x.BaseUrl.Equals(key, StringComparison.OrdinalIgnoreCase));

if (clientConfig != null)
{
_logger.LogInformation("Adding API Key to request for {BaseUrl}", clientConfig.BaseUrl);
request.Headers.Add(API_KEY_HEADER_NAME, clientConfig.ApiKey);
}
}
Expand Down
9 changes: 8 additions & 1 deletion src/Proxarr.Api/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
});

builder.Services.AddHealthChecks();
builder.Services.AddProblemDetails();
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
builder.Services.AddOpenApi();

Expand Down Expand Up @@ -92,7 +93,11 @@
if (app.Environment.IsDevelopment())
{
app.MapOpenApi();
app.MapScalarApiReference();
app.MapScalarApiReference(opt =>
{
opt.Title = "Proxarr API";
opt.Theme = ScalarTheme.Mars;
});
}

app.UseAuthorization();
Expand All @@ -101,4 +106,6 @@

app.MapHealthChecks("/health");

app.UseExceptionHandler();

await app.RunAsync();

0 comments on commit 1be0c88

Please sign in to comment.