appName = $appName; $this->request = $request; $this->config = $config; } /** * Load configuration */ public function load(): JSONResponse { $clientId = $this->config->getAppValue('google_client_id', 'analyticshub', ''); $apiKey = $this->config->getAppValue('anthropic_api_key', 'analyticshub', ''); $llmEndpoint = $this->config->getAppValue('llm_api_endpoint', 'analyticshub', ''); $refreshToken = $this->config->getAppValue('google_refresh_token', 'analyticshub', ''); // 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, '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'] ?? ''; if (empty($clientId) || empty($clientSecret) || empty($apiKey)) { return new JSONResponse([ 'success' => false, 'error' => 'Missing required fields', ], 400); } // Save configuration $this->config->setAppValue('google_client_id', 'analyticshub', $clientId); $this->config->setAppValue('google_client_secret', 'analyticshub', $clientSecret); if (!empty($refreshToken)) { $this->config->setAppValue('google_refresh_token', 'analyticshub', $refreshToken); } if (!empty($llmEndpoint)) { $this->config->setAppValue('llm_api_endpoint', 'analyticshub', $llmEndpoint); } $this->config->setAppValue('anthropic_api_key', 'analyticshub', $apiKey); // Check if fully configured $isConfigured = !empty($clientId) && !empty($clientSecret) && !empty($apiKey) && !empty($refreshToken); return new JSONResponse([ 'success' => true, 'data' => [ 'is_configured' => $isConfigured, ], ]); } }