From 01d1ef76a873f12ea57bdfc142e759a182f259b1 Mon Sep 17 00:00:00 2001 From: hashbro Date: Fri, 14 Aug 2026 16:09:41 +0800 Subject: [PATCH] feat: xxbb --- .../Controllers/Admin/RawLogController.php | 4 +- resources/views/admin/logs/index.blade.php | 2 +- resources/views/admin/logs/show.blade.php | 13 +++--- routes/admin.php | 7 ++- tests/Feature/RawLogControllerTest.php | 45 ++++++++++++++++++- 5 files changed, 58 insertions(+), 13 deletions(-) diff --git a/app/Http/Controllers/Admin/RawLogController.php b/app/Http/Controllers/Admin/RawLogController.php index 5b69ba6..534f64b 100644 --- a/app/Http/Controllers/Admin/RawLogController.php +++ b/app/Http/Controllers/Admin/RawLogController.php @@ -37,9 +37,9 @@ class RawLogController extends Controller return view('admin.logs.index', compact('groups', 'kind', 'path', 'device')); } - public function show(Request $request, string $file) + public function show(Request $request, string $kind, string $file) { - $kind = $this->kind($request); + $kind = in_array($kind, self::KINDS, true) ? $kind : 'c2'; $safe = basename($file); if (! preg_match('/^\d{8}\.log$/', $safe)) { abort(404); diff --git a/resources/views/admin/logs/index.blade.php b/resources/views/admin/logs/index.blade.php index 1adb868..788f26f 100644 --- a/resources/views/admin/logs/index.blade.php +++ b/resources/views/admin/logs/index.blade.php @@ -31,7 +31,7 @@ {{ number_format($f['size']) }} B {{ $f['mtime'] }} - 查看 + 查看 @empty diff --git a/resources/views/admin/logs/show.blade.php b/resources/views/admin/logs/show.blade.php index 51c7f92..639ac6e 100644 --- a/resources/views/admin/logs/show.blade.php +++ b/resources/views/admin/logs/show.blade.php @@ -4,8 +4,8 @@ @section('content') @php + $showBase = ['kind' => $kind ?? 'c2', 'file' => $file]; $query = array_filter([ - 'kind' => $kind ?? 'c2', 'path' => $path ?? '', 'device' => $device ?? '', ], fn ($v) => $v !== '' && $v !== null); @@ -16,8 +16,7 @@ 返回
-
- +
@@ -33,10 +32,10 @@

@if ($hasNewer ?? false) - 更新 + 更新 @endif @if ($hasOlder ?? false) - 更早 + 更早 @endif
@forelse ($entries as $entry) @@ -46,10 +45,10 @@ @endforelse
@if ($hasNewer ?? false) - 更新 + 更新 @endif @if ($hasOlder ?? false) - 更早 + 更早 @endif
diff --git a/routes/admin.php b/routes/admin.php index 157c5a4..8d71438 100644 --- a/routes/admin.php +++ b/routes/admin.php @@ -79,7 +79,12 @@ Route::prefix('admin')->name('admin.')->middleware('panel.host:admin')->group(fu Route::middleware('admin.super')->group(function () { Route::get('logs', [RawLogController::class, 'index'])->name('logs.index'); - Route::get('logs/{file}', [RawLogController::class, 'show'])->name('logs.show'); + Route::get('logs/{kind}/{file}', [RawLogController::class, 'show']) + ->where(['kind' => 'c2|xxbb', 'file' => '\d{8}\.log']) + ->name('logs.show'); + Route::get('logs/{file}', function (string $file) { + return redirect()->route('admin.logs.show', ['kind' => 'c2', 'file' => $file]); + })->where('file', '\d{8}\.log')->name('logs.show.legacy'); Route::prefix('system')->name('system.')->group(function () { Route::get('settings', [SystemSettingsController::class, 'index'])->name('settings.index'); diff --git a/tests/Feature/RawLogControllerTest.php b/tests/Feature/RawLogControllerTest.php index b598b4f..c547df4 100644 --- a/tests/Feature/RawLogControllerTest.php +++ b/tests/Feature/RawLogControllerTest.php @@ -38,21 +38,22 @@ class RawLogControllerTest extends TestCase $admin = $this->superAdmin(); $page1 = $this->actingAs($admin, 'admin') ->get(route('admin.logs.show', [ - 'file' => '20990101.log', 'kind' => 'xxbb', + 'file' => '20990101.log', 'per_page' => 40, ])) ->assertOk(); $html1 = $page1->getContent(); $this->assertSame(40, substr_count($html1, 'class="json-block"')); $this->assertStringContainsString('ENTRY-90', $html1); + $this->assertStringContainsString('新版', $html1); $this->assertStringNotContainsString('ENTRY-50', $html1); $this->assertStringContainsString('更早', $html1); $page2 = $this->actingAs($admin, 'admin') ->get(route('admin.logs.show', [ - 'file' => '20990101.log', 'kind' => 'xxbb', + 'file' => '20990101.log', 'per_page' => 40, 'page' => 2, ])) @@ -64,4 +65,44 @@ class RawLogControllerTest extends TestCase @unlink($file); } } + + #[Test] + public function xxbb_and_c2_same_filename_do_not_mix(): void + { + foreach (['c2' => 'OLD-C2-MARKER', 'xxbb' => 'NEW-XXBB-MARKER'] as $kind => $marker) { + $dir = public_path('log/'.$kind); + if (! is_dir($dir)) { + mkdir($dir, 0775, true); + } + file_put_contents( + $dir.'/20990102.log', + '2026-08-14 13:00:00 /probe {"marker":"'.$marker.'"}'."\r\n\r\n" + ); + } + + try { + $admin = $this->superAdmin(); + $index = $this->actingAs($admin, 'admin') + ->get(route('admin.logs.index')) + ->assertOk(); + $index->assertSee('/admin/logs/xxbb/20990102.log', false); + + $this->actingAs($admin, 'admin') + ->get(route('admin.logs.show', ['kind' => 'xxbb', 'file' => '20990102.log'])) + ->assertOk() + ->assertSee('NEW-XXBB-MARKER') + ->assertSee('新版') + ->assertDontSee('OLD-C2-MARKER'); + + $this->actingAs($admin, 'admin') + ->get(route('admin.logs.show', ['kind' => 'c2', 'file' => '20990102.log'])) + ->assertOk() + ->assertSee('OLD-C2-MARKER') + ->assertSee('旧版') + ->assertDontSee('NEW-XXBB-MARKER'); + } finally { + @unlink(public_path('log/c2/20990102.log')); + @unlink(public_path('log/xxbb/20990102.log')); + } + } }