Update API related and Releases classes

This commit is contained in:
DariusIII
2023-02-07 22:49:18 +01:00
parent d76f69723a
commit 544b851e38
5 changed files with 33 additions and 54 deletions
+18 -40
View File
@@ -64,7 +64,7 @@ class Releases extends Release
* @param int $minSize * @param int $minSize
* @return Collection|mixed * @return Collection|mixed
*/ */
public function getBrowseRange($page, $cat, $start, $num, $orderBy, int $maxAge = -1, array $excludedCats = [], int|string $groupName = -1, int $minSize = 0, array $tags = []) public function getBrowseRange($page, $cat, $start, $num, $orderBy, int $maxAge = -1, array $excludedCats = [], int|string $groupName = -1, int $minSize = 0, array $tags = []): mixed
{ {
$orderBy = $this->getBrowseOrder($orderBy); $orderBy = $this->getBrowseOrder($orderBy);
@@ -161,7 +161,7 @@ class Releases extends Release
/** /**
* @return string * @return string
*/ */
public function showPasswords() public function showPasswords(): string
{ {
$show = (int) Settings::settingValue('..showpasswordedrelease'); $show = (int) Settings::settingValue('..showpasswordedrelease');
$setting = $show ?? 0; $setting = $show ?? 0;
@@ -217,13 +217,10 @@ class Releases extends Release
} }
/** /**
* Get list of releases available for export.
*
*
* @param string $postFrom * @param string $postFrom
* @param string $postTo * @param string $postTo
* @param string $groupID * @param string $groupID
* @return Collection|\Illuminate\Support\Collection|static[] * @return \App\Models\Release[]|\Illuminate\Database\Eloquent\Builder[]|\Illuminate\Database\Eloquent\Collection|\Illuminate\Database\Query\Builder[]|\Illuminate\Support\Collection
*/ */
public function getForExport(string $postFrom = '', string $postTo = '', string $groupID = '') public function getForExport(string $postFrom = '', string $postTo = '', string $groupID = '')
{ {
@@ -257,13 +254,9 @@ class Releases extends Release
} }
/** /**
* Get date in this format : 01/01/2014 of the oldest release. * @return mixed|string
*
* @note Used for exporting NZBs.
*
* @return mixed
*/ */
public function getEarliestUsenetPostDate() public function getEarliestUsenetPostDate(): mixed
{ {
$row = self::query()->selectRaw("DATE_FORMAT(min(postdate), '%d/%m/%Y') AS postdate")->first(); $row = self::query()->selectRaw("DATE_FORMAT(min(postdate), '%d/%m/%Y') AS postdate")->first();
@@ -271,13 +264,9 @@ class Releases extends Release
} }
/** /**
* Get date in this format : 01/01/2014 of the newest release. * @return mixed|string
*
* @note Used for exporting NZBs.
*
* @return mixed
*/ */
public function getLatestUsenetPostDate() public function getLatestUsenetPostDate(): mixed
{ {
$row = self::query()->selectRaw("DATE_FORMAT(max(postdate), '%d/%m/%Y') AS postdate")->first(); $row = self::query()->selectRaw("DATE_FORMAT(max(postdate), '%d/%m/%Y') AS postdate")->first();
@@ -285,12 +274,7 @@ class Releases extends Release
} }
/** /**
* Gets all groups for drop down selection on NZB-Export web page.
*
* @param bool $blnIncludeAll * @param bool $blnIncludeAll
*
* @note Used for exporting NZBs.
*
* @return array * @return array
*/ */
public function getReleasedGroupsForSelect(bool $blnIncludeAll = true): array public function getReleasedGroupsForSelect(bool $blnIncludeAll = true): array
@@ -313,16 +297,13 @@ class Releases extends Release
} }
/** /**
* Get TV for My Shows page.
*
*
* @param $userShows * @param $userShows
* @param $offset * @param $offset
* @param $limit * @param $limit
* @param $orderBy * @param $orderBy
* @param int $maxAge * @param int $maxAge
* @param array $excludedCats * @param array $excludedCats
* @return Collection|mixed * @return \Illuminate\Cache\|\Illuminate\Database\Eloquent\Collection|mixed
*/ */
public function getShowsRange($userShows, $offset, $limit, $orderBy, int $maxAge = -1, array $excludedCats = []) public function getShowsRange($userShows, $offset, $limit, $orderBy, int $maxAge = -1, array $excludedCats = [])
{ {
@@ -363,9 +344,7 @@ class Releases extends Release
} }
/** /**
* Get count for my shows page pagination. * @param $userShows
*
* @param $userShows
* @param int $maxAge * @param int $maxAge
* @param array $excludedCats * @param array $excludedCats
* @return int * @return int
@@ -393,9 +372,8 @@ class Releases extends Release
} }
/** /**
* Delete multiple releases, or a single by ID. * @param int|array|string $list
* * @return void
* @param int|array|string $list Array of GUID or ID of releases to delete.
* *
* @throws \Exception * @throws \Exception
*/ */
@@ -540,7 +518,7 @@ class Releases extends Release
* @throws \Foolz\SphinxQL\Exception\DatabaseException * @throws \Foolz\SphinxQL\Exception\DatabaseException
* @throws \Foolz\SphinxQL\Exception\SphinxQLException * @throws \Foolz\SphinxQL\Exception\SphinxQLException
*/ */
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 = []) 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
{ {
$sizeRange = [ $sizeRange = [
1 => 1, 1 => 1,
@@ -816,7 +794,7 @@ class Releases extends Release
if (! empty($name) && $showSql === '') { if (! empty($name) && $showSql === '') {
if (! empty($series) && (int) $series < 1900) { if (! empty($series) && (int) $series < 1900) {
$name .= sprintf(' S%s', str_pad($series, 2, '0', STR_PAD_LEFT)); $name .= sprintf(' S%s', str_pad($series, 2, '0', STR_PAD_LEFT));
if (! empty($episode) && strpos($episode, '/') === false) { if (! empty($episode) && ! str_contains($episode, '/')) {
$name .= sprintf('E%s', str_pad($episode, 2, '0', STR_PAD_LEFT)); $name .= sprintf('E%s', str_pad($episode, 2, '0', STR_PAD_LEFT));
} }
} elseif (! empty($airDate)) { } elseif (! empty($airDate)) {
@@ -917,7 +895,7 @@ class Releases extends Release
* @throws \Foolz\SphinxQL\Exception\DatabaseException * @throws \Foolz\SphinxQL\Exception\DatabaseException
* @throws \Foolz\SphinxQL\Exception\SphinxQLException * @throws \Foolz\SphinxQL\Exception\SphinxQLException
*/ */
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 = []) 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
{ {
$siteSQL = []; $siteSQL = [];
$showSql = ''; $showSql = '';
@@ -945,7 +923,7 @@ class Releases extends Release
); );
$show = self::fromQuery($showQry); $show = self::fromQuery($showQry);
if ($show->isNotEmpty()) { if ($show->isNotEmpty()) {
if ((! empty($series) || ! empty($episode) || ! empty($airDate)) && $show[0]->episodes != '') { if ((! empty($series) || ! empty($episode) || ! empty($airDate)) && $show[0]->episodes !== '') {
$showSql = sprintf('AND r.tv_episodes_id IN (%s)', $show[0]->episodes); $showSql = sprintf('AND r.tv_episodes_id IN (%s)', $show[0]->episodes);
} elseif ((int) $show[0]->video > 0) { } elseif ((int) $show[0]->video > 0) {
$showSql = 'AND r.videos_id = '.$show[0]->video; $showSql = 'AND r.videos_id = '.$show[0]->video;
@@ -1056,7 +1034,7 @@ class Releases extends Release
* @throws \Foolz\SphinxQL\Exception\DatabaseException * @throws \Foolz\SphinxQL\Exception\DatabaseException
* @throws \Foolz\SphinxQL\Exception\SphinxQLException * @throws \Foolz\SphinxQL\Exception\SphinxQLException
*/ */
public function animeSearch($aniDbID, int $offset = 0, int $limit = 100, string $name = '', array $cat = [-1], int $maxAge = -1, array $excludedCategories = []) public function animeSearch($aniDbID, int $offset = 0, int $limit = 100, string $name = '', array $cat = [-1], int $maxAge = -1, array $excludedCategories = []): mixed
{ {
if (! empty($name)) { if (! empty($name)) {
if (config('nntmux.elasticsearch_enabled') === true) { if (config('nntmux.elasticsearch_enabled') === true) {
@@ -1140,7 +1118,7 @@ class Releases extends Release
* @throws \Foolz\SphinxQL\Exception\DatabaseException * @throws \Foolz\SphinxQL\Exception\DatabaseException
* @throws \Foolz\SphinxQL\Exception\SphinxQLException * @throws \Foolz\SphinxQL\Exception\SphinxQLException
*/ */
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 = []) 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
{ {
if (! empty($name)) { if (! empty($name)) {
if (config('nntmux.elasticsearch_enabled') === true) { if (config('nntmux.elasticsearch_enabled') === true) {
@@ -1219,7 +1197,7 @@ class Releases extends Release
* @throws \Foolz\SphinxQL\Exception\DatabaseException * @throws \Foolz\SphinxQL\Exception\DatabaseException
* @throws \Foolz\SphinxQL\Exception\SphinxQLException * @throws \Foolz\SphinxQL\Exception\SphinxQLException
*/ */
public function searchSimilar($currentID, $name, array $excludedCats = []) public function searchSimilar($currentID, $name, array $excludedCats = []): bool|array
{ {
// Get the category for the parent of this release. // Get the category for the parent of this release.
$ret = false; $ret = false;
+1 -1
View File
@@ -172,7 +172,7 @@ class API extends Capabilities
*/ */
public function verifyEmptyParameter(string $parameter): void public function verifyEmptyParameter(string $parameter): void
{ {
if (request()->has($parameter) && ! request()->filled($parameter)) { if (request()->has($parameter) && request()->isNotFilled($parameter)) {
Utility::showApiError(201, 'Incorrect parameter ('.$parameter.' must not be empty)'); Utility::showApiError(201, 'Incorrect parameter ('.$parameter.' must not be empty)');
} }
} }
+3 -3
View File
@@ -233,9 +233,9 @@ class ApiController extends BasePageController
$maxAge = $api->maxAge(); $maxAge = $api->maxAge();
UserRequest::addApiRequest($apiKey, $request->getRequestUri()); UserRequest::addApiRequest($apiKey, $request->getRequestUri());
$imdbId = $request->has('imdbid') && ! empty($request->input('imdbid')) ? (int) $request->input('imdbid') : -1; $imdbId = $request->has('imdbid') && $request->filled('imdbid') ? (int) $request->input('imdbid') : -1;
$tmdbId = $request->has('tmdbid') && ! empty($request->input('tmdbid')) ? (int) $request->input('tmdbid') : -1; $tmdbId = $request->has('tmdbid') && $request->filled('tmdbid') ? (int) $request->input('tmdbid') : -1;
$traktId = $request->has('traktid') && ! empty($request->input('traktid')) ? (int) $request->input('traktid') : -1; $traktId = $request->has('traktid') && $request->filled('traktid') ? (int) $request->input('traktid') : -1;
$relData = $releases->moviesSearch( $relData = $releases->moviesSearch(
$imdbId, $imdbId,
+10 -9
View File
@@ -15,6 +15,7 @@ use App\Transformers\CategoryTransformer;
use App\Transformers\DetailsTransformer; use App\Transformers\DetailsTransformer;
use Blacklight\Releases; use Blacklight\Releases;
use Blacklight\utility\Utility; use Blacklight\utility\Utility;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Carbon; use Illuminate\Support\Carbon;
@@ -23,7 +24,7 @@ class ApiV2Controller extends BasePageController
/** /**
* @return \Illuminate\Http\JsonResponse * @return \Illuminate\Http\JsonResponse
*/ */
public function capabilities(): \Illuminate\Http\JsonResponse public function capabilities(): JsonResponse
{ {
$category = Category::getForApi(); $category = Category::getForApi();
@@ -63,7 +64,7 @@ class ApiV2Controller extends BasePageController
* @throws \Foolz\SphinxQL\Exception\SphinxQLException * @throws \Foolz\SphinxQL\Exception\SphinxQLException
* @throws \Throwable * @throws \Throwable
*/ */
public function movie(Request $request): \Illuminate\Http\JsonResponse public function movie(Request $request): JsonResponse
{ {
$api = new API(); $api = new API();
$releases = new Releases(); $releases = new Releases();
@@ -119,7 +120,7 @@ class ApiV2Controller extends BasePageController
* @throws \Exception * @throws \Exception
* @throws \Throwable * @throws \Throwable
*/ */
public function apiSearch(Request $request): \Illuminate\Http\JsonResponse public function apiSearch(Request $request): JsonResponse
{ {
$api = new API(); $api = new API();
$releases = new Releases(); $releases = new Releases();
@@ -188,7 +189,7 @@ class ApiV2Controller extends BasePageController
* @throws \Exception * @throws \Exception
* @throws \Throwable * @throws \Throwable
*/ */
public function tv(Request $request): \Illuminate\Http\JsonResponse public function tv(Request $request): JsonResponse
{ {
$api = new API(); $api = new API();
$releases = new Releases(); $releases = new Releases();
@@ -225,15 +226,15 @@ class ApiV2Controller extends BasePageController
$series = $request->input('season') ?? ''; $series = $request->input('season') ?? '';
$episode = $request->input('ep') ?? ''; $episode = $request->input('ep') ?? '';
if (preg_match('#^(19|20)\d{2}$#', $series, $year) && strpos($episode, '/') !== false) { if (preg_match('#^(19|20)\d{2}$#', $series, $year) && str_contains($episode, '/')) {
$airdate = str_replace('/', '-', $year[0].'-'.$episode); $airDate = str_replace('/', '-', $year[0].'-'.$episode);
} }
$relData = $releases->apiTvSearch( $relData = $releases->apiTvSearch(
$siteIdArr, $siteIdArr,
$series, $series,
$episode, $episode,
$airdate ?? '', $airDate ?? '',
$api->offset(), $api->offset(),
$api->limit(), $api->limit(),
$request->input('id') ?? '', $request->input('id') ?? '',
@@ -265,7 +266,7 @@ class ApiV2Controller extends BasePageController
/** /**
* @param \Illuminate\Http\Request $request * @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|void
*/ */
public function getNzb(Request $request) public function getNzb(Request $request)
{ {
@@ -284,7 +285,7 @@ class ApiV2Controller extends BasePageController
* @param \Illuminate\Http\Request $request * @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\JsonResponse * @return \Illuminate\Http\JsonResponse
*/ */
public function details(Request $request): \Illuminate\Http\JsonResponse public function details(Request $request): JsonResponse
{ {
if ($request->missing('id')) { if ($request->missing('id')) {
Utility::showApiError(200, 'Missing parameter (guid is required for single release details)'); Utility::showApiError(200, 'Missing parameter (guid is required for single release details)');
+1 -1
View File
@@ -674,7 +674,7 @@ class XML_Response
* @param array $columns The columns in the release we need to insert * @param array $columns The columns in the release we need to insert
* @return string The HTML format cData * @return string The HTML format cData
*/ */
protected function buildCdata($columns): string protected function buildCdata(array $columns): string
{ {
$cData = ''; $cData = '';