feat: 外链中转 /go——点击统计 + 拦截 + 隐藏真实链接

- redirects 表 + UrlRedirector:go_url() 站外链接改写为 /go/{hash}(确定性 hash、同 URL 复用、并发安全、缓存)
- /go/{hash} 302 跳转 + 点击计数 + 最后点击时间;停用状态 410(二次拦截);后台「外链中转」资源可查看点击量/启停/删除
- 接入点:正文外链(渲染器统一改写)、评论正文自动链接(comment_body)、评论作者网址、友链(侧边栏+友链页);站内/相对/mailto/tel/锚点不中转
- 测试 6 个(改写/计数/拦截/复用/渲染/评论正文);README 补充
This commit is contained in:
ak
2026-08-13 01:28:10 +08:00
parent 5f74dd76e4
commit 8f1ff6e3f9
17 changed files with 421 additions and 8 deletions
+4
View File
@@ -7,6 +7,7 @@ use App\Blog\Controllers\AuthController;
use App\Blog\Controllers\CategoryController;
use App\Blog\Controllers\CommentController;
use App\Blog\Controllers\FeedController;
use App\Blog\Controllers\GoController;
use App\Blog\Controllers\HomeController;
use App\Blog\Controllers\LegacyController;
use App\Blog\Controllers\LinkController;
@@ -38,6 +39,9 @@ Route::post('/posts/{post}/comments', [CommentController::class, 'store'])->name
// 浏览量统计(独立端点,避开整页缓存,保证实时)
Route::get('/track-view/{post}', fn (\App\Models\Post $post) => response($post->increment('views') ? '' : '', 204))->name('track-view');
// 外链中转:/go/{hash} 302 跳转,记录点击量;停用状态返回 410
Route::get('/go/{hash}', [GoController::class, 'show'])->name('go.show');
Route::get('/category/{slug}.shtml', [CategoryController::class, 'show'])->where('slug', '[^/]+')->name('category.show');
Route::get('/category/{slug}', fn (string $slug) => redirect()->route('category.show', $slug, 301))->where('slug', '[^/]+');