Skip to content

Commit 3bbd23d

Browse files
committed
Fix radarr API issue
1 parent df120b0 commit 3bbd23d

2 files changed

Lines changed: 57 additions & 10 deletions

File tree

app/Http/Controllers/Api/ApiController.php

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -313,9 +313,6 @@ public function api(Request $request)
313313
$this->verifyEmptyParameter($request, 'imdbid');
314314
$this->verifyEmptyParameter($request, 'tmdbid');
315315
$this->verifyEmptyParameter($request, 'traktid');
316-
if (! $this->hasMovieSearchParameters($request)) {
317-
return showApiError(200, 'Missing parameter (q, imdbid, tmdbid or traktid)');
318-
}
319316
$maxAge = $this->maxAge($request);
320317
if (! is_int($maxAge)) {
321318
return $maxAge;
@@ -325,6 +322,28 @@ public function api(Request $request)
325322
return $sort;
326323
}
327324
UserRequest::addApiRequest($uid, $request->getRequestUri());
325+
$categoryID = $this->categoryID($request);
326+
$limit = $this->limit($request);
327+
328+
if (! $this->hasMovieSearchParameters($request)) {
329+
if ($categoryID === [-1]) {
330+
$categoryID = Category::MOVIES_GROUP;
331+
}
332+
333+
$relData = $this->releaseBrowseService->getBrowseRangeForApi(
334+
1,
335+
$categoryID,
336+
$offset,
337+
$limit,
338+
$sort,
339+
$maxAge,
340+
$catExclusions,
341+
-1,
342+
$minSize
343+
);
344+
$this->output($relData, $params, $outputXML, $offset, 'api');
345+
break;
346+
}
328347

329348
$imdbId = $request->has('imdbid') && $request->filled('imdbid')
330349
? (string) Str::replace('tt', '', (string) $request->input('imdbid'))
@@ -337,9 +356,9 @@ public function api(Request $request)
337356
$tmdbId,
338357
$traktId,
339358
$this->offset($request),
340-
$this->limit($request),
359+
$limit,
341360
$request->input('q') ?? '',
342-
$this->categoryID($request),
361+
$categoryID,
343362
$maxAge,
344363
$minSize,
345364
$catExclusions,

tests/Feature/ApiRequestMatrixTest.php

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,43 @@ public function test_v2_invalid_maxage_returns_json_400_error(): void
7979
->assertJsonPath('error', 'Incorrect parameter (maxage must be numeric)');
8080
}
8181

82-
public function test_v1_movie_requires_query_or_external_id(): void
82+
public function test_v1_movie_without_search_params_returns_recent_movie_feed(): void
8383
{
8484
$token = (string) DB::table('users')->value('api_token');
85+
$request = Request::create('/api/v1/api', 'GET', [
86+
't' => 'm',
87+
'apikey' => $token,
88+
]);
89+
90+
$releaseSearchService = Mockery::mock(ReleaseSearchService::class);
91+
$releaseBrowseService = Mockery::mock(ReleaseBrowseService::class);
92+
$releaseBrowseService->shouldReceive('getBrowseRangeForApi')
93+
->once()
94+
->andReturn(collect());
8595

86-
$response = $this->get('/api/v1/api?t=m&apikey='.$token);
96+
$controller = new class($releaseSearchService, $releaseBrowseService) extends ApiController
97+
{
98+
/**
99+
* @var array{data:mixed,params:array<string,mixed>,xml:bool,offset:int,type:string}|null
100+
*/
101+
public ?array $capturedOutput = null;
87102

88-
$response->assertOk();
89-
$response->assertSee('<error code="200"', false);
90-
$response->assertSee('Missing parameter (q, imdbid, tmdbid or traktid)', false);
103+
public function output(mixed $data, array $params, bool $xml, int $offset, string $type = '')
104+
{
105+
$this->capturedOutput = [
106+
'data' => $data,
107+
'params' => $params,
108+
'xml' => $xml,
109+
'offset' => $offset,
110+
'type' => $type,
111+
];
112+
}
113+
};
114+
115+
$controller->api($request);
116+
$this->assertNotNull($controller->capturedOutput);
117+
$this->assertSame('api', $controller->capturedOutput['type']);
118+
$this->assertInstanceOf(Collection::class, $controller->capturedOutput['data']);
91119
}
92120

93121
public function test_v1_tv_without_search_params_returns_recent_tv_feed(): void

0 commit comments

Comments
 (0)