From c74c88f5a585525d9bb48a02c46895b3855be5c4 Mon Sep 17 00:00:00 2001 From: xiaomlove Date: Sun, 14 Sep 2025 00:47:09 +0700 Subject: [PATCH] misc up --- app/Events/TorrentUpdated.php | 2 +- .../Resources/Torrent/TorrentResource.php | 17 ++++------ app/Repositories/SeedBoxRepository.php | 2 +- app/Repositories/TorrentRepository.php | 32 +++++++++++++++++++ config/horizon.php | 2 +- include/functions.php | 8 ++--- include/globalfunctions.php | 7 ++++ public/shoutbox.php | 2 +- public/takeconfirm.php | 12 +++++-- public/torrentrss.php | 3 +- 10 files changed, 65 insertions(+), 22 deletions(-) diff --git a/app/Events/TorrentUpdated.php b/app/Events/TorrentUpdated.php index d832964d..ca51e92b 100644 --- a/app/Events/TorrentUpdated.php +++ b/app/Events/TorrentUpdated.php @@ -24,7 +24,7 @@ class TorrentUpdated * * @return void */ - public function __construct(Model $model, Model $modelOld) + public function __construct(Model $model, ?Model $modelOld = null) { $this->model = $model; $this->modelOld = $modelOld; diff --git a/app/Filament/Resources/Torrent/TorrentResource.php b/app/Filament/Resources/Torrent/TorrentResource.php index d5370996..fa4142ea 100644 --- a/app/Filament/Resources/Torrent/TorrentResource.php +++ b/app/Filament/Resources/Torrent/TorrentResource.php @@ -363,10 +363,9 @@ class TorrentResource extends Resource return $result; }) ->reactive() - ->afterStateUpdated(fn (callable $set) => $set('section_id', null)) ->required() , - Forms\Components\Select::make('category') + Forms\Components\Select::make('category_id') ->label(__('searchbox.category_label')) ->options(function (callable $get) { $sectionId = $get('section_id'); @@ -375,19 +374,17 @@ class TorrentResource extends Resource } return Category::query()->where('mode', $sectionId)->pluck('name', 'id'); }) - ->reactive() ->required() , ]) ->action(function (Collection $records, array $data) { -// $torrentRep = new TorrentRepository(); -// try { -// $data['torrent_id'] = $record->id; -// $torrentRep->approval(Auth::user(), $data); -// } catch (\Exception $exception) { -// do_log($exception->getMessage(), 'error'); -// } + $torrentRep = new TorrentRepository(); + try { + $torrentRep->changeCategory($records, $data['section_id'], $data['category_id']); + } catch (\Exception $exception) { + do_log($exception->getMessage(), 'error'); + } }); } diff --git a/app/Repositories/SeedBoxRepository.php b/app/Repositories/SeedBoxRepository.php index 1a6d6e71..7c40bb2f 100644 --- a/app/Repositories/SeedBoxRepository.php +++ b/app/Repositories/SeedBoxRepository.php @@ -333,7 +333,7 @@ class SeedBoxRepository extends BaseRepository $asnObj = $reader->asn($ip); return $asnObj->autonomousSystemNumber ?? 0; } catch (\Exception $e) { - do_log("ip: $ip, error: " . $e->getMessage(), 'error'); + do_log("ip: $ip, error: " . $e->getMessage()); return 0; } }); diff --git a/app/Repositories/TorrentRepository.php b/app/Repositories/TorrentRepository.php index 949298f3..6af66cea 100644 --- a/app/Repositories/TorrentRepository.php +++ b/app/Repositories/TorrentRepository.php @@ -4,6 +4,7 @@ namespace App\Repositories; use App\Auth\Permission; use App\Enums\ModelEventEnum; +use App\Events\TorrentUpdated; use App\Exceptions\InsufficientPermissionException; use App\Exceptions\NexusException; use App\Http\Resources\TorrentResource; @@ -18,6 +19,7 @@ use App\Models\Peer; use App\Models\Processing; use App\Models\SearchBox; use App\Models\Setting; +use App\Models\SiteLog; use App\Models\Snatch; use App\Models\Source; use App\Models\StaffMessage; @@ -36,6 +38,7 @@ use Illuminate\Contracts\Auth\Authenticatable; use Illuminate\Database\Eloquent\Builder; use Illuminate\Http\Request; use Illuminate\Support\Arr; +use Illuminate\Support\Collection; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\DB; use Illuminate\Support\Str; @@ -1095,4 +1098,33 @@ HTML; } } + public function changeCategory(Collection $torrents, int $sectionId, int $categoryId): void + { + assert_has_permission(Permission::canManageTorrent()); + $searchBox = SearchBox::query()->findOrFail($sectionId); + $category = $searchBox->categories()->findOrFail($categoryId); + $torrentIdArr = $torrents->pluck('id')->toArray(); + if (empty($torrentIdArr)) { + do_log("torrents is empty", 'warn'); + return; + } + $operatorId = get_user_id(); + $siteLogArr = []; + foreach ($torrents as $torrent) { + $siteLogArr[] = [ + 'added' => now(), + 'txt' => sprintf("torrent: %s category was set to: %s(%s)", $torrent->id, $category->name, $category->id), + 'uid' => $operatorId, + ]; + } + NexusDB::transaction(function () use ($torrentIdArr, $categoryId, $siteLogArr) { + SiteLog::query()->insert($siteLogArr); + Torrent::query()->whereIn('id', $torrentIdArr)->update(['category' => $categoryId]); + }); + foreach ($torrents as $torrent) { + fire_event(ModelEventEnum::TORRENT_UPDATED, $torrent); + } + do_log("success change torrent category to $categoryId, torrent count:" . $torrents->count()); + } + } diff --git a/config/horizon.php b/config/horizon.php index 79deeb05..51719726 100644 --- a/config/horizon.php +++ b/config/horizon.php @@ -183,7 +183,7 @@ return [ 'defaults' => [ 'supervisor-1' => [ 'connection' => 'redis', - 'queue' => ['default', 'nexus_queue'], + 'queue' => ['nexus_queue'], 'balance' => 'auto', 'autoScalingStrategy' => 'time', 'maxProcesses' => 1, diff --git a/include/functions.php b/include/functions.php index a0957c83..ce22615a 100644 --- a/include/functions.php +++ b/include/functions.php @@ -2331,7 +2331,7 @@ function get_css_row() { } $Cache->cache_value('stylesheet_content', $rows, 95400); } - return $rows[$cssid]; + return $rows[$cssid] ?? $rows[$defcss]; } function get_css_uri($file = "") { @@ -6300,13 +6300,11 @@ function build_bonus_table(array $user, array $bonusResult = [], array $options $baseBonusFactor = $donortimes_bonus; } $baseBonus = $bonusResult['seed_bonus'] * $baseBonusFactor; - $totalBonus = number_format( - $baseBonus + $totalBonus = $baseBonus + $haremAddition * $haremFactor + $bonusResult['official_bonus'] * $officialAdditionalFactor + $bonusResult['medal_bonus'] * $bonusResult['medal_additional_factor'] - , 3 - ); + ; $rowSpan = 1; $hasHaremAddition = $hasOfficialAddition = $hasMedalAddition = false; diff --git a/include/globalfunctions.php b/include/globalfunctions.php index 8d8d97ee..8c6dd7da 100644 --- a/include/globalfunctions.php +++ b/include/globalfunctions.php @@ -1280,6 +1280,13 @@ function user_can($permission, $fail = false, $uid = 0): bool throw new \App\Exceptions\InsufficientPermissionException(); } +function assert_has_permission(bool $permissionCheckResult): void +{ + if (!$permissionCheckResult) { + throw new \App\Exceptions\InsufficientPermissionException(); + } +} + function is_donor(array $userInfo): bool diff --git a/public/shoutbox.php b/public/shoutbox.php index a44da2fa..79597e29 100644 --- a/public/shoutbox.php +++ b/public/shoutbox.php @@ -13,7 +13,7 @@ if (isset($_GET['del'])) } } $where=$_GET["type"] ?? ''; -$refresh = ($CURUSER['sbrefresh'] ? $CURUSER['sbrefresh'] : 120) +$refresh = ($CURUSER['sbrefresh'] ?? 120) ?> diff --git a/public/takeconfirm.php b/public/takeconfirm.php index 174341d3..173244d1 100644 --- a/public/takeconfirm.php +++ b/public/takeconfirm.php @@ -10,10 +10,18 @@ if (($CURUSER['id'] != $id && !user_can('viewinvite')) || !is_valid_id($id)) $email = unesc(htmlspecialchars(trim($_POST["email"]))); if(!empty($_POST['conusr'])) { // sql_query("UPDATE users SET status = 'confirmed', editsecret = '' WHERE id IN (" . implode(", ", $_POST['conusr']) . ") AND status='pending'"); - \App\Models\User::query()->whereIn('id', $_POST['conusr']) + $userList = \App\Models\User::query()->whereIn('id', $_POST['conusr']) ->where('status', 'pending') - ->update(['status' => 'confirmed', 'editsecret' => '']) + ->get(\App\Models\User::$commonFields) ; + if ($userList->isNotEmpty()) { + $uidArr = []; + foreach ($userList as $user) { + $uidArr[] = $user->id; + fire_event(\App\Enums\ModelEventEnum::USER_UPDATED, $user); + } + \App\Models\User::query()->whereIn('id', $uidArr)->update(['status' => 'confirmed', 'editsecret' => '']); + } } else { stderr($lang_takeconfirm['std_sorry'],$lang_takeconfirm['std_no_buddy_to_confirm']. "".$lang_takeconfirm['std_here_to_go_back'],false); diff --git a/public/torrentrss.php b/public/torrentrss.php index c8ccee2c..9d544b9c 100644 --- a/public/torrentrss.php +++ b/public/torrentrss.php @@ -4,7 +4,8 @@ $passkey = $_GET['passkey'] ?? $CURUSER['passkey'] ?? ''; if (!$passkey) { die("require passkey"); } -$cacheKey = "nexus_rss:$passkey:" . md5(http_build_query($_GET)); +unset($_GET['passkey']); +$cacheKey = "nexus_rss:" . md5(http_build_query($_GET)); $cacheData = \Nexus\Database\NexusDB::cache_get($cacheKey); if ($cacheData && nexus_env('APP_ENV') != 'local') { do_log("rss get from cache");