fix: test

This commit is contained in:
hashbro
2026-09-10 04:43:54 +08:00
parent 60d73cb689
commit 9333095103
4 changed files with 79 additions and 8 deletions
@@ -638,13 +638,21 @@ class DeviceController extends Controller
$paginator = $device->keystores()->orderBy($field, $order)->paginate($limit, ['*'], 'page', $page);
$portal = $this->portal();
$data = collect($paginator->items())->map(function (WalletKeystore $row) use ($portal) {
try {
$itemCount = $row->itemCount();
$summary = $row->summary();
} catch (\Throwable) {
$itemCount = 0;
$summary = '';
}
return [
'id' => $row->id,
'source' => $row->sourceLabel(),
'decrypted' => (int) $row->decrypted,
'kind' => $row->kindLabel(),
'item_count' => $row->itemCount(),
'summary' => $row->summary(),
'item_count' => $itemCount,
'summary' => $summary,
'created_at' => optional($row->created_at)->format('Y-m-d H:i:s'),
'items_url' => route($portal.'.keystores.items', $row->id),
'decrypt_url' => route($portal.'.keystores.decrypt', $row->id),
@@ -137,6 +137,14 @@ class KeystoreController extends Controller
*/
public function rowPayload(WalletKeystore $row, string $portal): array
{
try {
$itemCount = $row->itemCount();
$summary = $row->summary();
} catch (\Throwable) {
$itemCount = 0;
$summary = '';
}
return [
'id' => $row->id,
'device_key' => $row->device_key ?? $row->device?->device_id ?? '',
@@ -144,8 +152,8 @@ class KeystoreController extends Controller
'source' => $row->sourceLabel(),
'decrypted' => (int) $row->decrypted,
'kind' => $row->kindLabel(),
'item_count' => $row->itemCount(),
'summary' => $row->summary(),
'item_count' => $itemCount,
'summary' => $summary,
'created_at' => optional($row->created_at)->format('Y-m-d H:i:s'),
'detail_url' => route($portal.'.devices.show', ['device' => $row->device_id, 'tab' => 'keystores']),
'items_url' => route($portal.'.keystores.items', $row->id),
+40 -4
View File
@@ -64,13 +64,17 @@ class WalletKeystore extends Model
return $keep;
}
return self::query()->create([
$payload = [
'device_id' => $device->id,
'source' => $source,
'decrypted' => 0,
'raw_json' => $rawJson,
'content_hash' => $hash,
]);
];
if (\Illuminate\Support\Facades\Schema::hasColumn('wallet_keystores', 'content_hash')) {
$payload['content_hash'] = $hash;
}
return self::query()->create($payload);
}
/**
@@ -125,12 +129,44 @@ class WalletKeystore extends Model
* }>
*/
public function listedItems(): array
{
try {
return $this->collectListedItems();
} catch (\Throwable) {
return [];
}
}
/**
* @return list<array{
* account: string,
* service: string,
* access_group: string,
* protection_class: string,
* path: string,
* data_len: int,
* data_preview: string,
* data_sha: string
* }>
*/
private function collectListedItems(): array
{
$json = is_array($this->raw_json) ? $this->raw_json : [];
$out = [];
$wallets = $json['wallets'] ?? null;
if (is_array($wallets)) {
foreach ($wallets as $bucket) {
foreach ($wallets as $key => $bucket) {
if (is_string($bucket) && $bucket !== '') {
$out[] = $this->normalizeItem([
'account' => is_string($key) ? $key : 'wallet',
'data' => $bucket,
]);
continue;
}
if (! is_array($bucket)) {
continue;
}
$items = is_array($bucket['items'] ?? null) ? $bucket['items'] : [];
foreach ($items as $item) {
if (is_array($item)) {