mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-14 20:40:49 +08:00
Merge branch 'php8' into section
This commit is contained in:
@@ -38,6 +38,7 @@ use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Redis;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Str;
|
||||
use Imdb\Cache;
|
||||
use League\Flysystem\StorageAttributes;
|
||||
use Nexus\Database\NexusDB;
|
||||
use Nexus\Imdb\Imdb;
|
||||
@@ -86,11 +87,7 @@ class Test extends Command
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$box = SearchBox::query()->find(6);
|
||||
$update = [
|
||||
'extra->taxonomy_labels->ss' => '444'
|
||||
];
|
||||
$box->update($update);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -163,6 +163,7 @@ class TorrentResource extends Resource
|
||||
$torrentRep = new TorrentRepository();
|
||||
$torrentRep->setPosState($idArr, $data['pos_state']);
|
||||
} catch (\Exception $exception) {
|
||||
do_log($exception->getMessage() . $exception->getTraceAsString(), 'error');
|
||||
Filament::notify('danger', class_basename($exception));
|
||||
}
|
||||
})
|
||||
@@ -180,6 +181,7 @@ class TorrentResource extends Resource
|
||||
$torrentRep = new TorrentRepository();
|
||||
$torrentRep->syncTags($idArr);
|
||||
} catch (\Exception $exception) {
|
||||
do_log($exception->getMessage() . $exception->getTraceAsString(), 'error');
|
||||
Filament::notify('danger', class_basename($exception));
|
||||
}
|
||||
})
|
||||
@@ -188,11 +190,13 @@ class TorrentResource extends Resource
|
||||
$actions[] = Tables\Actions\BulkAction::make('attach_tag')
|
||||
->label(__('admin.resources.torrent.bulk_action_attach_tag'))
|
||||
->form([
|
||||
Forms\Components\Checkbox::make('remove')->label(__('admin.resources.torrent.bulk_action_attach_tag_remove_old')),
|
||||
Forms\Components\CheckboxList::make('tags')
|
||||
->label(__('label.tag.label'))
|
||||
->columns(4)
|
||||
->options(TagRepository::createBasicQuery()->pluck('name', 'id')->toArray())
|
||||
->required(),
|
||||
|
||||
])
|
||||
->icon('heroicon-o-tag')
|
||||
->action(function (Collection $records, array $data) {
|
||||
@@ -202,8 +206,9 @@ class TorrentResource extends Resource
|
||||
$idArr = $records->pluck('id')->toArray();
|
||||
try {
|
||||
$torrentRep = new TorrentRepository();
|
||||
$torrentRep->syncTags($idArr, $data['tags']);
|
||||
$torrentRep->syncTags($idArr, $data['tags'], $data['remove'] ?? false);
|
||||
} catch (\Exception $exception) {
|
||||
do_log($exception->getMessage() . $exception->getTraceAsString(), 'error');
|
||||
Filament::notify('danger', class_basename($exception));
|
||||
}
|
||||
})
|
||||
|
||||
@@ -6,6 +6,7 @@ use App\Filament\OptionsTrait;
|
||||
use App\Filament\Resources\User\UserResource\Pages;
|
||||
use App\Filament\Resources\User\UserResource\RelationManagers;
|
||||
use App\Models\User;
|
||||
use App\Repositories\UserRepository;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Components\Grid;
|
||||
use Filament\Resources\Form;
|
||||
@@ -15,6 +16,8 @@ use Filament\Tables;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\HtmlString;
|
||||
|
||||
class UserResource extends Resource
|
||||
@@ -85,9 +88,7 @@ class UserResource extends Resource
|
||||
->actions([
|
||||
Tables\Actions\ViewAction::make(),
|
||||
])
|
||||
->bulkActions([
|
||||
// Tables\Actions\DeleteBulkAction::make(),
|
||||
]);
|
||||
->bulkActions(self::getBulkActions());
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
@@ -108,4 +109,21 @@ class UserResource extends Resource
|
||||
];
|
||||
}
|
||||
|
||||
public static function getBulkActions(): array
|
||||
{
|
||||
$actions = [];
|
||||
if (Auth::user()->class >= User::CLASS_SYSOP) {
|
||||
$actions[] = Tables\Actions\BulkAction::make('confirm')
|
||||
->label(__('admin.resources.user.actions.confirm_bulk'))
|
||||
->requiresConfirmation()
|
||||
->deselectRecordsAfterCompletion()
|
||||
->action(function (Collection $records) {
|
||||
$rep = new UserRepository();
|
||||
$rep->confirmUser($records->pluck('id')->toArray());
|
||||
});
|
||||
}
|
||||
|
||||
return $actions;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -287,8 +287,10 @@ class UserProfile extends Page
|
||||
try {
|
||||
if (!empty($data['duration'])) {
|
||||
$data['deadline'] = now()->addDays($data['duration']);
|
||||
} else {
|
||||
$data['deadline'] = null;
|
||||
}
|
||||
$rep->addMeta($this->record, $data);
|
||||
$rep->addMeta($this->record, $data, $data);
|
||||
$this->notify('success', 'Success!');
|
||||
$this->emitSelf(self::EVENT_RECORD_UPDATED, $this->record->id);
|
||||
} catch (\Exception $exception) {
|
||||
|
||||
@@ -57,4 +57,20 @@ class Controller extends BaseController
|
||||
return Str::slug("$title.$action", '.');
|
||||
}
|
||||
|
||||
protected function getPaginationParameters(): array
|
||||
{
|
||||
$request = request();
|
||||
$format = $request->__format;
|
||||
if ($format == 'data-table') {
|
||||
$perPage = $request->length;
|
||||
$page = intval($request->start / $perPage) + 1;
|
||||
} else {
|
||||
$perPage = $request->limit;
|
||||
$page = $request->page;
|
||||
}
|
||||
return [$perPage, ['*'], 'page', $page];
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ class Peer extends NexusModel
|
||||
protected $fillable = [
|
||||
'torrent', 'peer_id', 'ip', 'port', 'uploaded', 'downloaded', 'to_go', 'seeder', 'started', 'last_action',
|
||||
'prev_action', 'connectable', 'userid', 'agent', 'finishedat', 'downloadoffset', 'uploadedoffset', 'passkey',
|
||||
'ipv4', 'ipv6',
|
||||
'ipv4', 'ipv6', 'is_seed_box'
|
||||
];
|
||||
|
||||
const CONNECTABLE_YES = 'yes';
|
||||
|
||||
@@ -6,11 +6,11 @@ use App\Http\Middleware\Locale;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\View;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
use Nexus\Nexus;
|
||||
use Filament\Facades\Filament;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use NexusPlugin\Menu\Filament\MenuItemResource;
|
||||
|
||||
class AppServiceProvider extends ServiceProvider
|
||||
@@ -44,11 +44,6 @@ class AppServiceProvider extends ServiceProvider
|
||||
]);
|
||||
});
|
||||
|
||||
// Filament::registerRenderHook(
|
||||
// 'content.end',
|
||||
// fn (): View => view('filament.footer'),
|
||||
// );
|
||||
|
||||
Filament::registerStyles([
|
||||
asset('styles/sprites.css'),
|
||||
asset('styles/admin.css'),
|
||||
|
||||
@@ -138,12 +138,20 @@ class SeedBoxRepository extends BaseRepository
|
||||
}
|
||||
foreach (Arr::wrap($ipArr) as $ip) {
|
||||
if ((isIPV4($ip) || isIPV6($ip)) && $enableSeedBox && isIPSeedBox($ip, $uid)) {
|
||||
return '<img src="pic/misc/seed-box.png" style="vertical-align: bottom; height: 16px; margin-left: 4px" title="SeedBox" />';
|
||||
return $this->getSeedBoxIcon();
|
||||
}
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
public function getSeedBoxIcon($isSeedBox = true): string
|
||||
{
|
||||
if (!$isSeedBox) {
|
||||
return '';
|
||||
}
|
||||
return '<img src="pic/misc/seed-box.png" style="vertical-align: bottom; height: 16px; margin-left: 4px" title="SeedBox" />';
|
||||
}
|
||||
|
||||
private function clearCache()
|
||||
{
|
||||
return true;
|
||||
|
||||
@@ -30,6 +30,7 @@ use Hashids\Hashids;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
use Nexus\Database\NexusDB;
|
||||
|
||||
@@ -572,28 +573,27 @@ class TorrentRepository extends BaseRepository
|
||||
return false;
|
||||
}
|
||||
|
||||
public function syncTags($id, array $tagIdArr = [])
|
||||
public function syncTags($id, array $tagIdArr = [], $remove = true)
|
||||
{
|
||||
user_can('torrentmanage', true);
|
||||
$idArr = Arr::wrap($id);
|
||||
return NexusDB::transaction(function () use ($idArr, $tagIdArr) {
|
||||
$insert = [];
|
||||
return NexusDB::transaction(function () use ($idArr, $tagIdArr, $remove) {
|
||||
$sql = "insert into torrent_tags (torrent_id, tag_id, created_at, updated_at) values ";
|
||||
$time = now()->toDateTimeString();
|
||||
$values = [];
|
||||
foreach ($idArr as $torrentId) {
|
||||
foreach ($tagIdArr as $tagId) {
|
||||
$insert[] = [
|
||||
'torrent_id' => $torrentId,
|
||||
'tag_id' => $tagId,
|
||||
'created_at' => $time,
|
||||
'updated_at' => $time,
|
||||
];
|
||||
$values[] = sprintf("(%s, %s, '%s', '%s')", $torrentId, $tagId, $time, $time);
|
||||
}
|
||||
}
|
||||
TorrentTag::query()->whereIn('torrent_id', $idArr)->delete();
|
||||
if (!empty($insert)) {
|
||||
TorrentTag::query()->insert($insert);
|
||||
$sql .= implode(', ', $values) . " on duplicate key update updated_at = values(updated_at)";
|
||||
if ($remove) {
|
||||
TorrentTag::query()->whereIn('torrent_id', $idArr)->delete();
|
||||
}
|
||||
return count($insert);
|
||||
if (!empty($values)) {
|
||||
DB::insert($sql);
|
||||
}
|
||||
return count($values);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@@ -841,11 +841,16 @@ class TrackerRepository extends BaseRepository
|
||||
'agent' => $queries['user_agent'],
|
||||
'connectable' => $this->getConnectable($queries['ip'], $queries['port'], $queries['user_agent'])
|
||||
];
|
||||
$isSeedBox = false;
|
||||
if (!empty($queries['ipv4'])) {
|
||||
$update['ipv4'] = $queries['ipv4'];
|
||||
$isSeedBox = isIPSeedBox($queries['ipv4'], $peer->userid);
|
||||
}
|
||||
if (!empty($queries['ipv6'])) {
|
||||
$update['ipv6'] = $queries['ipv6'];
|
||||
if (!$isSeedBox) {
|
||||
$isSeedBox = isIPSeedBox($queries['ipv6'], $peer->userid);
|
||||
}
|
||||
}
|
||||
|
||||
if ($peer->exists) {
|
||||
@@ -865,6 +870,7 @@ class TrackerRepository extends BaseRepository
|
||||
$update['last_action'] = $nowStr;
|
||||
$update['uploaded'] = $queries['uploaded'];
|
||||
$update['downloaded'] = $queries['downloaded'];
|
||||
$update['is_seed_box'] = intval($isSeedBox);
|
||||
|
||||
$logData = json_encode(Arr::except($update, ['peer_id']));
|
||||
if ($peer->exists) {
|
||||
|
||||
@@ -138,7 +138,10 @@ class UserRepository extends BaseRepository
|
||||
throw new \InvalidArgumentException("password confirmation != password");
|
||||
}
|
||||
$user = User::query()->findOrFail($id, ['id', 'username', 'class']);
|
||||
$this->checkPermission(Auth::user(), $user);
|
||||
$operator = Auth::user();
|
||||
if ($operator) {
|
||||
$this->checkPermission($operator, $user);
|
||||
}
|
||||
$secret = mksecret();
|
||||
$passhash = md5($secret . $password . $secret);
|
||||
$update = [
|
||||
@@ -480,4 +483,18 @@ class UserRepository extends BaseRepository
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function confirmUser($id): bool
|
||||
{
|
||||
$update = [
|
||||
'status' => User::STATUS_CONFIRMED,
|
||||
'editsecret' => '',
|
||||
];
|
||||
User::query()
|
||||
->whereIn('id', Arr::wrap($id))
|
||||
->where('status', User::STATUS_PENDING)
|
||||
->update($update);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user