From 7d63a0586aa0e2a2f629eeaf303e2a527bc81470 Mon Sep 17 00:00:00 2001 From: xiaomlove Date: Wed, 2 Nov 2022 17:39:57 +0800 Subject: [PATCH 1/2] fix enablespecial judgment --- include/constants.php | 2 +- public/edit.php | 2 +- public/upload.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include/constants.php b/include/constants.php index 9ed9daf3..17c9524b 100644 --- a/include/constants.php +++ b/include/constants.php @@ -1,6 +1,6 @@ renderOnUploadPage($id, $browsecatmode); echo $hitAndRunRep->renderOnUploadPage($row['hr'], $browsecatmode); - if ($enablespecial) { + if ($enablespecial == 'yes') { $customField->renderOnUploadPage($id, $specialcatmode); echo $hitAndRunRep->renderOnUploadPage($row['hr'], $specialcatmode); } diff --git a/public/upload.php b/public/upload.php index 0c33a17d..0882c329 100644 --- a/public/upload.php +++ b/public/upload.php @@ -152,7 +152,7 @@ stdhead($lang_upload['head_upload']); $hitAndRunRep = new \App\Repositories\HitAndRunRepository(); echo $customField->renderOnUploadPage(0, $browsecatmode); echo $hitAndRunRep->renderOnUploadPage('', $browsecatmode); - if ($enablespecial) { + if ($enablespecial == 'yes') { echo $customField->renderOnUploadPage(0, $specialcatmode); echo $hitAndRunRep->renderOnUploadPage('', $specialcatmode); } From aae99b0df193c8b43fa341c19c4916fc17ee0515 Mon Sep 17 00:00:00 2001 From: xiaomlove Date: Sat, 5 Nov 2022 01:39:20 +0800 Subject: [PATCH 2/2] fix torrent searchbox id --- app/Models/HitAndRun.php | 14 ++++++++++++-- app/Models/Torrent.php | 7 ++++++- app/Repositories/SearchRepository.php | 6 +++++- app/Repositories/TrackerRepository.php | 7 ++++++- include/constants.php | 2 +- include/functions.php | 7 ++++++- 6 files changed, 36 insertions(+), 7 deletions(-) diff --git a/app/Models/HitAndRun.php b/app/Models/HitAndRun.php index c93fc77c..6dd8d70d 100644 --- a/app/Models/HitAndRun.php +++ b/app/Models/HitAndRun.php @@ -62,7 +62,12 @@ class HitAndRun extends NexusModel if ($this->status != self::STATUS_INSPECTING) { return '---'; } - $inspectTime = HitAndRun::getConfig('inspect_time', $this->torrent->basic_category->mode); + $searchBoxId = $this->torrent->basic_category->mode ?? 0; + if ($searchBoxId == 0) { + do_log(sprintf('[INVALID_CATEGORY], Torrent: %s', $this->torrent_id), 'error'); + return '---'; + } + $inspectTime = HitAndRun::getConfig('inspect_time', $searchBoxId); $diffInSeconds = Carbon::now()->diffInSeconds($this->snatch->completedat->addHours($inspectTime)); return mkprettytime($diffInSeconds); } @@ -72,7 +77,12 @@ class HitAndRun extends NexusModel if ($this->status != self::STATUS_INSPECTING) { return '---'; } - $seedTimeMinimum = HitAndRun::getConfig('seed_time_minimum', $this->torrent->basic_category->mode); + $searchBoxId = $this->torrent->basic_category->mode ?? 0; + if ($searchBoxId == 0) { + do_log(sprintf('[INVALID_CATEGORY], Torrent: %s', $this->torrent_id), 'error'); + return '---'; + } + $seedTimeMinimum = HitAndRun::getConfig('seed_time_minimum', $searchBoxId); $diffInSeconds = 3600 * $seedTimeMinimum - $this->snatch->seedtime; return mkprettytime($diffInSeconds); } diff --git a/app/Models/Torrent.php b/app/Models/Torrent.php index 9f792ef1..155495e2 100644 --- a/app/Models/Torrent.php +++ b/app/Models/Torrent.php @@ -303,7 +303,12 @@ class Torrent extends NexusModel public function getHrAttribute(): string { // $hrMode = Setting::get('hr.mode'); - $hrMode = HitAndRun::getConfig('mode', $this->basic_category->mode); + $searchBoxId = $this->basic_category->mode ?? 0; + if ($searchBoxId == 0) { + do_log(sprintf('[INVALID_CATEGORY], Torrent: %s, category: %s invalid', $this->id, $this->category), 'error'); + return self::HR_NO; + } + $hrMode = HitAndRun::getConfig('mode', $searchBoxId); if ($hrMode == HitAndRun::MODE_GLOBAL) { return self::HR_YES; } diff --git a/app/Repositories/SearchRepository.php b/app/Repositories/SearchRepository.php index afa9d26b..4054b517 100644 --- a/app/Repositories/SearchRepository.php +++ b/app/Repositories/SearchRepository.php @@ -301,8 +301,12 @@ class SearchRepository extends BaseRepository $idName => $this->getTorrentId($torrent->id), 'routing' => $torrent->owner, ]; + $searchBoxId = $torrent->basic_category->mode ?? 0; + if ($searchBoxId == 0) { + do_log(sprintf('[INVALID_CATEGORY], Torrent: %s', $torrent->id), 'error'); + } $data = Arr::only($torrent->toArray(), $baseFields); - $data['mode'] = $torrent->basic_category->mode; + $data['mode'] = $searchBoxId; $body = array_merge($data, [ '_doc_type' => $docType, 'torrent_id' => $torrent->id, diff --git a/app/Repositories/TrackerRepository.php b/app/Repositories/TrackerRepository.php index c438d3b0..22fee05f 100644 --- a/app/Repositories/TrackerRepository.php +++ b/app/Repositories/TrackerRepository.php @@ -1093,7 +1093,12 @@ class TrackerRepository extends BaseRepository return; } // $hrMode = Setting::get('hr.mode'); - $hrMode = HitAndRun::getConfig('mode', $torrent->basic_category->mode); + $searchBoxId = $torrent->basic_category->mode ?? 0; + if ($searchBoxId == 0) { + do_log(sprintf('[INVALID_CATEGORY], Torrent: %s', $torrent->id), 'error'); + return; + } + $hrMode = HitAndRun::getConfig('mode', $searchBoxId); if ($hrMode == HitAndRun::MODE_DISABLED) { return; } diff --git a/include/constants.php b/include/constants.php index 17c9524b..880949ba 100644 --- a/include/constants.php +++ b/include/constants.php @@ -1,6 +1,6 @@ findOrFail(intval($torrent), ['id', 'category'])->basic_category->mode; + $torrent = \App\Models\Torrent::query()->findOrFail(intval($torrent), ['id', 'category']); + $searchBoxId = $torrent->basic_category->mode ?? 0; + if ($searchBoxId == 0) { + do_log("[INVALID_CATEGORY], torrent: " . $torrent->id, 'error'); + return false; + } } else { throw new \InvalidArgumentException("Unsupported argument: " . json_encode($torrent)); }