mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-24 03:57:22 +08:00
misc up
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user