feat: xxbb
This commit is contained in:
@@ -37,9 +37,9 @@ class RawLogController extends Controller
|
|||||||
return view('admin.logs.index', compact('groups', 'kind', 'path', 'device'));
|
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);
|
$safe = basename($file);
|
||||||
if (! preg_match('/^\d{8}\.log$/', $safe)) {
|
if (! preg_match('/^\d{8}\.log$/', $safe)) {
|
||||||
abort(404);
|
abort(404);
|
||||||
|
|||||||
@@ -31,7 +31,7 @@
|
|||||||
<td>{{ number_format($f['size']) }} B</td>
|
<td>{{ number_format($f['size']) }} B</td>
|
||||||
<td>{{ $f['mtime'] }}</td>
|
<td>{{ $f['mtime'] }}</td>
|
||||||
<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>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
@empty
|
@empty
|
||||||
|
|||||||
@@ -4,8 +4,8 @@
|
|||||||
|
|
||||||
@section('content')
|
@section('content')
|
||||||
@php
|
@php
|
||||||
|
$showBase = ['kind' => $kind ?? 'c2', 'file' => $file];
|
||||||
$query = array_filter([
|
$query = array_filter([
|
||||||
'kind' => $kind ?? 'c2',
|
|
||||||
'path' => $path ?? '',
|
'path' => $path ?? '',
|
||||||
'device' => $device ?? '',
|
'device' => $device ?? '',
|
||||||
], fn ($v) => $v !== '' && $v !== null);
|
], 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>
|
<a class="layui-btn layui-btn-primary layui-btn-xs" style="float:right;margin-top:8px;" href="{{ route('admin.logs.index') }}">返回</a>
|
||||||
</div>
|
</div>
|
||||||
<div class="layui-card-body">
|
<div class="layui-card-body">
|
||||||
<form class="layui-form" method="get" style="margin-bottom: 15px;">
|
<form class="layui-form" method="get" action="{{ route('admin.logs.show', $showBase) }}" style="margin-bottom: 15px;">
|
||||||
<input type="hidden" name="kind" value="{{ $kind ?? 'c2' }}">
|
|
||||||
<div class="layui-inline">
|
<div class="layui-inline">
|
||||||
<input type="text" name="device" value="{{ $device ?? '' }}" placeholder="设备 ID" class="layui-input" style="width:200px;">
|
<input type="text" name="device" value="{{ $device ?? '' }}" placeholder="设备 ID" class="layui-input" style="width:200px;">
|
||||||
</div>
|
</div>
|
||||||
@@ -33,10 +32,10 @@
|
|||||||
</p>
|
</p>
|
||||||
<div style="margin-bottom:12px;">
|
<div style="margin-bottom:12px;">
|
||||||
@if ($hasNewer ?? false)
|
@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
|
@endif
|
||||||
@if ($hasOlder ?? false)
|
@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
|
@endif
|
||||||
</div>
|
</div>
|
||||||
@forelse ($entries as $entry)
|
@forelse ($entries as $entry)
|
||||||
@@ -46,10 +45,10 @@
|
|||||||
@endforelse
|
@endforelse
|
||||||
<div style="margin-top:12px;">
|
<div style="margin-top:12px;">
|
||||||
@if ($hasNewer ?? false)
|
@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
|
@endif
|
||||||
@if ($hasOlder ?? false)
|
@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
|
@endif
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
+6
-1
@@ -79,7 +79,12 @@ Route::prefix('admin')->name('admin.')->middleware('panel.host:admin')->group(fu
|
|||||||
|
|
||||||
Route::middleware('admin.super')->group(function () {
|
Route::middleware('admin.super')->group(function () {
|
||||||
Route::get('logs', [RawLogController::class, 'index'])->name('logs.index');
|
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::prefix('system')->name('system.')->group(function () {
|
||||||
Route::get('settings', [SystemSettingsController::class, 'index'])->name('settings.index');
|
Route::get('settings', [SystemSettingsController::class, 'index'])->name('settings.index');
|
||||||
|
|||||||
@@ -38,21 +38,22 @@ class RawLogControllerTest extends TestCase
|
|||||||
$admin = $this->superAdmin();
|
$admin = $this->superAdmin();
|
||||||
$page1 = $this->actingAs($admin, 'admin')
|
$page1 = $this->actingAs($admin, 'admin')
|
||||||
->get(route('admin.logs.show', [
|
->get(route('admin.logs.show', [
|
||||||
'file' => '20990101.log',
|
|
||||||
'kind' => 'xxbb',
|
'kind' => 'xxbb',
|
||||||
|
'file' => '20990101.log',
|
||||||
'per_page' => 40,
|
'per_page' => 40,
|
||||||
]))
|
]))
|
||||||
->assertOk();
|
->assertOk();
|
||||||
$html1 = $page1->getContent();
|
$html1 = $page1->getContent();
|
||||||
$this->assertSame(40, substr_count($html1, 'class="json-block"'));
|
$this->assertSame(40, substr_count($html1, 'class="json-block"'));
|
||||||
$this->assertStringContainsString('ENTRY-90', $html1);
|
$this->assertStringContainsString('ENTRY-90', $html1);
|
||||||
|
$this->assertStringContainsString('新版', $html1);
|
||||||
$this->assertStringNotContainsString('ENTRY-50', $html1);
|
$this->assertStringNotContainsString('ENTRY-50', $html1);
|
||||||
$this->assertStringContainsString('更早', $html1);
|
$this->assertStringContainsString('更早', $html1);
|
||||||
|
|
||||||
$page2 = $this->actingAs($admin, 'admin')
|
$page2 = $this->actingAs($admin, 'admin')
|
||||||
->get(route('admin.logs.show', [
|
->get(route('admin.logs.show', [
|
||||||
'file' => '20990101.log',
|
|
||||||
'kind' => 'xxbb',
|
'kind' => 'xxbb',
|
||||||
|
'file' => '20990101.log',
|
||||||
'per_page' => 40,
|
'per_page' => 40,
|
||||||
'page' => 2,
|
'page' => 2,
|
||||||
]))
|
]))
|
||||||
@@ -64,4 +65,44 @@ class RawLogControllerTest extends TestCase
|
|||||||
@unlink($file);
|
@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'));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user