From 9fec1a7edef90fe562229e87f38dc776fb372694 Mon Sep 17 00:00:00 2001 From: xiaomlove Date: Tue, 8 Oct 2024 00:22:52 +0800 Subject: [PATCH] up --- app/Console/Commands/Test.php | 14 +++++++++++++- app/Jobs/LoadTorrentBoughtUsers.php | 4 ++++ include/constants.php | 2 +- nexus/Plugin/BasePlugin.php | 12 ++++++++++-- public/viewpeerlist.php | 28 ++++++++++++++++++---------- 5 files changed, 46 insertions(+), 14 deletions(-) diff --git a/app/Console/Commands/Test.php b/app/Console/Commands/Test.php index 1f65219c4..3cee37fda 100644 --- a/app/Console/Commands/Test.php +++ b/app/Console/Commands/Test.php @@ -40,10 +40,12 @@ use Carbon\Carbon; use Filament\Notifications\Notification; use GeoIp2\Database\Reader; +use GuzzleHttp\Client; use Illuminate\Console\Command; use Illuminate\Encryption\Encrypter; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Hash; +use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Redis; use Illuminate\Support\Facades\Storage; use Illuminate\Support\Str; @@ -98,7 +100,17 @@ public function __construct() */ public function handle() { - CleanupRepository::checkQueueFailedJobs(); + $url = "http://127.0.0.1:7777/list-seeder-leecher-count"; + $idArr = [8, 12]; + $client = new Client(); + $response = $client->post($url, ['json' => ['torrent_ids' => $idArr]]); + $result = json_decode((string)$response->getBody(), true); + dump($result); + if (!isset($result['ret']) || $result['ret'] != 0) { + echo "Bad"; + } else { + echo "OK"; + } } } diff --git a/app/Jobs/LoadTorrentBoughtUsers.php b/app/Jobs/LoadTorrentBoughtUsers.php index a75a40a1e..90e05d997 100644 --- a/app/Jobs/LoadTorrentBoughtUsers.php +++ b/app/Jobs/LoadTorrentBoughtUsers.php @@ -16,6 +16,10 @@ class LoadTorrentBoughtUsers implements ShouldQueue private int $torrentId; + public $tries = 1; + + public $timeout = 1800; + /** * Create a new job instance. * diff --git a/include/constants.php b/include/constants.php index fc1cb9898..f03d4ca22 100644 --- a/include/constants.php +++ b/include/constants.php @@ -1,6 +1,6 @@ getFileName(), 2); return $pluginRoot . "/resources/views/" . trim($name, "/"); } + + public function trans($name): string + { + return nexus_trans(sprintf("%s::%s", static::ID, $name)); + } + + public static function getInstance(): static + { + return Plugin::getById(static::ID); + } } diff --git a/public/viewpeerlist.php b/public/viewpeerlist.php index 813902d20..446e9d674 100644 --- a/public/viewpeerlist.php +++ b/public/viewpeerlist.php @@ -168,16 +168,24 @@ function dltable($name, $arr, $torrent, &$isSeedBoxCaseWhens) $s .= "\n"; return $s; } - $downloaders = array(); - $seeders = array(); - $torrent = \App\Models\Torrent::query()->findOrFail($id, ['id', 'seeders', 'leechers']); - $subres = sql_query("SELECT id, seeder, finishedat, downloadoffset, uploadoffset, ip, ipv4, ipv6, port, uploaded, downloaded, to_go, UNIX_TIMESTAMP(started) AS st, connectable, agent, peer_id, UNIX_TIMESTAMP(last_action) AS la, userid FROM peers WHERE torrent = $id") or sqlerr(); - while ($subrow = mysql_fetch_array($subres)) { - if ($subrow["seeder"] == "yes") - $seeders[] = $subrow; - else - $downloaders[] = $subrow; - } + $downloaders = array(); + $seeders = array(); + $torrent = \App\Models\Torrent::query()->findOrFail($id, ['id', 'seeders', 'leechers']); + $seedersAndLeechers = apply_filter("torrent_seeder_leecher_list", [], $id); + if (isset($seedersAndLeechers['seeders'], $seedersAndLeechers['leechers'])) { +// dd($seedersAndLeechers); + $seeders = $seedersAndLeechers['seeders']; + $downloaders = $seedersAndLeechers['leechers']; + do_log("SEEDER_LEECHER_FROM_FILTER: torrent_seeder_leecher_list"); + } else { + $subres = sql_query("SELECT id, seeder, finishedat, downloadoffset, uploadoffset, ip, ipv4, ipv6, port, uploaded, downloaded, to_go, UNIX_TIMESTAMP(started) AS st, connectable, agent, peer_id, UNIX_TIMESTAMP(last_action) AS la, userid FROM peers WHERE torrent = $id") or sqlerr(); + while ($subrow = mysql_fetch_array($subres)) { + if ($subrow["seeder"] == "yes") + $seeders[] = $subrow; + else + $downloaders[] = $subrow; + } + } $seedersCount = count($seeders); $leechersCount = count($downloaders); if ($torrent->seeders != $seedersCount || $torrent->leechers != $leechersCount) {