Files
nextcloud-analytics/analyticshub/lib/Controller/PageController.php
2026-02-16 17:18:31 +00:00

88 lines
2.7 KiB
PHP

<?php
declare(strict_types=1);
namespace OCA\AnalyticsHub\Controller;
use OCP\IRequest;
use OCP\IConfig;
use OCP\AppFramework\Http\TemplateResponse;
use OCA\AnalyticsHub\Service\GoogleAnalyticsService;
use OCA\AnalyticsHub\Service\LLMService;
/**
* Admin Settings Controller
*
* @NoAdminRequired
* @NoCSRFRequired
*/
class PageController extends \OCP\AppFramework\Controller {
protected $appName;
protected $config;
protected $gaService;
protected $llmService;
public function __construct(
string $appName,
IRequest $request,
IConfig $config,
GoogleAnalyticsService $gaService,
LLMService $llmService
) {
parent::__construct($appName, $request);
$this->appName = $appName;
$this->config = $config;
$this->gaService = $gaService;
$this->llmService = $llmService;
}
/**
* Index page - render admin UI
*
* @NoAdminRequired
* @NoCSRFRequired
*/
public function index(): TemplateResponse {
// Check configuration status gracefully
$isConfigured = false;
$isGAConfigured = false;
$isLLMConfigured = false;
try {
$isGAConfigured = $this->gaService->isConfigured();
$isLLMConfigured = $this->llmService->isConfigured();
$isConfigured = $isGAConfigured && $isLLMConfigured;
} catch (\Exception $e) {
// If service initialization fails, app is not configured
$isConfigured = false;
}
// Get configuration values (masked for secrets)
$clientId = $this->config->getAppValue('google_client_id', 'analyticshub', '');
$apiKey = $this->config->getAppValue('anthropic_api_key', 'analyticshub', '');
$llmEndpoint = $this->config->getAppValue('llm_api_endpoint', 'analyticshub', '');
$llmModel = $this->config->getAppValue('llm_model', 'analyticshub', '');
// Mask API key for display
$maskedApiKey = '';
if (!empty($apiKey)) {
$maskedApiKey = substr($apiKey, 0, 8) . '...' . substr($apiKey, -4);
}
return new TemplateResponse($this->appName, 'admin', [
'app_name' => $this->appName,
'version' => '1.0.0',
'status' => 'Ready for development',
'is_configured' => $isConfigured,
'is_ga_configured' => $isGAConfigured,
'is_llm_configured' => $isLLMConfigured,
'google_client_id' => $clientId,
'llm_api_endpoint' => $llmEndpoint,
'llm_model' => $llmModel,
'anthropic_api_key_masked' => $maskedApiKey,
'request' => $this->request,
]);
}
}