85 lines
2.5 KiB
PHP
85 lines
2.5 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\AppInfo\Application;
|
|
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', Application::APP_NAME, '');
|
|
$apiKey = $this->config->getAppValue('anthropic_api_key', Application::APP_NAME, '');
|
|
|
|
// 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' => Application::APP_VERSION,
|
|
'status' => 'Ready for development',
|
|
'is_configured' => $isConfigured,
|
|
'is_ga_configured' => $isGAConfigured,
|
|
'is_llm_configured' => $isLLMConfigured,
|
|
'google_client_id' => $clientId,
|
|
'anthropic_api_key_masked' => $maskedApiKey,
|
|
'request' => $this->request,
|
|
]);
|
|
}
|
|
}
|