Scope raw search mode to Prowlarr API route

This commit is contained in:
Tomer Horowitz 2026-03-07 22:12:02 +02:00
parent a7e44d15df
commit ea5f5fdaea
4 changed files with 33 additions and 0 deletions

View file

@ -0,0 +1,18 @@
using FluentAssertions;
using Microsoft.AspNetCore.Http;
using NUnit.Framework;
using NzbDrone.Api.V1.Indexers;
namespace Prowlarr.Api.V1.Test.Indexers
{
public class NewznabControllerFixture
{
[TestCase("/api/v1/indexer/12/newznab", true)]
[TestCase("/12/api", false)]
[TestCase("/api/v1/indexer/12/download", false)]
public void should_only_allow_extended_search_parameters_on_prowlarr_newznab_route(string path, bool expected)
{
NewznabController.SupportsExtendedSearchParameters(new PathString(path)).Should().Be(expected);
}
}
}

View file

@ -7,6 +7,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\NzbDrone.Core\Prowlarr.Core.csproj" />
<ProjectReference Include="..\Prowlarr.Api.V1\Prowlarr.Api.V1.csproj" />
<ProjectReference Include="..\NzbDrone.Test.Common\Prowlarr.Test.Common.csproj" />
<ProjectReference Include="..\Prowlarr.Http\Prowlarr.Http.csproj" />
</ItemGroup>

View file

@ -0,0 +1,3 @@
using System.Runtime.CompilerServices;
[assembly: InternalsVisibleTo("Prowlarr.Api.V1.Test")]

View file

@ -58,6 +58,11 @@ public NewznabController(IndexerFactory indexerFactory,
[HttpGet("{id:int}/api")]
public async Task<IActionResult> GetNewznabResponse(int id, [FromQuery] NewznabRequest request)
{
if (!SupportsExtendedSearchParameters(Request.Path))
{
request.searchMode = null;
}
var requestType = request.t;
request.source = Request.GetSource();
request.server = Request.GetServerUrl();
@ -206,6 +211,12 @@ public async Task<IActionResult> GetNewznabResponse(int id, [FromQuery] NewznabR
}
}
internal static bool SupportsExtendedSearchParameters(PathString path)
{
return path.Value?.StartsWith("/api/v1/indexer/", StringComparison.OrdinalIgnoreCase) == true &&
path.Value.EndsWith("/newznab", StringComparison.OrdinalIgnoreCase);
}
[HttpGet("/api/v1/indexer/{id:int}/download")]
[HttpGet("{id:int}/download")]
public async Task<object> GetDownload(int id, string link, string file)