diff --git a/.env.example b/.env.example index ec8a3085..154f51e7 100644 --- a/.env.example +++ b/.env.example @@ -45,10 +45,10 @@ MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}" MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}" -REDIS_HOST= +REDIS_HOST=127.0.0.1 REDIS_PASSWORD= -REDIS_PORT= -REDIS_DB= +REDIS_PORT=6379 +REDIS_DB=0 USE_CRON_TRIGGER_CLEANUP=true @@ -62,7 +62,6 @@ GOOGLE_DRIVE_REFRESH_TOKEN= GOOGLE_DRIVE_FOLDER_ID= GEOIP2_DATABASE= -EXAM_PROGRESS_UPDATE_PROBABILITY=20 TRACKER_API_LOCAL_HOST= diff --git a/app/Repositories/ClaimRepository.php b/app/Repositories/ClaimRepository.php index 5a549947..a058a0ca 100644 --- a/app/Repositories/ClaimRepository.php +++ b/app/Repositories/ClaimRepository.php @@ -304,4 +304,20 @@ class ClaimRepository extends BaseRepository 'msg' => implode("\n\n", $msg), ]; } + + public function buildActionButtons($torrentId, $claimData, $reload = 0): string + { + $buttonHtml = ''; + $addButton = sprintf($buttonHtml, 'addClaim', $reload, nexus_trans('claim.add_claim_confirm'), $claimData ? $claimData->id : 0, $torrentId, '%s', 'edit', nexus_trans('claim.add_claim')); + $removeButton = sprintf($buttonHtml, 'removeClaim', $reload, nexus_trans('claim.remove_claim_confirm'), $claimData ? $claimData->id : 0, $torrentId, '%s', 'delete', nexus_trans('claim.remove_claim')); + + if ($claimData) { + //Only show remove + return sprintf($addButton, 'none') . sprintf($removeButton, 'flex'); + } else { + //Only show add + return sprintf($addButton, 'flex') . sprintf($removeButton, 'none'); + } + + } } diff --git a/public/claim.php b/public/claim.php index 9161020c..62fafcfb 100644 --- a/public/claim.php +++ b/public/claim.php @@ -28,25 +28,6 @@ if (!empty($_GET['torrent_id'])) { print("

".nexus_trans('claim.title_for_user') . " ".htmlspecialchars($user->username)."

"); if ($uid == $CURUSER['id']) { $actionTh = sprintf("%s", nexus_trans("claim.th_action")); - $actionTd = ""; - $confirmMsg = nexus_trans('claim.confirm_give_up'); - $removeJs = << $now = \Carbon\Carbon::now(); $seedTimeRequiredHours = \App\Models\Claim::getConfigStandardSeedTimeHours(); $uploadedRequiredTimes = \App\Models\Claim::getConfigStandardUploadedTimes(); +$claimRep = new \App\Repositories\ClaimRepository(); foreach ($list as $row) { if ( bcsub($row->snatch->seedtime, $row->seed_time_begin) >= $seedTimeRequiredHours * 3600 @@ -82,6 +64,10 @@ foreach ($list as $row) { } else { $reached = 'No'; } + $actionTd = ''; + if ($actionTh) { + $actionTd = sprintf('%s', $claimRep->buildActionButtons($row->torrent_id, $row, 1)); + } print(" " . $row->id . " " . $row->user->username . " @@ -93,7 +79,7 @@ foreach ($list as $row) { " . mkprettytime($row->snatch->seedtime - $row->seed_time_begin) . " " . mksize($row->snatch->uploaded - $row->uploaded_begin) . " " . $reached . " - ".sprintf($actionTd, $row->id)." + ".$actionTd." "); } diff --git a/public/getusertorrentlistajax.php b/public/getusertorrentlistajax.php index 1fc617ab..c37129fe 100644 --- a/public/getusertorrentlistajax.php +++ b/public/getusertorrentlistajax.php @@ -10,7 +10,7 @@ header("Pragma: no-cache" ); //header("Content-Type: text/xml; charset=utf-8"); $torrentRep = new \App\Repositories\TorrentRepository(); - +$claimRep = new \App\Repositories\ClaimRepository(); $id = intval($_GET['userid'] ?? 0); $type = $_GET['type']; if (!in_array($type,array('uploaded','seeding','leeching','completed','incomplete'))) @@ -21,7 +21,8 @@ if(!user_can('torrenthistory') && $id != $CURUSER["id"]) function maketable($res, $mode = 'seeding') { global $lang_getusertorrentlistajax,$CURUSER,$smalldescription_main, $lang_functions, $id; - global $torrentRep; + global $torrentRep, $claimRep; + $showActionClaim = false; switch ($mode) { case 'uploaded': { @@ -82,6 +83,7 @@ function maketable($res, $mode = 'seeding') $showanonymous = false; $showtotalsize = false; $columncount = 8; + $showActionClaim = true; break; } case 'incomplete': { @@ -115,10 +117,21 @@ function maketable($res, $mode = 'seeding') ->get() ->keyBy('torrentid'); } + if ($showActionClaim) { + $claimData = \App\Models\Claim::query() + ->where('uid', $CURUSER['id']) + ->whereIn('torrent_id', $torrentIdArr) + ->get() + ->keyBy('torrent_id'); + } $ret = "". - ($showsize ? "" : "").($showsenum ? "" : "").($showlenum ? "" : "").($showuploaded ? "" : "") . ($showdownloaded ? "" : "").($showratio ? "" : "").($showsetime ? "" : "").($showletime ? "" : "").($showcotime ? "" : "").($showanonymous ? "" : "")."\n"; - $total_size = 0; + ($showsize ? "" : "").($showsenum ? "" : "").($showlenum ? "" : "").($showuploaded ? "" : "") . ($showdownloaded ? "" : "").($showratio ? "" : "").($showsetime ? "" : "").($showletime ? "" : "").($showcotime ? "" : "").($showanonymous ? "" : ""); + if ($showActionClaim) { + $ret .= sprintf('', $lang_functions['std_action']); + } + $ret .= ""; + $total_size = 0; foreach ($results as $arr) { if ($mode == 'uploaded') { @@ -199,6 +212,11 @@ function maketable($res, $mode = 'seeding') $ret .= ""; if ($showanonymous) $ret .= ""; + if ($showActionClaim) { + $claim = $claimData->get($arr['torrent']); + $claimButton = $claimRep->buildActionButtons($arr['torrent'], $claim); + $ret .= sprintf('', $claimButton); + } $ret .="\n"; } @@ -255,7 +273,7 @@ switch ($type) // Incomplete torrents case 'incomplete': { - $res = sql_query("SELECT torrents.id AS torrent, torrents.name AS torrentname, small_descr, torrents.banned, torrents.approval_status, categories.name AS catname, categories.image, category, sp_state, size, torrents.hr, torrents.added,snatched.uploaded, snatched.downloaded, snatched.leechtime FROM torrents LEFT JOIN snatched ON torrents.id = snatched.torrentid LEFT JOIN categories on torrents.category = categories.id WHERE snatched.finished='no' AND userid=$id AND torrents.owner != $id ORDER BY snatched.id DESC") or sqlerr(); +// $res = sql_query("SELECT torrents.id AS torrent, torrents.name AS torrentname, small_descr, torrents.banned, torrents.approval_status, categories.name AS catname, categories.image, category, sp_state, size, torrents.hr, torrents.added,snatched.uploaded, snatched.downloaded, snatched.leechtime FROM torrents LEFT JOIN snatched ON torrents.id = snatched.torrentid LEFT JOIN categories on torrents.category = categories.id WHERE snatched.finished='no' AND userid=$id AND torrents.owner != $id ORDER BY snatched.id DESC") or sqlerr(); $fields = "torrents.id AS torrent, torrents.name AS torrentname, small_descr, torrents.banned, torrents.approval_status, categories.name AS catname, categories.image, category, sp_state, size, torrents.hr, torrents.added,snatched.uploaded, snatched.downloaded, snatched.leechtime,snatched.seedtime,snatched.uploaded"; $tableWhere = "torrents LEFT JOIN snatched ON torrents.id = snatched.torrentid LEFT JOIN categories on torrents.category = categories.id WHERE snatched.finished='no' AND userid=$id AND torrents.owner != $id"; $order = "snatched.id DESC"; diff --git a/public/js/nexus.js b/public/js/nexus.js index b0dbe244..453bd826 100644 --- a/public/js/nexus.js +++ b/public/js/nexus.js @@ -103,4 +103,47 @@ jQuery(document).ready(function () { imgList.forEach(img => io.observe(img)) } + //claim + jQuery("body").on("click", "[data-claim_id]", function () { + let _this = jQuery(this) + let box = _this.closest('td') + let claimId = _this.attr("data-claim_id") + let torrentId = _this.attr("data-torrent_id") + let action = _this.attr("data-action") + let reload = _this.attr("data-reload") + let confirmText = _this.attr("data-confirm") + let showStyle = "width: max-content;display: flex;align-items: center"; + let hideStyle = "width: max-content;display: none;align-items: center"; + let params = {} + if (claimId > 0) { + params.id = claimId + } else { + params.torrent_id = torrentId + } + let modalConfig = {title: "Info", btn: ['OK', 'Cancel'], btnAlign: 'c'} + layer.confirm(confirmText, modalConfig, function (confirmIndex) { + jQuery.post("ajax.php", {"action": action, params: params}, function (response) { + console.log(response) + if (response.ret != 0) { + layer.alert(response.msg, modalConfig) + return + } + if (reload > 0) { + window.location.reload(); + return; + } + if (claimId > 0) { + //do remove, show add + box.find("[data-action=addClaim]").attr("style", showStyle).attr("data-claim_id", 0) + box.find("[data-action=removeClaim]").attr("style", hideStyle) + } else { + //do add, show remove, update claim_id + box.find("[data-action=addClaim]").attr("style", hideStyle) + box.find("[data-action=removeClaim]").attr("style", showStyle).attr("data-claim_id", response.data.id) + } + layer.close(confirmIndex) + }, "json") + }) + }) + }) diff --git a/resources/lang/en/claim.php b/resources/lang/en/claim.php index a33dc293..9a465baa 100644 --- a/resources/lang/en/claim.php +++ b/resources/lang/en/claim.php @@ -25,4 +25,8 @@ return [ 'claim_unreached_summary' => 'Deduct bonus every unreached torrent::deduct_per_torrent, total deduct: :deduct_total', 'confirm_give_up' => 'Are you sure you want to give up claiming this torrent?', + 'add_claim' => 'Claim', + 'add_claim_confirm' => 'Confirm to claim?', + 'remove_claim' => 'Give up', + 'remove_claim_confirm' => 'Confirm to give up the claim?', ]; diff --git a/resources/lang/zh_CN/claim.php b/resources/lang/zh_CN/claim.php index 484af200..925b306e 100644 --- a/resources/lang/zh_CN/claim.php +++ b/resources/lang/zh_CN/claim.php @@ -25,4 +25,8 @@ return [ 'claim_unreached_summary' => '未达标每个种子扣除魔力::deduct_per_torrent,总扣除魔力::deduct_total', 'confirm_give_up' => '确定要放弃认领此种子吗?', + 'add_claim' => '认领', + 'add_claim_confirm' => '确认要认领?', + 'remove_claim' => '放弃', + 'remove_claim_confirm' => '确认要放弃认领?', ]; diff --git a/resources/lang/zh_TW/claim.php b/resources/lang/zh_TW/claim.php index 0b5ec93a..bfc9d19b 100644 --- a/resources/lang/zh_TW/claim.php +++ b/resources/lang/zh_TW/claim.php @@ -22,4 +22,10 @@ return [ 'claim_unreached_remain_counts' => '未達標保留數::counts', 'claim_unreached_remove_counts' => '未達標刪除數::counts', 'claim_unreached_summary' => '未達標每個種子扣除魔力::deduct_per_torrent,總扣除魔力::deduct_total', + + 'confirm_give_up' => '確定要放棄認領此種子嗎?', + 'add_claim' => '認領', + 'add_claim_confirm' => '確認要認領?', + 'remove_claim' => '放棄', + 'remove_claim_confirm' => '確認要放棄認領?', ];
".$lang_getusertorrentlistajax['col_type']."".$lang_getusertorrentlistajax['col_name']."".$lang_getusertorrentlistajax['col_added']."\"size\"\"seeders\"\"leechers\"".$lang_getusertorrentlistajax['col_uploaded']."".$lang_getusertorrentlistajax['col_downloaded']."".$lang_getusertorrentlistajax['col_ratio']."".$lang_getusertorrentlistajax['col_se_time']."".$lang_getusertorrentlistajax['col_le_time']."".$lang_getusertorrentlistajax['col_time_completed']."".$lang_getusertorrentlistajax['col_anonymous']."
\"size\"\"seeders\"\"leechers\"".$lang_getusertorrentlistajax['col_uploaded']."".$lang_getusertorrentlistajax['col_downloaded']."".$lang_getusertorrentlistajax['col_ratio']."".$lang_getusertorrentlistajax['col_se_time']."".$lang_getusertorrentlistajax['col_le_time']."".$lang_getusertorrentlistajax['col_time_completed']."".$lang_getusertorrentlistajax['col_anonymous']."%s
"."". str_replace(" ", "
", gettime($arr['completedat'],false)). "
".$arr['anonymous']."%s