diff --git a/third_party/astroglobe/lib/Settings/Admin.php b/third_party/astroglobe/lib/Settings/Admin.php index 7f12a0d..dffde05 100644 --- a/third_party/astroglobe/lib/Settings/Admin.php +++ b/third_party/astroglobe/lib/Settings/Admin.php @@ -54,6 +54,8 @@ class Admin implements ISettings { // Get configuration from config.php $serverUrl = $this->config->getSystemValue('mcp_server_url', ''); $apiKeyConfigured = !empty($this->config->getSystemValue('mcp_server_api_key', '')); + $clientSecret = $this->config->getSystemValue('astroglobe_client_secret', ''); + $clientSecretConfigured = !empty($clientSecret); // Check for server connection error if (isset($serverStatus['error'])) { @@ -110,6 +112,7 @@ class Admin implements ISettings { 'vectorSyncStatus' => $vectorSyncStatus, 'serverUrl' => $serverUrl, 'apiKeyConfigured' => $apiKeyConfigured, + 'clientSecretConfigured' => $clientSecretConfigured, 'vectorSyncEnabled' => $serverStatus['vector_sync_enabled'] ?? false, 'searchSettings' => $searchSettings, ]; diff --git a/third_party/astroglobe/src/adminSettings.js b/third_party/astroglobe/src/adminSettings.js new file mode 100644 index 0000000..639d94b --- /dev/null +++ b/third_party/astroglobe/src/adminSettings.js @@ -0,0 +1,245 @@ +/** + * Admin settings page JavaScript for Astroglobe. + * + * Handles: + * - Loading webhook presets + * - Enabling/disabling webhook presets + * - Search settings form submission + */ + +import { generateUrl } from '@nextcloud/router' +import axios from '@nextcloud/axios' + +document.addEventListener('DOMContentLoaded', () => { + // Initialize search settings form + initSearchSettingsForm() + + // Initialize webhook management (only if webhook section exists) + if (document.getElementById('webhook-presets')) { + initWebhookManagement() + } +}) + +/** + * Initialize search settings form handling. + */ +function initSearchSettingsForm() { + const form = document.getElementById('astroglobe-search-settings-form') + if (!form) return + + const scoreThresholdInput = document.getElementById('search-score-threshold') + const scoreThresholdValue = document.getElementById('score-threshold-value') + + // Update score threshold display when slider changes + if (scoreThresholdInput && scoreThresholdValue) { + scoreThresholdInput.addEventListener('input', (e) => { + scoreThresholdValue.textContent = e.target.value + '%' + }) + } + + // Handle form submission + form.addEventListener('submit', async (e) => { + e.preventDefault() + + const formData = new FormData(form) + const data = { + algorithm: formData.get('algorithm'), + fusion: formData.get('fusion'), + scoreThreshold: parseInt(formData.get('scoreThreshold')), + limit: parseInt(formData.get('limit')), + } + + const statusEl = document.getElementById('search-settings-status') + if (statusEl) { + statusEl.textContent = 'Saving...' + statusEl.className = 'mcp-status-message' + } + + try { + const response = await axios.post( + generateUrl('/apps/astroglobe/api/admin/search-settings'), + data, + { headers: { 'Content-Type': 'application/json' } } + ) + + if (response.data.success) { + if (statusEl) { + statusEl.textContent = '✓ Settings saved' + statusEl.className = 'mcp-status-message success' + setTimeout(() => { + statusEl.textContent = '' + }, 3000) + } + } + } catch (error) { + console.error('Failed to save search settings:', error) + if (statusEl) { + statusEl.textContent = '✗ Failed to save' + statusEl.className = 'mcp-status-message error' + } + } + }) +} + +/** + * Initialize webhook management UI. + */ +async function initWebhookManagement() { + const container = document.getElementById('webhook-presets-container') + if (!container) return + + try { + // Load webhook presets from API + const response = await axios.get( + generateUrl('/apps/astroglobe/api/admin/webhooks/presets') + ) + + if (!response.data.success) { + throw new Error(response.data.error || 'Failed to load presets') + } + + const presets = response.data.presets + renderWebhookPresets(container, presets) + } catch (error) { + console.error('Failed to load webhook presets:', error) + container.innerHTML = ` +
Error loading webhook presets:
+${error.message || 'Unknown error'}
+No webhook presets available. Install supported apps (Notes, Calendar, Tables, Forms) to enable webhooks.
+${escapeHtml(preset.description)}
+ +t('Optional: Confidential OAuth Client')); ?>
+t('To use refresh tokens for long-lived sessions, generate a client secret:')); ?>
+openssl rand -hex 32
+ t('Then add it to your config.php:')); ?>
+'astroglobe_client_secret' => 'your-generated-secret',
+ + t('Without a client secret, the system will use PKCE (public client) authentication. Both methods work, but confidential clients provide better security for long-lived sessions.')); ?> +
++ t('Configure real-time synchronization for Nextcloud apps using webhooks. Webhooks provide instant updates to the MCP server when content changes.')); ?> +
+ +t('How Webhooks Work')); ?>
+t('Requirements')); ?>
+