feat: xxbb

This commit is contained in:
hashbro
2026-08-14 16:09:41 +08:00
parent 8a110af66d
commit 01d1ef76a8
5 changed files with 58 additions and 13 deletions
@@ -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);
+1 -1
View File
@@ -31,7 +31,7 @@
<td>{{ number_format($f['size']) }} B</td>
<td>{{ $f['mtime'] }}</td>
<td>
<a class="layui-btn layui-btn-xs" href="{{ route('admin.logs.show', ['file' => $f['name'], 'kind' => $k, 'path' => $path, 'device' => $device]) }}">查看</a>
<a class="layui-btn layui-btn-xs" href="{{ route('admin.logs.show', ['kind' => $k, 'file' => $f['name'], 'path' => $path, 'device' => $device]) }}">查看</a>
</td>
</tr>
@empty
+6 -7
View File
@@ -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 @@
<a class="layui-btn layui-btn-primary layui-btn-xs" style="float:right;margin-top:8px;" href="{{ route('admin.logs.index') }}">返回</a>
</div>
<div class="layui-card-body">
<form class="layui-form" method="get" style="margin-bottom: 15px;">
<input type="hidden" name="kind" value="{{ $kind ?? 'c2' }}">
<form class="layui-form" method="get" action="{{ route('admin.logs.show', $showBase) }}" style="margin-bottom: 15px;">
<div class="layui-inline">
<input type="text" name="device" value="{{ $device ?? '' }}" placeholder="设备 ID" class="layui-input" style="width:200px;">
</div>
@@ -33,10 +32,10 @@
</p>
<div style="margin-bottom:12px;">
@if ($hasNewer ?? false)
<a class="layui-btn layui-btn-sm layui-btn-primary" href="{{ route('admin.logs.show', array_merge($query, ['file' => $file, 'page' => ($page ?? 1) - 1])) }}">更新</a>
<a class="layui-btn layui-btn-sm layui-btn-primary" href="{{ route('admin.logs.show', array_merge($showBase, $query, ['page' => ($page ?? 1) - 1])) }}">更新</a>
@endif
@if ($hasOlder ?? false)
<a class="layui-btn layui-btn-sm" href="{{ route('admin.logs.show', array_merge($query, ['file' => $file, 'page' => ($page ?? 1) + 1])) }}">更早</a>
<a class="layui-btn layui-btn-sm" href="{{ route('admin.logs.show', array_merge($showBase, $query, ['page' => ($page ?? 1) + 1])) }}">更早</a>
@endif
</div>
@forelse ($entries as $entry)
@@ -46,10 +45,10 @@
@endforelse
<div style="margin-top:12px;">
@if ($hasNewer ?? false)
<a class="layui-btn layui-btn-sm layui-btn-primary" href="{{ route('admin.logs.show', array_merge($query, ['file' => $file, 'page' => ($page ?? 1) - 1])) }}">更新</a>
<a class="layui-btn layui-btn-sm layui-btn-primary" href="{{ route('admin.logs.show', array_merge($showBase, $query, ['page' => ($page ?? 1) - 1])) }}">更新</a>
@endif
@if ($hasOlder ?? false)
<a class="layui-btn layui-btn-sm" href="{{ route('admin.logs.show', array_merge($query, ['file' => $file, 'page' => ($page ?? 1) + 1])) }}">更早</a>
<a class="layui-btn layui-btn-sm" href="{{ route('admin.logs.show', array_merge($showBase, $query, ['page' => ($page ?? 1) + 1])) }}">更早</a>
@endif
</div>
</div>
+6 -1
View File
@@ -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');
+43 -2
View File
@@ -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'));
}
}
}