Files
WLTBAgent 49b6b37277 Fixes: Simplify PageController, fix config API, update deployment package (2026-02-17)
- Removed service dependencies from PageController constructor
- Fixed AdminController config API signatures
- Cleaned up Application.php resource loading
- Updated template with proper resource includes
- Simplified routes.php
- Reduced analyticshub.zip from 50KB to 27KB
- Status: Fixed and ready for redeployment
2026-02-22 06:56:57 +00:00

124 lines
3.8 KiB
PHP

<?php
declare(strict_types=1);
namespace OCA\AnalyticsHub\Controller;
use OCP\IRequest;
use OCP\IConfig;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Http\JSONResponse;
/**
* Admin Settings Controller
*
* @NoAdminRequired
* @NoCSRFRequired
*/
class AdminController {
protected $appName;
protected $request;
protected $config;
public function __construct(string $appName, IRequest $request, IConfig $config) {
$this->appName = $appName;
$this->request = $request;
$this->config = $config;
}
/**
* Load configuration
*/
public function load(): JSONResponse {
$clientId = $this->config->getAppValue('analyticshub', 'google_client_id', '');
$apiKey = $this->config->getAppValue('analyticshub', 'anthropic_api_key', '');
$llmEndpoint = $this->config->getAppValue('analyticshub', 'llm_api_endpoint', '');
$llmModel = $this->config->getAppValue('analyticshub', 'llm_model', '');
$refreshToken = $this->config->getAppValue('analyticshub', 'google_refresh_token', '');
// Check if configured
$isConfigured = !empty($clientId) && !empty($apiKey) && !empty($refreshToken);
// Mask sensitive values for display
$maskedApiKey = '';
if (!empty($apiKey)) {
$maskedApiKey = substr($apiKey, 0, 8) . '...' . substr($apiKey, -4);
}
$maskedRefreshToken = '';
if (!empty($refreshToken)) {
$maskedRefreshToken = substr($refreshToken, 0, 10) . '...';
}
return new JSONResponse([
'success' => true,
'data' => [
'google_client_id' => $clientId,
'google_refresh_token' => $maskedRefreshToken,
'llm_api_endpoint' => $llmEndpoint,
'llm_model' => $llmModel,
'anthropic_api_key' => $maskedApiKey,
'is_configured' => $isConfigured,
],
]);
}
/**
* Save configuration
*/
public function save(): JSONResponse {
$data = json_decode($this->request->getRawBody(), true);
if (!$data) {
return new JSONResponse([
'success' => false,
'error' => 'Invalid request body',
], 400);
}
$clientId = $data['google_client_id'] ?? '';
$clientSecret = $data['google_client_secret'] ?? '';
$refreshToken = $data['google_refresh_token'] ?? '';
$apiKey = $data['anthropic_api_key'] ?? '';
$llmEndpoint = $data['llm_api_endpoint'] ?? '';
$llmModel = $data['llm_model'] ?? '';
if (empty($clientId) || empty($clientSecret) || empty($apiKey)) {
return new JSONResponse([
'success' => false,
'error' => 'Missing required fields',
], 400);
}
// Save configuration
$this->config->setAppValue('analyticshub', 'google_client_id', $clientId);
$this->config->setAppValue('analyticshub', 'google_client_secret', $clientSecret);
if (!empty($refreshToken)) {
$this->config->setAppValue('analyticshub', 'google_refresh_token', $refreshToken);
}
if (!empty($llmEndpoint)) {
$this->config->setAppValue('analyticshub', 'llm_api_endpoint', $llmEndpoint);
}
if (!empty($llmModel)) {
$this->config->setAppValue('analyticshub', 'llm_model', $llmModel);
}
$this->config->setAppValue('analyticshub', 'anthropic_api_key', $apiKey);
// Check if fully configured
$isConfigured = !empty($clientId) && !empty($clientSecret) && !empty($apiKey) && !empty($refreshToken);
return new JSONResponse([
'success' => true,
'data' => [
'is_configured' => $isConfigured,
],
]);
}
}