Skip to content

Commit 544b851

Browse files
committed
Update API related and Releases classes
1 parent d76f697 commit 544b851

File tree

5 files changed

+33
-54
lines changed

5 files changed

+33
-54
lines changed

Blacklight/Releases.php

+18-40
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function __construct()
6464
* @param int $minSize
6565
* @return Collection|mixed
6666
*/
67-
public function getBrowseRange($page, $cat, $start, $num, $orderBy, int $maxAge = -1, array $excludedCats = [], int|string $groupName = -1, int $minSize = 0, array $tags = [])
67+
public function getBrowseRange($page, $cat, $start, $num, $orderBy, int $maxAge = -1, array $excludedCats = [], int|string $groupName = -1, int $minSize = 0, array $tags = []): mixed
6868
{
6969
$orderBy = $this->getBrowseOrder($orderBy);
7070

@@ -161,7 +161,7 @@ public function getBrowseCount(array $cat, int $maxAge = -1, array $excludedCats
161161
/**
162162
* @return string
163163
*/
164-
public function showPasswords()
164+
public function showPasswords(): string
165165
{
166166
$show = (int) Settings::settingValue('..showpasswordedrelease');
167167
$setting = $show ?? 0;
@@ -217,13 +217,10 @@ public function getBrowseOrdering(): array
217217
}
218218

219219
/**
220-
* Get list of releases available for export.
221-
*
222-
*
223220
* @param string $postFrom
224221
* @param string $postTo
225222
* @param string $groupID
226-
* @return Collection|\Illuminate\Support\Collection|static[]
223+
* @return \App\Models\Release[]|\Illuminate\Database\Eloquent\Builder[]|\Illuminate\Database\Eloquent\Collection|\Illuminate\Database\Query\Builder[]|\Illuminate\Support\Collection
227224
*/
228225
public function getForExport(string $postFrom = '', string $postTo = '', string $groupID = '')
229226
{
@@ -257,40 +254,27 @@ public function getForExport(string $postFrom = '', string $postTo = '', string
257254
}
258255

259256
/**
260-
* Get date in this format : 01/01/2014 of the oldest release.
261-
*
262-
* @note Used for exporting NZBs.
263-
*
264-
* @return mixed
257+
* @return mixed|string
265258
*/
266-
public function getEarliestUsenetPostDate()
259+
public function getEarliestUsenetPostDate(): mixed
267260
{
268261
$row = self::query()->selectRaw("DATE_FORMAT(min(postdate), '%d/%m/%Y') AS postdate")->first();
269262

270263
return $row === null ? '01/01/2014' : $row['postdate'];
271264
}
272265

273266
/**
274-
* Get date in this format : 01/01/2014 of the newest release.
275-
*
276-
* @note Used for exporting NZBs.
277-
*
278-
* @return mixed
267+
* @return mixed|string
279268
*/
280-
public function getLatestUsenetPostDate()
269+
public function getLatestUsenetPostDate(): mixed
281270
{
282271
$row = self::query()->selectRaw("DATE_FORMAT(max(postdate), '%d/%m/%Y') AS postdate")->first();
283272

284273
return $row === null ? '01/01/2014' : $row['postdate'];
285274
}
286275

287276
/**
288-
* Gets all groups for drop down selection on NZB-Export web page.
289-
*
290277
* @param bool $blnIncludeAll
291-
*
292-
* @note Used for exporting NZBs.
293-
*
294278
* @return array
295279
*/
296280
public function getReleasedGroupsForSelect(bool $blnIncludeAll = true): array
@@ -313,16 +297,13 @@ public function getReleasedGroupsForSelect(bool $blnIncludeAll = true): array
313297
}
314298

315299
/**
316-
* Get TV for My Shows page.
317-
*
318-
*
319300
* @param $userShows
320301
* @param $offset
321302
* @param $limit
322303
* @param $orderBy
323304
* @param int $maxAge
324305
* @param array $excludedCats
325-
* @return Collection|mixed
306+
* @return \Illuminate\Cache\|\Illuminate\Database\Eloquent\Collection|mixed
326307
*/
327308
public function getShowsRange($userShows, $offset, $limit, $orderBy, int $maxAge = -1, array $excludedCats = [])
328309
{
@@ -363,9 +344,7 @@ public function getShowsRange($userShows, $offset, $limit, $orderBy, int $maxAge
363344
}
364345

365346
/**
366-
* Get count for my shows page pagination.
367-
*
368-
* @param $userShows
347+
* @param $userShows
369348
* @param int $maxAge
370349
* @param array $excludedCats
371350
* @return int
@@ -393,9 +372,8 @@ public function getShowsCount($userShows, int $maxAge = -1, array $excludedCats
393372
}
394373

395374
/**
396-
* Delete multiple releases, or a single by ID.
397-
*
398-
* @param int|array|string $list Array of GUID or ID of releases to delete.
375+
* @param int|array|string $list
376+
* @return void
399377
*
400378
* @throws \Exception
401379
*/
@@ -540,7 +518,7 @@ public function uSQL(Collection|array $userQuery, string $type): string
540518
* @throws \Foolz\SphinxQL\Exception\DatabaseException
541519
* @throws \Foolz\SphinxQL\Exception\SphinxQLException
542520
*/
543-
public function search(array $searchArr, $groupName, $sizeFrom, $sizeTo, $daysNew, $daysOld, int $offset = 0, int $limit = 1000, array|string $orderBy = '', int $maxAge = -1, array $excludedCats = [], string $type = 'basic', array $cat = [-1], int $minSize = 0, array $tags = [])
521+
public function search(array $searchArr, $groupName, $sizeFrom, $sizeTo, $daysNew, $daysOld, int $offset = 0, int $limit = 1000, array|string $orderBy = '', int $maxAge = -1, array $excludedCats = [], string $type = 'basic', array $cat = [-1], int $minSize = 0, array $tags = []): mixed
544522
{
545523
$sizeRange = [
546524
1 => 1,
@@ -816,7 +794,7 @@ public function tvSearch(array $siteIdArr = [], string $series = '', string $epi
816794
if (! empty($name) && $showSql === '') {
817795
if (! empty($series) && (int) $series < 1900) {
818796
$name .= sprintf(' S%s', str_pad($series, 2, '0', STR_PAD_LEFT));
819-
if (! empty($episode) && strpos($episode, '/') === false) {
797+
if (! empty($episode) && ! str_contains($episode, '/')) {
820798
$name .= sprintf('E%s', str_pad($episode, 2, '0', STR_PAD_LEFT));
821799
}
822800
} elseif (! empty($airDate)) {
@@ -917,7 +895,7 @@ public function tvSearch(array $siteIdArr = [], string $series = '', string $epi
917895
* @throws \Foolz\SphinxQL\Exception\DatabaseException
918896
* @throws \Foolz\SphinxQL\Exception\SphinxQLException
919897
*/
920-
public function apiTvSearch(array $siteIdArr = [], string $series = '', string $episode = '', string $airDate = '', int $offset = 0, int $limit = 100, string $name = '', array $cat = [-1], int $maxAge = -1, int $minSize = 0, array $excludedCategories = [], array $tags = [])
898+
public function apiTvSearch(array $siteIdArr = [], string $series = '', string $episode = '', string $airDate = '', int $offset = 0, int $limit = 100, string $name = '', array $cat = [-1], int $maxAge = -1, int $minSize = 0, array $excludedCategories = [], array $tags = []): mixed
921899
{
922900
$siteSQL = [];
923901
$showSql = '';
@@ -945,7 +923,7 @@ public function apiTvSearch(array $siteIdArr = [], string $series = '', string $
945923
);
946924
$show = self::fromQuery($showQry);
947925
if ($show->isNotEmpty()) {
948-
if ((! empty($series) || ! empty($episode) || ! empty($airDate)) && $show[0]->episodes != '') {
926+
if ((! empty($series) || ! empty($episode) || ! empty($airDate)) && $show[0]->episodes !== '') {
949927
$showSql = sprintf('AND r.tv_episodes_id IN (%s)', $show[0]->episodes);
950928
} elseif ((int) $show[0]->video > 0) {
951929
$showSql = 'AND r.videos_id = '.$show[0]->video;
@@ -1056,7 +1034,7 @@ public function apiTvSearch(array $siteIdArr = [], string $series = '', string $
10561034
* @throws \Foolz\SphinxQL\Exception\DatabaseException
10571035
* @throws \Foolz\SphinxQL\Exception\SphinxQLException
10581036
*/
1059-
public function animeSearch($aniDbID, int $offset = 0, int $limit = 100, string $name = '', array $cat = [-1], int $maxAge = -1, array $excludedCategories = [])
1037+
public function animeSearch($aniDbID, int $offset = 0, int $limit = 100, string $name = '', array $cat = [-1], int $maxAge = -1, array $excludedCategories = []): mixed
10601038
{
10611039
if (! empty($name)) {
10621040
if (config('nntmux.elasticsearch_enabled') === true) {
@@ -1140,7 +1118,7 @@ public function animeSearch($aniDbID, int $offset = 0, int $limit = 100, string
11401118
* @throws \Foolz\SphinxQL\Exception\DatabaseException
11411119
* @throws \Foolz\SphinxQL\Exception\SphinxQLException
11421120
*/
1143-
public function moviesSearch(int $imDbId = -1, int $tmDbId = -1, int $traktId = -1, int $offset = 0, int $limit = 100, string $name = '', array $cat = [-1], int $maxAge = -1, int $minSize = 0, array $excludedCategories = [], array $tags = [])
1121+
public function moviesSearch(int $imDbId = -1, int $tmDbId = -1, int $traktId = -1, int $offset = 0, int $limit = 100, string $name = '', array $cat = [-1], int $maxAge = -1, int $minSize = 0, array $excludedCategories = [], array $tags = []): mixed
11441122
{
11451123
if (! empty($name)) {
11461124
if (config('nntmux.elasticsearch_enabled') === true) {
@@ -1219,7 +1197,7 @@ public function moviesSearch(int $imDbId = -1, int $tmDbId = -1, int $traktId =
12191197
* @throws \Foolz\SphinxQL\Exception\DatabaseException
12201198
* @throws \Foolz\SphinxQL\Exception\SphinxQLException
12211199
*/
1222-
public function searchSimilar($currentID, $name, array $excludedCats = [])
1200+
public function searchSimilar($currentID, $name, array $excludedCats = []): bool|array
12231201
{
12241202
// Get the category for the parent of this release.
12251203
$ret = false;

app/Http/Controllers/Api/API.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ public function offset(): int
172172
*/
173173
public function verifyEmptyParameter(string $parameter): void
174174
{
175-
if (request()->has($parameter) && ! request()->filled($parameter)) {
175+
if (request()->has($parameter) && request()->isNotFilled($parameter)) {
176176
Utility::showApiError(201, 'Incorrect parameter ('.$parameter.' must not be empty)');
177177
}
178178
}

app/Http/Controllers/Api/ApiController.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,9 @@ public function api(Request $request): \Symfony\Component\HttpFoundation\Streame
233233
$maxAge = $api->maxAge();
234234
UserRequest::addApiRequest($apiKey, $request->getRequestUri());
235235

236-
$imdbId = $request->has('imdbid') && ! empty($request->input('imdbid')) ? (int) $request->input('imdbid') : -1;
237-
$tmdbId = $request->has('tmdbid') && ! empty($request->input('tmdbid')) ? (int) $request->input('tmdbid') : -1;
238-
$traktId = $request->has('traktid') && ! empty($request->input('traktid')) ? (int) $request->input('traktid') : -1;
236+
$imdbId = $request->has('imdbid') && $request->filled('imdbid') ? (int) $request->input('imdbid') : -1;
237+
$tmdbId = $request->has('tmdbid') && $request->filled('tmdbid') ? (int) $request->input('tmdbid') : -1;
238+
$traktId = $request->has('traktid') && $request->filled('traktid') ? (int) $request->input('traktid') : -1;
239239

240240
$relData = $releases->moviesSearch(
241241
$imdbId,

app/Http/Controllers/Api/ApiV2Controller.php

+10-9
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use App\Transformers\DetailsTransformer;
1616
use Blacklight\Releases;
1717
use Blacklight\utility\Utility;
18+
use Illuminate\Http\JsonResponse;
1819
use Illuminate\Http\Request;
1920
use Illuminate\Support\Carbon;
2021

@@ -23,7 +24,7 @@ class ApiV2Controller extends BasePageController
2324
/**
2425
* @return \Illuminate\Http\JsonResponse
2526
*/
26-
public function capabilities(): \Illuminate\Http\JsonResponse
27+
public function capabilities(): JsonResponse
2728
{
2829
$category = Category::getForApi();
2930

@@ -63,7 +64,7 @@ public function capabilities(): \Illuminate\Http\JsonResponse
6364
* @throws \Foolz\SphinxQL\Exception\SphinxQLException
6465
* @throws \Throwable
6566
*/
66-
public function movie(Request $request): \Illuminate\Http\JsonResponse
67+
public function movie(Request $request): JsonResponse
6768
{
6869
$api = new API();
6970
$releases = new Releases();
@@ -119,7 +120,7 @@ public function movie(Request $request): \Illuminate\Http\JsonResponse
119120
* @throws \Exception
120121
* @throws \Throwable
121122
*/
122-
public function apiSearch(Request $request): \Illuminate\Http\JsonResponse
123+
public function apiSearch(Request $request): JsonResponse
123124
{
124125
$api = new API();
125126
$releases = new Releases();
@@ -188,7 +189,7 @@ public function apiSearch(Request $request): \Illuminate\Http\JsonResponse
188189
* @throws \Exception
189190
* @throws \Throwable
190191
*/
191-
public function tv(Request $request): \Illuminate\Http\JsonResponse
192+
public function tv(Request $request): JsonResponse
192193
{
193194
$api = new API();
194195
$releases = new Releases();
@@ -225,15 +226,15 @@ public function tv(Request $request): \Illuminate\Http\JsonResponse
225226
$series = $request->input('season') ?? '';
226227
$episode = $request->input('ep') ?? '';
227228

228-
if (preg_match('#^(19|20)\d{2}$#', $series, $year) && strpos($episode, '/') !== false) {
229-
$airdate = str_replace('/', '-', $year[0].'-'.$episode);
229+
if (preg_match('#^(19|20)\d{2}$#', $series, $year) && str_contains($episode, '/')) {
230+
$airDate = str_replace('/', '-', $year[0].'-'.$episode);
230231
}
231232

232233
$relData = $releases->apiTvSearch(
233234
$siteIdArr,
234235
$series,
235236
$episode,
236-
$airdate ?? '',
237+
$airDate ?? '',
237238
$api->offset(),
238239
$api->limit(),
239240
$request->input('id') ?? '',
@@ -265,7 +266,7 @@ public function tv(Request $request): \Illuminate\Http\JsonResponse
265266

266267
/**
267268
* @param \Illuminate\Http\Request $request
268-
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
269+
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|void
269270
*/
270271
public function getNzb(Request $request)
271272
{
@@ -284,7 +285,7 @@ public function getNzb(Request $request)
284285
* @param \Illuminate\Http\Request $request
285286
* @return \Illuminate\Http\JsonResponse
286287
*/
287-
public function details(Request $request): \Illuminate\Http\JsonResponse
288+
public function details(Request $request): JsonResponse
288289
{
289290
if ($request->missing('id')) {
290291
Utility::showApiError(200, 'Missing parameter (guid is required for single release details)');

app/Http/Controllers/Api/XML_Response.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,7 @@ protected function writeRssConsoleInfo(): void
674674
* @param array $columns The columns in the release we need to insert
675675
* @return string The HTML format cData
676676
*/
677-
protected function buildCdata($columns): string
677+
protected function buildCdata(array $columns): string
678678
{
679679
$cData = '';
680680

0 commit comments

Comments
 (0)