From 64defea3e3c57ce67117a933cbfc057105ba0c57 Mon Sep 17 00:00:00 2001 From: xiaomlove Date: Sun, 12 Feb 2023 15:04:48 +0800 Subject: [PATCH] announce only check paid torrent for leechers --- app/Console/Commands/Test.php | 5 +++-- app/Models/Torrent.php | 7 ++++--- app/Repositories/TorrentRepository.php | 18 +++++++++++++++++- include/constants.php | 2 +- public/announce.php | 2 +- 5 files changed, 26 insertions(+), 8 deletions(-) diff --git a/app/Console/Commands/Test.php b/app/Console/Commands/Test.php index cc5a006f..6ff335d6 100644 --- a/app/Console/Commands/Test.php +++ b/app/Console/Commands/Test.php @@ -95,8 +95,9 @@ class Test extends Command */ public function handle() { - $r = nexus_env('PHP_PATH') ?: 'php'; - dd($r); + $now = Carbon::now(); + $now->addSeconds(); + dd($diffInSeconds); } } diff --git a/app/Models/Torrent.php b/app/Models/Torrent.php index 89d7dafc..17fa32e2 100644 --- a/app/Models/Torrent.php +++ b/app/Models/Torrent.php @@ -31,9 +31,10 @@ class Torrent extends NexusModel ]; public static $commentFields = [ - 'id', 'name', 'added', 'visible', 'banned', 'owner', 'sp_state', 'pos_state', 'hr', 'picktype', 'picktime', - 'last_action', 'leechers', 'seeders', 'times_completed', 'views', 'size', 'cover', 'anonymous', 'approval_status', - 'pos_state_until', 'category', 'source', 'medium', 'codec', 'standard', 'processing', 'team', 'audiocodec', 'price' + 'id', 'name', 'added', 'visible', 'banned', 'owner', 'sp_state', 'promotion_time_type', 'promotion_until', 'pos_state', + 'hr', 'picktype', 'picktime', 'last_action', 'leechers', 'seeders', 'times_completed', 'views', 'size', 'cover', 'anonymous', + 'approval_status', 'pos_state_until', 'category', 'source', 'medium', 'codec', 'standard', 'processing', 'team', 'audiocodec', + 'price', ]; public static $basicRelations = [ diff --git a/app/Repositories/TorrentRepository.php b/app/Repositories/TorrentRepository.php index 9dc21baa..2a3973e0 100644 --- a/app/Repositories/TorrentRepository.php +++ b/app/Repositories/TorrentRepository.php @@ -479,7 +479,7 @@ class TorrentRepository extends BaseRepository { $user = $this->getUser($user); user_can('torrent-approval', true); - $torrent = Torrent::query()->findOrFail($params['torrent_id'], ['id', 'banned', 'approval_status', 'visible', 'owner']); + $torrent = Torrent::query()->findOrFail($params['torrent_id'], Torrent::$commentFields); $lastLog = TorrentOperationLog::query() ->where('torrent_id', $params['torrent_id']) ->where('uid', $user->id) @@ -497,6 +497,21 @@ class TorrentRepository extends BaseRepository $torrentUpdate['visible'] = 'yes'; if ($torrent->approval_status != $params['approval_status']) { $torrentOperationLog['action_type'] = TorrentOperationLog::ACTION_TYPE_APPROVAL_ALLOW; + //increase promotion time + if ( + Setting::get('torrent.approval_status_none_visible') == 'no' + && $torrent->sp_state != Torrent::PROMOTION_NORMAL + && $torrent->promotion_until + ) { + $hasBeenDownloaded = Snatch::query()->where('torrentid', $torrent->id)->exists(); + $log = "Torrent: {$torrent->id} is in promotion, hasBeenDownloaded: $hasBeenDownloaded"; + if (!$hasBeenDownloaded) { + $diffInSeconds = $torrent->promotion_until->diffInSeconds($torrent->added); + $log .= ", addSeconds: $diffInSeconds"; + $torrentUpdate['promotion_until'] = $torrent->promotion_until->addSeconds($diffInSeconds); + } + do_log($log); + } } if ($torrent->approval_status == Torrent::APPROVAL_STATUS_DENY) { $notifyUser = true; @@ -519,6 +534,7 @@ class TorrentRepository extends BaseRepository } else { throw new \InvalidArgumentException("Invalid approval_status: " . $params['approval_status']); } + if (isset($torrentOperationLog['action_type'])) { $torrentOperationLog['uid'] = $user->id; $torrentOperationLog['torrent_id'] = $torrent->id; diff --git a/include/constants.php b/include/constants.php index 595b5004..95815adf 100644 --- a/include/constants.php +++ b/include/constants.php @@ -1,6 +1,6 @@ 0 && $torrent['owner'] != $userid) { +if ($seeder == 'no' && isset($torrent['price']) && $torrent['price'] > 0 && $torrent['owner'] != $userid) { $hasBuy = \App\Models\TorrentBuyLog::query()->where('uid', $userid)->where('torrent_id', $torrent['id'])->exists(); if (!$hasBuy) { err("You have not buy the torrent yet");