This commit is contained in:
xiaomlove
2025-09-14 00:47:09 +07:00
parent 4c46f376ba
commit c74c88f5a5
10 changed files with 65 additions and 22 deletions

View File

@@ -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;
}
});

View File

@@ -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());
}
}