refactor: 外链中转拆为内置插件 neatstudio.link-tracker
- 插件承载全部逻辑:redirects 迁移(hasTable 兼容旧库)、Redirect 模型、UrlRedirector、/go 路由+控制器、Filament 外链中转资源 - 核心只留 hook 接入点: - tracked_url() 助手走 link.redirect 过滤器(评论正文/作者网址/友链模板统一调用) - 正文外链改写移到插件的 post.rendered 过滤器(优先级 20,晚于会员付费过滤) - 停用插件:链接恢复直连、内容不受影响;后台「管理 → 外链中转」查看点击量/启停 - 测试更新为插件上下文(含无过滤器降级断言);97 通过
This commit is contained in:
@@ -1,90 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use App\Filament\Resources\RedirectResource\Pages\ListRedirects;
|
||||
use App\Models\Redirect;
|
||||
use BackedEnum;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class RedirectResource extends Resource
|
||||
{
|
||||
protected static \UnitEnum|string|null $navigationGroup = '管理';
|
||||
|
||||
protected static ?string $model = Redirect::class;
|
||||
|
||||
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedArrowUturnRight;
|
||||
|
||||
protected static ?string $navigationLabel = '外链中转';
|
||||
|
||||
protected static ?string $pluralModelLabel = '外链中转';
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
return $schema;
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
TextColumn::make('hash')
|
||||
->label('短码')
|
||||
->badge()
|
||||
->color('gray'),
|
||||
TextColumn::make('target_url')
|
||||
->label('目标地址')
|
||||
->limit(50)
|
||||
->copyable()
|
||||
->searchable(),
|
||||
TextColumn::make('clicks')
|
||||
->label('点击量')
|
||||
->numeric()
|
||||
->sortable(),
|
||||
TextColumn::make('status')
|
||||
->label('状态')
|
||||
->badge()
|
||||
->formatStateUsing(fn ($state) => $state === 'active' ? '启用' : '停用')
|
||||
->color(fn ($state) => $state === 'active' ? 'success' : 'danger'),
|
||||
TextColumn::make('last_clicked_at')
|
||||
->label('最后点击')
|
||||
->dateTime('Y-m-d H:i')
|
||||
->placeholder('—')
|
||||
->sortable(),
|
||||
TextColumn::make('created_at')
|
||||
->label('创建时间')
|
||||
->dateTime('Y-m-d H:i')
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
])
|
||||
->filters([
|
||||
\Filament\Tables\Filters\SelectFilter::make('status')
|
||||
->label('状态')
|
||||
->options(['active' => '启用', 'disabled' => '停用']),
|
||||
], \Filament\Tables\Enums\FiltersLayout::AboveContent)
|
||||
->recordActions([
|
||||
Action::make('toggle')
|
||||
->label(fn (Redirect $record) => $record->isActive() ? '停用' : '启用')
|
||||
->color(fn (Redirect $record) => $record->isActive() ? 'danger' : 'success')
|
||||
->action(fn (Redirect $record) => $record->update(['status' => $record->isActive() ? 'disabled' : 'active'])),
|
||||
DeleteAction::make(),
|
||||
])
|
||||
->recordUrl(null)
|
||||
->recordAction(null)
|
||||
->defaultSort('clicks', 'desc');
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => ListRedirects::route('/'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Filament\Resources\RedirectResource\Pages;
|
||||
|
||||
use App\Filament\Resources\RedirectResource;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListRedirects extends ListRecords
|
||||
{
|
||||
protected static string $resource = RedirectResource::class;
|
||||
}
|
||||
Reference in New Issue
Block a user