adasd
This commit is contained in:
@@ -681,6 +681,11 @@ class ApiKernel
|
||||
$this->fail('Send failed', null, 500);
|
||||
}
|
||||
|
||||
$customerId = (int)($auth['customer_id'] ?? 0);
|
||||
if ($customerId > 0) {
|
||||
$this->incrementTemplateUsage($customerId, $templateId);
|
||||
}
|
||||
|
||||
$this->respond([
|
||||
'ok' => true,
|
||||
'template_id' => $templateId,
|
||||
@@ -820,6 +825,12 @@ class ApiKernel
|
||||
case 'account.senders.delete':
|
||||
$this->handleAccountSenderDelete();
|
||||
break;
|
||||
case 'dashboard.metrics':
|
||||
$this->handleDashboardMetrics();
|
||||
break;
|
||||
case 'dashboard.reset_usage':
|
||||
$this->handleDashboardResetUsage();
|
||||
break;
|
||||
case 'downloads.bridge':
|
||||
$this->handleDownloadFile('bridge');
|
||||
break;
|
||||
@@ -1584,6 +1595,36 @@ class ApiKernel
|
||||
$this->respond(['ok' => true, 'deleted' => true]);
|
||||
}
|
||||
|
||||
private function handleDashboardMetrics(): void
|
||||
{
|
||||
$user = $this->authService->requireAuth();
|
||||
$this->ensureRole($user, ['owner', 'admin']);
|
||||
$customerId = (int)($user['customer_id'] ?? 0);
|
||||
if ($customerId <= 0) $this->fail('Customer context missing', null, 500);
|
||||
$counts = $this->fetchResourceCounts($customerId);
|
||||
$usage = $this->listTemplateUsage($customerId);
|
||||
$this->respond([
|
||||
'ok' => true,
|
||||
'counts' => $counts,
|
||||
'usage' => $usage,
|
||||
]);
|
||||
}
|
||||
|
||||
private function handleDashboardResetUsage(): void
|
||||
{
|
||||
$user = $this->authService->requireAuth();
|
||||
$this->ensureRole($user, ['owner', 'admin']);
|
||||
$customerId = (int)($user['customer_id'] ?? 0);
|
||||
if ($customerId <= 0) $this->fail('Customer context missing', null, 500);
|
||||
$raw = $this->in['template_id'] ?? $this->in['templates'] ?? null;
|
||||
$ids = $this->extractIdList($raw);
|
||||
if (!$ids) {
|
||||
$this->fail('template_id required', null, 422);
|
||||
}
|
||||
$this->resetTemplateUsage($customerId, $ids);
|
||||
$this->respond(['ok' => true]);
|
||||
}
|
||||
|
||||
private function handleDownloadFile(string $type): void
|
||||
{
|
||||
$user = $this->authService->requireAuth();
|
||||
@@ -1637,15 +1678,20 @@ class ApiKernel
|
||||
if ($bridgeUrl === '' || $bridgeToken === '') {
|
||||
$this->fail('Bridge nicht konfiguriert', null, 422);
|
||||
}
|
||||
$settings = $this->getCustomerSettings($customerId);
|
||||
try {
|
||||
$schema = $this->fetchPlaceholderSchema($bridgeUrl, $bridgeToken, 0);
|
||||
} catch (Throwable $e) {
|
||||
$this->fail('Bridge request failed', $e->getMessage(), 502);
|
||||
return;
|
||||
}
|
||||
$tables = $schema['tables'] ?? [];
|
||||
if (!empty($settings['bridge_tables'])) {
|
||||
$tables = $this->filterSchemaTables($tables, $settings['bridge_tables']);
|
||||
}
|
||||
$this->respond([
|
||||
'ok' => true,
|
||||
'tables' => $schema['tables'] ?? [],
|
||||
'tables' => $tables,
|
||||
'fetched' => $schema['fetched'] ?? date(DATE_ATOM),
|
||||
]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user