mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-24 12:07:23 +08:00
improve claim all seeding
This commit is contained in:
@@ -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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1178,6 +1178,8 @@ function executeCommand($command, $format = 'string', $artisan = false, $excepti
|
|||||||
|
|
||||||
function has_role_work_seeding($uid)
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -123,7 +123,7 @@ $lang_details = array
|
|||||||
'text_hide_list' => "[隐藏列表]",
|
'text_hide_list' => "[隐藏列表]",
|
||||||
'row_action' => "行为",
|
'row_action' => "行为",
|
||||||
'text_download_torrent' => "下载种子",
|
'text_download_torrent' => "下载种子",
|
||||||
'text_download_paid_torrent' => "下载种子(扣除魔力:%s)",
|
'text_download_paid_torrent' => "下载种子(汇报时将扣除魔力:%s)",
|
||||||
'text_download_bought_torrent' => "下载种子(已购买)",
|
'text_download_bought_torrent' => "下载种子(已购买)",
|
||||||
'title_download_torrent' => "下载种子",
|
'title_download_torrent' => "下载种子",
|
||||||
'text_ask_for_reseed' => "请求续种",
|
'text_ask_for_reseed' => "请求续种",
|
||||||
|
|||||||
@@ -123,7 +123,7 @@ $lang_details = array
|
|||||||
'text_hide_list' => "[隱藏清單]",
|
'text_hide_list' => "[隱藏清單]",
|
||||||
'row_action' => "行為",
|
'row_action' => "行為",
|
||||||
'text_download_torrent' => "下載種子",
|
'text_download_torrent' => "下載種子",
|
||||||
'text_download_paid_torrent' => "下載種子(扣除魔力:%s)",
|
'text_download_paid_torrent' => "下載種子(匯報時將扣除魔力:%s)",
|
||||||
'text_download_bought_torrent' => "下載種子(已購買)",
|
'text_download_bought_torrent' => "下載種子(已購買)",
|
||||||
'title_download_torrent' => "下載種子",
|
'title_download_torrent' => "下載種子",
|
||||||
'text_ask_for_reseed' => "要求續種",
|
'text_ask_for_reseed' => "要求續種",
|
||||||
|
|||||||
@@ -122,7 +122,7 @@ $lang_details = array
|
|||||||
'text_hide_list' => "[Hide list]",
|
'text_hide_list' => "[Hide list]",
|
||||||
'row_action' => "Action",
|
'row_action' => "Action",
|
||||||
'text_download_torrent' => "Download torrent",
|
'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)",
|
'text_download_bought_torrent' => "Download torrent(bought)",
|
||||||
'title_download_torrent' => "Download torrent",
|
'title_download_torrent' => "Download torrent",
|
||||||
'text_ask_for_reseed' => "Ask for a reseed",
|
'text_ask_for_reseed' => "Ask for a reseed",
|
||||||
|
|||||||
@@ -353,11 +353,8 @@ if (isset($total_size) && $total_size){
|
|||||||
$hasData = true;
|
$hasData = true;
|
||||||
}
|
}
|
||||||
if ($hasData) {
|
if ($hasData) {
|
||||||
$claimAllBtn = '';
|
$btnArr = apply_filter("user_seeding_top_btn", [], $CURUSER['id']);
|
||||||
if ($id == $CURUSER['id'] && has_role_work_seeding($CURUSER['id'])) {
|
$header = sprintf('<div style="display: flex;justify-content: space-between"><div>%s</div><div>%s</div></div>', $summary, implode("", $btnArr));
|
||||||
$claimAllBtn = sprintf('<input type="button" value="%s" id="claim-all-seeding">', nexus_trans('claim.claim_all_seeding_btn'));
|
|
||||||
}
|
|
||||||
$header = sprintf('<div style="display: flex;justify-content: space-between"><div>%s</div><div>%s</div></div>', $summary, $claimAllBtn);
|
|
||||||
echo '<br/>' . $header . $table;
|
echo '<br/>' . $header . $table;
|
||||||
} else {
|
} else {
|
||||||
echo $lang_getusertorrentlistajax['text_no_record'];
|
echo $lang_getusertorrentlistajax['text_no_record'];
|
||||||
|
|||||||
@@ -633,7 +633,7 @@ if ($userInfo->id == $CURUSER['id'] && has_role_work_seeding($userInfo->id)) {
|
|||||||
$claimJs = <<<JS
|
$claimJs = <<<JS
|
||||||
jQuery("body").on("click", "#claim-all-seeding", function (e) {
|
jQuery("body").on("click", "#claim-all-seeding", function (e) {
|
||||||
layer.confirm("$claimAllSeedingConfirmation", {}, function () {
|
layer.confirm("$claimAllSeedingConfirmation", {}, function () {
|
||||||
jQuery.post('ajax.php', {"action": "claimAllSeeding"}, function (response) {
|
jQuery.post('/plugin/claim_all_seeding', {"action": "claimAllSeeding"}, function (response) {
|
||||||
if (response.ret == 0) {
|
if (response.ret == 0) {
|
||||||
window.location.reload()
|
window.location.reload()
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -34,6 +34,5 @@ return [
|
|||||||
'fields' => [
|
'fields' => [
|
||||||
'torrent_id' => 'Torrent ID',
|
'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?' ,
|
'claim_all_seeding_confirmation' => 'Are you sure you want to claim all the torrents that are currently being seeding?' ,
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -36,7 +36,6 @@ return [
|
|||||||
'torrent_id' => '种子 ID',
|
'torrent_id' => '种子 ID',
|
||||||
],
|
],
|
||||||
|
|
||||||
'claim_all_seeding_btn' => '一键认领',
|
|
||||||
'claim_all_seeding_confirmation' => '确定要认领当前全部做种中的种子吗?',
|
'claim_all_seeding_confirmation' => '确定要认领当前全部做种中的种子吗?',
|
||||||
|
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -33,6 +33,5 @@ return [
|
|||||||
'fields' => [
|
'fields' => [
|
||||||
'torrent_id' => '種子 ID',
|
'torrent_id' => '種子 ID',
|
||||||
],
|
],
|
||||||
'claim_all_seeding_btn' => '一鍵認領',
|
|
||||||
'claim_all_seeding_confirmation' => '確定要認領當前全部做種中的種子嗎?',
|
'claim_all_seeding_confirmation' => '確定要認領當前全部做種中的種子嗎?',
|
||||||
];
|
];
|
||||||
|
|||||||
Reference in New Issue
Block a user