From b8f16901246302b0c8a53e145ca6ebd694ef3109 Mon Sep 17 00:00:00 2001 From: xiaomlove Date: Sun, 9 Apr 2023 16:33:36 +0800 Subject: [PATCH] improve claim all seeding --- app/Repositories/ClaimRepository.php | 46 +--------------------------- include/globalfunctions.php | 4 ++- lang/chs/lang_details.php | 2 +- lang/cht/lang_details.php | 2 +- lang/en/lang_details.php | 2 +- public/getusertorrentlistajax.php | 7 ++--- public/userdetails.php | 2 +- resources/lang/en/claim.php | 1 - resources/lang/zh_CN/claim.php | 1 - resources/lang/zh_TW/claim.php | 1 - 10 files changed, 10 insertions(+), 58 deletions(-) diff --git a/app/Repositories/ClaimRepository.php b/app/Repositories/ClaimRepository.php index 2c81e935..e4dbdd9e 100644 --- a/app/Repositories/ClaimRepository.php +++ b/app/Repositories/ClaimRepository.php @@ -345,49 +345,5 @@ class ClaimRepository extends BaseRepository } - public function claimAllSeeding(int $uid) - { - if (!has_role_work_seeding($uid)) { - throw new InsufficientPermissionException(); - } - $page = 1; - $size = 1000; - $total = 0; - while (true) { - $peers = Peer::query() - ->where('userid', $uid) - ->where('seeder', 'yes') - ->where('to_go', 0) - ->groupBy('torrent') - ->forPage($page, $size) - ->get(['torrent']); - if ($peers->isEmpty()) { - break; - } - $torrentIdArr = $peers->pluck('torrent')->toArray(); - $snatches = Snatch::query() - ->whereIn('torrentid', $torrentIdArr) - ->where('userid', $uid) - ->groupBy('torrentid') - ->get(['id', 'torrentid', 'seedtime', 'uploaded']); - if ($snatches->isNotEmpty()) { - $values = []; - $nowStr = now()->toDateTimeString(); - $sql = "insert into claims (uid, torrent_id, snatched_id, seed_time_begin, uploaded_begin, created_at, updated_at)"; - foreach ($snatches as $snatch) { - $values[] = sprintf( - "(%s, %s, %s, %s, %s, '%s', '%s')", - $uid, $snatch->torrentid, $snatch->id, $snatch->seedtime, $snatch->uploaded, $nowStr, $nowStr - ); - } - $sql .= sprintf(" values %s on duplicate key update updated_at = '%s'", implode(', ', $values), $nowStr); - NexusDB::statement($sql); - } - $count = $snatches->count(); - $total += $count; - do_log("page: $page, insert rows count: " . $count); - $page++; - } - return $total; - } + } diff --git a/include/globalfunctions.php b/include/globalfunctions.php index 60a10c5f..39e619e5 100644 --- a/include/globalfunctions.php +++ b/include/globalfunctions.php @@ -1178,6 +1178,8 @@ function executeCommand($command, $format = 'string', $artisan = false, $excepti function has_role_work_seeding($uid) { - return apply_filter('user_has_role_work_seeding', false, $uid); + $result = apply_filter('user_has_role_work_seeding', false, $uid); + do_log("uid: $uid, result: $result"); + return $result; } diff --git a/lang/chs/lang_details.php b/lang/chs/lang_details.php index a89ed755..e202cb79 100644 --- a/lang/chs/lang_details.php +++ b/lang/chs/lang_details.php @@ -123,7 +123,7 @@ $lang_details = array 'text_hide_list' => "[隐藏列表]", 'row_action' => "行为", 'text_download_torrent' => "下载种子", - 'text_download_paid_torrent' => "下载种子(扣除魔力:%s)", + 'text_download_paid_torrent' => "下载种子(汇报时将扣除魔力:%s)", 'text_download_bought_torrent' => "下载种子(已购买)", 'title_download_torrent' => "下载种子", 'text_ask_for_reseed' => "请求续种", diff --git a/lang/cht/lang_details.php b/lang/cht/lang_details.php index 39645109..94de3149 100644 --- a/lang/cht/lang_details.php +++ b/lang/cht/lang_details.php @@ -123,7 +123,7 @@ $lang_details = array 'text_hide_list' => "[隱藏清單]", 'row_action' => "行為", 'text_download_torrent' => "下載種子", - 'text_download_paid_torrent' => "下載種子(扣除魔力:%s)", + 'text_download_paid_torrent' => "下載種子(匯報時將扣除魔力:%s)", 'text_download_bought_torrent' => "下載種子(已購買)", 'title_download_torrent' => "下載種子", 'text_ask_for_reseed' => "要求續種", diff --git a/lang/en/lang_details.php b/lang/en/lang_details.php index e961f2f6..3e76b294 100644 --- a/lang/en/lang_details.php +++ b/lang/en/lang_details.php @@ -122,7 +122,7 @@ $lang_details = array 'text_hide_list' => "[Hide list]", 'row_action' => "Action", 'text_download_torrent' => "Download torrent", - 'text_download_paid_torrent' => "Download torrent(deduct bonus: %s)", + 'text_download_paid_torrent' => "Download torrent(announce will deduct bonus: %s)", 'text_download_bought_torrent' => "Download torrent(bought)", 'title_download_torrent' => "Download torrent", 'text_ask_for_reseed' => "Ask for a reseed", diff --git a/public/getusertorrentlistajax.php b/public/getusertorrentlistajax.php index 1afec73f..279d6151 100644 --- a/public/getusertorrentlistajax.php +++ b/public/getusertorrentlistajax.php @@ -353,11 +353,8 @@ if (isset($total_size) && $total_size){ $hasData = true; } if ($hasData) { - $claimAllBtn = ''; - if ($id == $CURUSER['id'] && has_role_work_seeding($CURUSER['id'])) { - $claimAllBtn = sprintf('', nexus_trans('claim.claim_all_seeding_btn')); - } - $header = sprintf('
%s
%s
', $summary, $claimAllBtn); + $btnArr = apply_filter("user_seeding_top_btn", [], $CURUSER['id']); + $header = sprintf('
%s
%s
', $summary, implode("", $btnArr)); echo '
' . $header . $table; } else { echo $lang_getusertorrentlistajax['text_no_record']; diff --git a/public/userdetails.php b/public/userdetails.php index d651353e..5cd20215 100644 --- a/public/userdetails.php +++ b/public/userdetails.php @@ -633,7 +633,7 @@ if ($userInfo->id == $CURUSER['id'] && has_role_work_seeding($userInfo->id)) { $claimJs = << [ 'torrent_id' => 'Torrent ID', ], - 'claim_all_seeding_btn' => 'One click to claim', 'claim_all_seeding_confirmation' => 'Are you sure you want to claim all the torrents that are currently being seeding?' , ]; diff --git a/resources/lang/zh_CN/claim.php b/resources/lang/zh_CN/claim.php index cdb45339..a5f0d3ec 100644 --- a/resources/lang/zh_CN/claim.php +++ b/resources/lang/zh_CN/claim.php @@ -36,7 +36,6 @@ return [ 'torrent_id' => '种子 ID', ], - 'claim_all_seeding_btn' => '一键认领', 'claim_all_seeding_confirmation' => '确定要认领当前全部做种中的种子吗?', ]; diff --git a/resources/lang/zh_TW/claim.php b/resources/lang/zh_TW/claim.php index d8585f61..bb2cfd07 100644 --- a/resources/lang/zh_TW/claim.php +++ b/resources/lang/zh_TW/claim.php @@ -33,6 +33,5 @@ return [ 'fields' => [ 'torrent_id' => '種子 ID', ], - 'claim_all_seeding_btn' => '一鍵認領', 'claim_all_seeding_confirmation' => '確定要認領當前全部做種中的種子嗎?', ];