Rework MCP access settings and preserve unsaved permissions
This commit is contained in:
1 parent
b456109c2d
commit
eede2cb608
4 files changed
+231
-61
No files matched your search
+7
-1
@@ -7387,7 +7387,13 @@ function syncSettingsSaveState(message) {
|
|||||||
button.classList.toggle('btn-success', settingsDirty && !settingsSaving);
|
button.classList.toggle('btn-success', settingsDirty && !settingsSaving);
|
||||||
button.classList.toggle('btn-secondary', !settingsDirty || settingsSaving);
|
button.classList.toggle('btn-secondary', !settingsDirty || settingsSaving);
|
||||||
}
|
}
|
||||||
if (feedback && message) feedback.textContent = message;
|
if (feedback) {
|
||||||
|
if (message) feedback.dataset.settingsMessage = message;
|
||||||
|
const mcp = window.getMcpSettingsSaveState?.();
|
||||||
|
feedback.textContent = mcp?.saving ? 'MCP-Einstellungen werden gespeichert…'
|
||||||
|
: mcp?.dirty ? 'MCP-Änderungen noch nicht gespeichert'
|
||||||
|
: feedback.dataset.settingsMessage || 'Keine ungespeicherten Änderungen';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function establishSettingsBaseline(message = 'Keine ungespeicherten Änderungen') {
|
function establishSettingsBaseline(message = 'Keine ungespeicherten Änderungen') {
|
||||||
|
|||||||
@@ -5,6 +5,38 @@
|
|||||||
})(typeof window !== 'undefined' ? window : globalThis, function () {
|
})(typeof window !== 'undefined' ? window : globalThis, function () {
|
||||||
const pairs = [
|
const pairs = [
|
||||||
['MCP-Fernzugriff', 'MCP remote access'],
|
['MCP-Fernzugriff', 'MCP remote access'],
|
||||||
|
['MCP-Einstellungen werden gespeichert…', 'Saving MCP settings…'],
|
||||||
|
['MCP-Änderungen noch nicht gespeichert', 'MCP changes have not been saved yet'],
|
||||||
|
['Wird gespeichert…', 'Saving…'],
|
||||||
|
['Änderungen speichern', 'Save changes'],
|
||||||
|
['Änderungen werden übernommen.', 'Applying changes.'],
|
||||||
|
['Änderungen noch nicht gespeichert.', 'Changes have not been saved yet.'],
|
||||||
|
['Alle Einstellungen gespeichert.', 'All settings saved.'],
|
||||||
|
['Erst speichern und aktivieren, dann den Verbindungscode kopieren.', 'Save and enable first, then copy the connection code.'],
|
||||||
|
['Fernzugriff ist ausgeschaltet. Berechtigungen auswählen und mit „Speichern und aktivieren“ übernehmen.', 'Remote access is off. Select permissions and choose “Save and enable”.'],
|
||||||
|
['Fernzugriff ist aktiv. Den Verbindungscode im MCP-Client hinterlegen.', 'Remote access is enabled. Add the connection code to your MCP client.'],
|
||||||
|
['Einstellungen gespeichert. Die Verbindung wird hergestellt.', 'Settings saved. Establishing the connection.'],
|
||||||
|
['Einstellungen gespeichert. Die Verbindung wird automatisch erneut versucht.', 'Settings saved. The connection will be retried automatically.'],
|
||||||
|
['Der Zugang wurde abgelehnt. Zugang erneuern und den neuen Code im Client hinterlegen.', 'Access was rejected. Rotate access and add the new code to the client.'],
|
||||||
|
['Die gespeicherten Zugangsdaten sind nicht lesbar. Lokalen Zugangsdaten-Speicher prüfen.', 'The saved credentials cannot be read. Check local credential storage.'],
|
||||||
|
['Die Registrierung ist fehlgeschlagen. Verbindung prüfen und erneut aktivieren.', 'Registration failed. Check the connection and enable access again.'],
|
||||||
|
['Status nicht verfügbar', 'Status unavailable'],
|
||||||
|
['Der Verbindungsstatus wird geladen.', 'Loading the connection status.'],
|
||||||
|
['Verbindung', 'Connection'],
|
||||||
|
['Den Code auf diesem Gerät kopieren und im MCP-Client hinterlegen. Er gilt nur für diese Installation.', 'Copy the code on this device and add it to your MCP client. It applies only to this installation.'],
|
||||||
|
['Einrichtung und Berechtigungen', 'Setup and permissions'],
|
||||||
|
['Name und Berechtigungen auswählen. Änderungen werden erst mit dem Speichern wirksam.', 'Choose a name and permissions. Changes take effect only when saved.'],
|
||||||
|
['Status, Uploads, Protokolle und Diagnose lesen.', 'Read status, uploads, logs and diagnostics.'],
|
||||||
|
['Uploads und Konten verwalten. Kritische Aktionen lokal bestätigen.', 'Manage uploads and accounts. Confirm critical actions locally.'],
|
||||||
|
['Auf ausgewählte Ordner zugreifen. Dateiinhalte separat freigeben.', 'Access selected directories. Allow file contents separately.'],
|
||||||
|
['App-Updates installieren', 'Install app updates'],
|
||||||
|
['Geprüfte Updates ohne erneute Bestätigung installieren. Uploads abschließen und danach fortsetzen. Keine Portable-Versionen.', 'Install verified updates without another confirmation. Finish uploads and resume afterwards. No portable versions.'],
|
||||||
|
['Zugangsdaten auslesen', 'Reveal credentials'],
|
||||||
|
['Gespeicherte Zugangsdaten ausdrücklich freigeben. Zusätzliche lokale Bestätigung erforderlich.', 'Explicitly allow saved credentials to be read. Additional local confirmation required.'],
|
||||||
|
['Ordnerfreigaben', 'Directory access'],
|
||||||
|
['Keine Ordner freigegeben.', 'No directories granted.'],
|
||||||
|
['Zugang verwalten', 'Manage access'],
|
||||||
|
['Zugang erneuern macht den bisherigen Code ungültig. Deaktivieren beendet den Fernzugriff und widerruft den Zugang.', 'Rotating access invalidates the previous code. Disabling remote access revokes access.'],
|
||||||
['Offizielle App-Updates ohne erneute Bestätigung erlauben', 'Allow official app updates without another confirmation'],
|
['Offizielle App-Updates ohne erneute Bestätigung erlauben', 'Allow official app updates without another confirmation'],
|
||||||
['Standardmäßig aus. Gilt nur für geprüfte Installer einer exakt angeforderten Version. Laufende Uploads werden abgeschlossen und die Warteschlange nach dem Neustart wieder aufgenommen. Portable-Versionen werden nicht unterstützt.', 'Disabled by default. Limited to verified installers of the exact requested version. Running uploads finish and the queue resumes after restart. Portable versions are not supported.'],
|
['Standardmäßig aus. Gilt nur für geprüfte Installer einer exakt angeforderten Version. Laufende Uploads werden abgeschlossen und die Warteschlange nach dem Neustart wieder aufgenommen. Portable-Versionen werden nicht unterstützt.', 'Disabled by default. Limited to verified installers of the exact requested version. Running uploads finish and the queue resumes after restart. Portable versions are not supported.'],
|
||||||
['MCP-Update wird vorbereitet', 'MCP update is being prepared'],
|
['MCP-Update wird vorbereitet', 'MCP update is being prepared'],
|
||||||
|
|||||||
+58
-16
@@ -1,16 +1,58 @@
|
|||||||
.mcp-controls { margin-bottom: 28px; font-size: 13px; }
|
.mcp-controls { display: grid; gap: 18px; margin-bottom: 28px; font-size: 13px; container-type: inline-size; }
|
||||||
.mcp-controls p { line-height: 1.6; overflow-wrap: anywhere; }
|
.mcp-controls p { margin: 0; line-height: 1.6; color: var(--text-muted); overflow-wrap: anywhere; }
|
||||||
.mcp-controls .settings-row input { min-width: 0; flex: 1; }
|
.mcp-card { min-width: 0; padding: 20px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg-card); }
|
||||||
.mcp-permissions { display: flex; flex-wrap: wrap; gap: 16px 24px; border: 1px solid var(--border, #424242); border-radius: 6px; padding: 16px; margin: 16px 0; }
|
.mcp-card-heading { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px; margin-bottom: 10px; }
|
||||||
.mcp-permissions label, .mcp-grant label { display: flex; align-items: center; gap: 6px; }
|
.mcp-card h4 { margin: 0; font-size: 16px; font-weight: 650; line-height: 1.4; }
|
||||||
.mcp-actions { display: flex; gap: 8px; flex-wrap: wrap; margin: 14px 0; }
|
.mcp-state { display: inline-flex; align-items: center; gap: 8px; max-width: 100%; padding: 6px 10px; border: 1px solid var(--border); border-radius: 6px; background: var(--bg-raised); font-size: 12px; font-weight: 650; line-height: 1.4; overflow-wrap: anywhere; }
|
||||||
.mcp-actions .btn { white-space: normal; }
|
.mcp-state::before { content: ''; flex: 0 0 7px; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
|
||||||
.mcp-status { display: flex; flex-wrap: wrap; gap: 18px 32px; border: 1px solid var(--border, #424242); border-radius: 6px; padding: 16px; }
|
.mcp-state[data-state="online"] { color: var(--success); border-color: color-mix(in srgb, var(--success) 45%, var(--border)); background: color-mix(in srgb, var(--success) 8%, var(--bg-card)); }
|
||||||
.mcp-status dt { margin-bottom: 8px; }
|
.mcp-state:is([data-state="offline"], [data-state="connecting"]) { color: var(--warning); }
|
||||||
.mcp-status dd { margin: 0; font-weight: 600; }
|
.mcp-state:is([data-state="blocked"], [data-state="storage-error"], [data-state="enrollment-error"]) { color: var(--danger); }
|
||||||
.mcp-state { padding: 5px 8px; border: 1px solid var(--border, #555); border-radius: 5px; }
|
.mcp-status { display: grid; grid-template-columns: minmax(0, 1.5fr) repeat(2, minmax(0, 1fr)); gap: 16px; margin: 18px 0; padding: 16px 0; border-block: 1px solid var(--border); }
|
||||||
.mcp-state.connected { color: #a2edc1; background: #193829; border-color: #46735b; }
|
.mcp-status > div { min-width: 0; }
|
||||||
.mcp-grant { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--border, #424242); }
|
.mcp-status dt { margin-bottom: 6px; font-size: 12px; color: var(--text-muted); }
|
||||||
.mcp-grant > span { flex: 1 1 220px; overflow-wrap: anywhere; }
|
.mcp-status dd { margin: 0; font-size: 14px; font-weight: 650; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
|
||||||
.mcp-update-permission { display: flex; align-items: flex-start; gap: 8px; margin-top: 20px; font-size: 13px; line-height: 1.6; }
|
.mcp-code-row, .mcp-save-row { display: flex; align-items: center; gap: 16px; justify-content: space-between; }
|
||||||
.mcp-update-permission input { flex: 0 0 auto; margin-top: 4px; }
|
.mcp-code-row p { flex: 1 1 260px; }
|
||||||
|
.mcp-controls .btn { min-height: 36px; max-width: 100%; flex-shrink: 0; font-size: 13px; white-space: normal; line-height: 1.4; }
|
||||||
|
.mcp-name-row { display: grid; grid-template-columns: minmax(130px, 0.6fr) minmax(0, 1fr); align-items: center; gap: 12px; margin: 20px 0; }
|
||||||
|
.mcp-name-row label { font-size: 14px; font-weight: 600; }
|
||||||
|
.mcp-name-row input { min-width: 0; width: 100%; }
|
||||||
|
.mcp-permissions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; padding: 0; margin: 0; min-width: 0; border: 0; }
|
||||||
|
.mcp-permissions legend { margin-bottom: 10px; padding: 0; font-size: 13px; font-weight: 600; }
|
||||||
|
.mcp-permission { display: flex; align-items: flex-start; gap: 10px; min-width: 0; padding: 13px; border: 1px solid var(--border); border-radius: 6px; background: var(--bg-input); cursor: pointer; }
|
||||||
|
.mcp-permission:has(input:checked) { border-color: color-mix(in srgb, var(--accent) 60%, var(--border)); background: color-mix(in srgb, var(--accent) 6%, var(--bg-input)); }
|
||||||
|
.mcp-permission:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
|
||||||
|
.mcp-permission > span { min-width: 0; }
|
||||||
|
.mcp-permission strong { display: block; font-size: 14px; font-weight: 600; line-height: 1.45; }
|
||||||
|
.mcp-permission-description { display: block; margin-top: 5px; color: var(--text-muted); font-size: 12px; line-height: 1.55; overflow-wrap: anywhere; }
|
||||||
|
.mcp-permission-sensitive { grid-column: 1 / -1; }
|
||||||
|
.mcp-controls input[type="checkbox"] { width: 16px; height: 16px; margin: 3px 0 0; flex: 0 0 auto; accent-color: var(--accent); }
|
||||||
|
.mcp-save-row { margin-top: 18px; padding-top: 18px; border-top: 1px solid var(--border); }
|
||||||
|
.mcp-save-row p { font-size: 12px; }
|
||||||
|
.mcp-save-row p.pending { color: var(--warning); }
|
||||||
|
.mcp-grant { min-width: 0; margin-top: 14px; padding: 14px; background: var(--bg-input); border: 1px solid var(--border); border-radius: 6px; }
|
||||||
|
#mcpControls .mcp-grant-path { color: var(--text); font-size: 13px; font-weight: 600; overflow-wrap: anywhere; user-select: text; }
|
||||||
|
.mcp-grant-options { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 20px; margin-top: 12px; }
|
||||||
|
.mcp-grant label { display: flex; align-items: flex-start; gap: 7px; font-size: 12px; line-height: 1.5; cursor: pointer; }
|
||||||
|
.mcp-grant-options .btn { margin-left: auto; }
|
||||||
|
.mcp-controls .mcp-empty { margin-top: 14px; padding: 18px; border: 1px dashed var(--border); border-radius: 6px; text-align: center; }
|
||||||
|
.mcp-empty[hidden] { display: none; }
|
||||||
|
.mcp-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 16px; }
|
||||||
|
.mcp-card > p + p { margin-top: 10px; }
|
||||||
|
.mcp-controls .mcp-footnote { padding: 0 2px; font-size: 12px; }
|
||||||
|
@container (max-width: 550px) {
|
||||||
|
.mcp-card { padding: 16px; }
|
||||||
|
.mcp-status { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
|
||||||
|
.mcp-status > div:first-child { grid-column: 1 / -1; }
|
||||||
|
.mcp-code-row, .mcp-save-row { align-items: stretch; flex-direction: column; gap: 12px; }
|
||||||
|
.mcp-code-row p { flex: auto; }
|
||||||
|
.mcp-permissions { grid-template-columns: minmax(0, 1fr); }
|
||||||
|
.mcp-permission-sensitive { grid-column: auto; }
|
||||||
|
}
|
||||||
|
@container (max-width: 360px) {
|
||||||
|
.mcp-name-row { grid-template-columns: minmax(0, 1fr); gap: 8px; }
|
||||||
|
.mcp-card-heading { align-items: flex-start; flex-direction: column; }
|
||||||
|
.mcp-grant-options { align-items: flex-start; flex-direction: column; }
|
||||||
|
.mcp-grant-options .btn { margin-left: 0; }
|
||||||
|
}
|
||||||
+134
-44
@@ -96,64 +96,154 @@
|
|||||||
finally { cancelled.delete(request.id); }
|
finally { cancelled.delete(request.id); }
|
||||||
});
|
});
|
||||||
let current = null;
|
let current = null;
|
||||||
const renderStatus = state => {
|
let busy = false;
|
||||||
current = state;
|
let saving = false;
|
||||||
|
const configuration = area => ({
|
||||||
|
enabled: true,
|
||||||
|
name: area.querySelector('#mcpName').value.trim(),
|
||||||
|
capabilities: [...area.querySelectorAll('.mcp-permissions input:checked')].map(input => input.value)
|
||||||
|
});
|
||||||
|
const hasChanges = (area, state) => {
|
||||||
|
if (!state) return false;
|
||||||
|
const draft = configuration(area);
|
||||||
|
return draft.name !== (state.name || 'Multi-Hoster-Uploader')
|
||||||
|
|| draft.capabilities.slice().sort().join('|') !== (state.capabilities || []).slice().sort().join('|');
|
||||||
|
};
|
||||||
|
const syncConfiguration = (area, state) => {
|
||||||
|
area.querySelector('#mcpName').value = state.name || 'Multi-Hoster-Uploader';
|
||||||
|
for (const input of area.querySelectorAll('.mcp-permissions input')) input.checked = state.capabilities?.includes(input.value) === true;
|
||||||
|
};
|
||||||
|
window.getMcpSettingsSaveState = () => {
|
||||||
|
const area = document.getElementById('mcpControls');
|
||||||
|
return { dirty: !!area && hasChanges(area, current), saving };
|
||||||
|
};
|
||||||
|
const refreshControls = () => {
|
||||||
const area = document.getElementById('mcpControls');
|
const area = document.getElementById('mcpControls');
|
||||||
if (!area) return;
|
if (!area) return;
|
||||||
|
const ready = current?.available !== false && current?.connection !== 'starting' && !!current;
|
||||||
|
const dirty = hasChanges(area, current);
|
||||||
|
area.setAttribute('aria-busy', String(busy));
|
||||||
|
for (const input of area.querySelectorAll('input')) input.disabled = busy || !ready;
|
||||||
|
const enable = area.querySelector('[data-mcp-action="enable"]');
|
||||||
|
enable.disabled = busy || !ready || (current?.enabled && !dirty && ['online', 'connecting'].includes(current.connection));
|
||||||
|
enable.textContent = saving ? text('Wird gespeichert…', 'Saving…') : current?.enabled ? text('Änderungen speichern', 'Save changes') : text('Speichern und aktivieren', 'Save and enable');
|
||||||
|
area.querySelector('[data-mcp-save-state]').textContent = saving ? text('Änderungen werden übernommen.', 'Applying changes.')
|
||||||
|
: dirty ? text('Änderungen noch nicht gespeichert.', 'Changes have not been saved yet.')
|
||||||
|
: current?.enabled ? text('Alle Einstellungen gespeichert.', 'All settings saved.')
|
||||||
|
: text('Erst speichern und aktivieren, dann den Verbindungscode kopieren.', 'Save and enable first, then copy the connection code.');
|
||||||
|
area.querySelector('[data-mcp-save-state]').classList.toggle('pending', dirty);
|
||||||
|
area.querySelector('[data-mcp-action="copy"]').disabled = busy || !current?.enabled || !current?.installationId;
|
||||||
|
area.querySelector('[data-mcp-action="rotate"]').disabled = busy || !current?.enabled;
|
||||||
|
area.querySelector('[data-mcp-action="disable"]').disabled = busy || (!current?.enabled && !current?.installationId);
|
||||||
|
area.querySelector('[data-mcp-action="grant"]').disabled = busy || !ready;
|
||||||
|
for (const button of area.querySelectorAll('.mcp-grant button')) button.disabled = busy || !ready;
|
||||||
|
window.syncSettingsSaveState?.();
|
||||||
|
};
|
||||||
|
const renderStatus = (state, resetDraft = false) => {
|
||||||
|
const area = document.getElementById('mcpControls');
|
||||||
|
if (!area) { current = state; return; }
|
||||||
|
const preserveDraft = !resetDraft && hasChanges(area, current);
|
||||||
|
current = state;
|
||||||
|
if (!preserveDraft) syncConfiguration(area, state);
|
||||||
const states = {
|
const states = {
|
||||||
disabled: text('Deaktiviert', 'Disabled'), connecting: text('Verbindung wird hergestellt', 'Connecting'), online: text('Verbunden', 'Connected'), offline: text('Nicht verbunden – erneuter Versuch', 'Offline – retrying'),
|
disabled: text('Deaktiviert', 'Disabled'), connecting: text('Verbindung wird hergestellt', 'Connecting'), online: text('Verbunden', 'Connected'), offline: text('Nicht verbunden – erneuter Versuch', 'Offline – retrying'),
|
||||||
blocked: text('Zugang abgelehnt', 'Access rejected'), 'storage-error': text('Zugangsdaten nicht lesbar', 'Credentials unavailable'), 'enrollment-error': text('Registrierung fehlgeschlagen', 'Enrollment failed'), starting: text('Wird geladen', 'Loading')
|
blocked: text('Zugang abgelehnt', 'Access rejected'), 'storage-error': text('Zugangsdaten nicht lesbar', 'Credentials unavailable'), 'enrollment-error': text('Registrierung fehlgeschlagen', 'Enrollment failed'), starting: text('Wird geladen', 'Loading')
|
||||||
};
|
};
|
||||||
area.querySelector('[data-mcp-status]').textContent = states[state.connection] || state.connection;
|
const descriptions = {
|
||||||
area.querySelector('[data-mcp-status]').className = `mcp-state ${state.connection === 'online' ? 'connected' : ''}`;
|
disabled: text('Fernzugriff ist ausgeschaltet. Berechtigungen auswählen und mit „Speichern und aktivieren“ übernehmen.', 'Remote access is off. Select permissions and choose “Save and enable”.'),
|
||||||
|
online: text('Fernzugriff ist aktiv. Den Verbindungscode im MCP-Client hinterlegen.', 'Remote access is enabled. Add the connection code to your MCP client.'),
|
||||||
|
connecting: text('Einstellungen gespeichert. Die Verbindung wird hergestellt.', 'Settings saved. Establishing the connection.'),
|
||||||
|
offline: text('Einstellungen gespeichert. Die Verbindung wird automatisch erneut versucht.', 'Settings saved. The connection will be retried automatically.'),
|
||||||
|
blocked: text('Der Zugang wurde abgelehnt. Zugang erneuern und den neuen Code im Client hinterlegen.', 'Access was rejected. Rotate access and add the new code to the client.'),
|
||||||
|
'storage-error': text('Die gespeicherten Zugangsdaten sind nicht lesbar. Lokalen Zugangsdaten-Speicher prüfen.', 'The saved credentials cannot be read. Check local credential storage.'),
|
||||||
|
'enrollment-error': text('Die Registrierung ist fehlgeschlagen. Verbindung prüfen und erneut aktivieren.', 'Registration failed. Check the connection and enable access again.')
|
||||||
|
};
|
||||||
|
const status = area.querySelector('[data-mcp-status]');
|
||||||
|
status.textContent = states[state.connection] || text('Status nicht verfügbar', 'Status unavailable');
|
||||||
|
status.dataset.state = state.connection || 'starting';
|
||||||
|
area.querySelector('[data-mcp-summary]').textContent = descriptions[state.connection] || text('Der Verbindungsstatus wird geladen.', 'Loading the connection status.');
|
||||||
area.querySelector('[data-mcp-contact]').textContent = state.lastContact ? new Date(state.lastContact).toLocaleString(getUiLocale()) : '—';
|
area.querySelector('[data-mcp-contact]').textContent = state.lastContact ? new Date(state.lastContact).toLocaleString(getUiLocale()) : '—';
|
||||||
area.querySelector('[data-mcp-pending]').textContent = Number(state.pendingRevocations || 0).toLocaleString(getUiLocale());
|
area.querySelector('[data-mcp-pending]').textContent = Number(state.pendingRevocations || 0).toLocaleString(getUiLocale());
|
||||||
for (const action of ['copy', 'rotate']) area.querySelector(`[data-mcp-action="${action}"]`).disabled = !state.enabled;
|
area.querySelector('[data-mcp-grant-count]').textContent = Number(state.grants?.length || 0).toLocaleString(getUiLocale());
|
||||||
area.querySelector('[data-mcp-action="disable"]').disabled = !state.enabled && !state.installationId;
|
const grants = area.querySelector('[data-mcp-grants]');
|
||||||
area.querySelector('[data-mcp-grants]').replaceChildren(...(state.grants || []).map(grant => {
|
const grantIds = JSON.stringify(state.grants || []);
|
||||||
const row = document.createElement('div'); row.className = 'mcp-grant';
|
if (grants.dataset.snapshot !== grantIds) {
|
||||||
const name = document.createElement('span'); name.textContent = grant.path;
|
grants.dataset.snapshot = grantIds;
|
||||||
const label = document.createElement('label'); const checkbox = document.createElement('input'); checkbox.type = 'checkbox'; checkbox.checked = !grant.readOnly;
|
grants.replaceChildren(...(state.grants || []).map(grant => {
|
||||||
label.append(checkbox, text(' Schreibzugriff', ' Write access'));
|
const row = document.createElement('div'); row.className = 'mcp-grant';
|
||||||
checkbox.onchange = () => act(() => window.api.mcpUpdateGrant({ id: grant.id, remove: false, readOnly: !checkbox.checked, allowTransfer: grant.allowTransfer === true }));
|
const name = document.createElement('p'); name.className = 'mcp-grant-path'; name.textContent = grant.path;
|
||||||
const transferLabel = document.createElement('label'); const transfer = document.createElement('input'); transfer.type = 'checkbox'; transfer.checked = grant.allowTransfer === true;
|
const options = document.createElement('div'); options.className = 'mcp-grant-options';
|
||||||
transferLabel.append(transfer, text(' Dateiinhalte übertragen', ' Transfer file contents'));
|
const label = document.createElement('label'); const checkbox = document.createElement('input'); checkbox.type = 'checkbox'; checkbox.checked = !grant.readOnly;
|
||||||
transfer.onchange = () => act(() => window.api.mcpUpdateGrant({ id: grant.id, remove: false, readOnly: grant.readOnly, allowTransfer: transfer.checked }));
|
label.append(checkbox, text(' Schreibzugriff', ' Write access'));
|
||||||
const remove = document.createElement('button'); remove.type = 'button'; remove.className = 'btn btn-sm btn-secondary'; remove.textContent = text('Entfernen', 'Remove');
|
checkbox.onchange = () => act(() => window.api.mcpUpdateGrant({ id: grant.id, remove: false, readOnly: !checkbox.checked, allowTransfer: grant.allowTransfer === true }));
|
||||||
remove.onclick = () => act(() => window.api.mcpUpdateGrant({ id: grant.id, remove: true, readOnly: true }));
|
const transferLabel = document.createElement('label'); const transfer = document.createElement('input'); transfer.type = 'checkbox'; transfer.checked = grant.allowTransfer === true;
|
||||||
row.append(name, label, transferLabel, remove); return row;
|
transferLabel.append(transfer, text(' Dateiinhalte übertragen', ' Transfer file contents'));
|
||||||
}));
|
transfer.onchange = () => act(() => window.api.mcpUpdateGrant({ id: grant.id, remove: false, readOnly: grant.readOnly, allowTransfer: transfer.checked }));
|
||||||
|
const remove = document.createElement('button'); remove.type = 'button'; remove.className = 'btn btn-sm btn-secondary'; remove.textContent = text('Entfernen', 'Remove');
|
||||||
|
remove.onclick = () => act(() => window.api.mcpUpdateGrant({ id: grant.id, remove: true, readOnly: true }));
|
||||||
|
options.append(label, transferLabel, remove); row.append(name, options); return row;
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
for (const [index, grant] of (state.grants || []).entries()) {
|
||||||
|
const inputs = grants.children[index]?.querySelectorAll('input');
|
||||||
|
if (inputs) { inputs[0].checked = !grant.readOnly; inputs[1].checked = grant.allowTransfer === true; }
|
||||||
|
}
|
||||||
|
area.querySelector('[data-mcp-grants-empty]').hidden = !!state.grants?.length;
|
||||||
|
refreshControls();
|
||||||
};
|
};
|
||||||
const syncPermissions = state => {
|
const act = async (action, resetDraft = false) => {
|
||||||
for (const input of document.querySelectorAll('#mcpControls .mcp-permissions input, #mcpControls [data-mcp-updates]')) input.checked = state?.capabilities?.includes(input.value) === true;
|
if (busy) return;
|
||||||
};
|
busy = true;
|
||||||
const act = async action => {
|
saving = resetDraft;
|
||||||
try { const state = await action(); if (state && typeof state === 'object') { renderStatus(state); syncPermissions(state); } }
|
refreshControls();
|
||||||
catch { showCopyToast(text('MCP-Aktion fehlgeschlagen. Verbindung und lokale Berechtigungen prüfen.', 'MCP action failed. Check connection and local permissions.'), 6000, 'error'); if (current) { renderStatus(current); syncPermissions(current); } }
|
try {
|
||||||
|
const state = await action();
|
||||||
|
if (state && typeof state === 'object') renderStatus(state, resetDraft);
|
||||||
|
} catch {
|
||||||
|
showCopyToast(text('MCP-Aktion fehlgeschlagen. Verbindung und lokale Berechtigungen prüfen.', 'MCP action failed. Check connection and local permissions.'), 6000, 'error');
|
||||||
|
if (current) renderStatus(current);
|
||||||
|
} finally { busy = false; saving = false; refreshControls(); }
|
||||||
};
|
};
|
||||||
window.renderMcpSettings = () => `<section id="mcpControls" class="mcp-controls">
|
window.renderMcpSettings = () => `<section id="mcpControls" class="mcp-controls">
|
||||||
<div class="settings-section-label">MCP</div>
|
<section class="mcp-card mcp-connection" aria-labelledby="mcpConnectionTitle">
|
||||||
<p>${text('Strukturierter Fernzugriff über HTTPS. Nur bei laufender Anwendung; keine Portfreigabe erforderlich. Berechtigungen werden ausschließlich hier vergeben.', 'Structured remote access over HTTPS. Available while the app is running; no inbound port required. Permissions can only be granted here.')}</p>
|
<div class="mcp-card-heading"><h4 id="mcpConnectionTitle">${text('Verbindung', 'Connection')}</h4><span class="mcp-state" data-mcp-status data-state="starting" role="status">${text('Wird geladen', 'Loading')}</span></div>
|
||||||
<div class="settings-row"><label for="mcpName">${text('Installationsname', 'Installation name')}</label><input id="mcpName" class="key-input" maxlength="100"></div>
|
<p data-mcp-summary>${text('Der Verbindungsstatus wird geladen.', 'Loading the connection status.')}</p>
|
||||||
<fieldset class="mcp-permissions"><legend>${text('Lokale Berechtigungen', 'Local permissions')}</legend>${[['read','Lesen und Diagnose','Read and diagnostics'],['control','App steuern','Control app'],['files','Freigegebene Ordner','Granted directories'],['secrets','Zugangsdaten explizit auslesen','Explicitly reveal secrets']].map(([value,de,en])=>`<label><input type="checkbox" value="${value}"> ${text(de,en)}</label>`).join('')}</fieldset>
|
<dl class="mcp-status"><div><dt>${text('Letzter Kontakt','Last contact')}</dt><dd data-mcp-contact>—</dd></div><div><dt>${text('Freigegebene Ordner','Granted directories')}</dt><dd data-mcp-grant-count>0</dd></div><div><dt>${text('Ausstehende Widerrufe','Pending revocations')}</dt><dd data-mcp-pending>0</dd></div></dl>
|
||||||
<div class="mcp-actions"><button class="btn btn-sm btn-primary" data-mcp-action="enable">${text('Speichern und aktivieren','Save and enable')}</button><button class="btn btn-sm btn-secondary" data-mcp-action="disable">${text('Deaktivieren und widerrufen','Disable and revoke')}</button><button class="btn btn-sm btn-secondary" data-mcp-action="copy">${text('Verbindungscode kopieren','Copy connection code')}</button><button class="btn btn-sm btn-secondary" data-mcp-action="rotate">${text('Zugang erneuern','Rotate access')}</button></div>
|
<div class="mcp-code-row" data-settings-search-entry data-settings-search-label="Verbindungscode kopieren"><p>${text('Den Code auf diesem Gerät kopieren und im MCP-Client hinterlegen. Er gilt nur für diese Installation.', 'Copy the code on this device and add it to your MCP client. It applies only to this installation.')}</p><button type="button" class="btn btn-sm btn-secondary" data-mcp-action="copy" disabled>${text('Verbindungscode kopieren','Copy connection code')}</button></div>
|
||||||
<dl class="mcp-status"><div><dt>Status</dt><dd data-mcp-status>—</dd></div><div><dt>${text('Letzter Kontakt','Last contact')}</dt><dd data-mcp-contact>—</dd></div><div><dt>${text('Ausstehende Widerrufe','Pending revocations')}</dt><dd data-mcp-pending>0</dd></div></dl>
|
</section>
|
||||||
<p>${text('Der Verbindungscode ist ein Zugangsschlüssel. Er wird weder im Backup gespeichert noch auf andere Installationen übertragen. Löschungen und andere gefährliche Aktionen verlangen eine lokale Bestätigung.', 'The connection code is a credential. It is not stored in backups or transferred to other installations. Deletions and other dangerous actions require local confirmation.')}</p>
|
<section class="mcp-card" aria-labelledby="mcpSetupTitle">
|
||||||
<div class="mcp-actions"><button class="btn btn-sm btn-secondary" data-mcp-action="grant">${text('Ordner freigeben','Grant directory')}</button></div>
|
<div class="mcp-card-heading"><h4 id="mcpSetupTitle">${text('Einrichtung und Berechtigungen', 'Setup and permissions')}</h4></div>
|
||||||
<p>${text('Dateiinhalte werden nur nach zusätzlicher Freigabe pro Ordner übertragen. Bestehende Ordnerfreigaben erlauben dies nicht automatisch.', 'File contents are transferred only after additional permission for each directory. Existing directory grants do not allow this automatically.')}</p><div data-mcp-grants></div>
|
<p>${text('Name und Berechtigungen auswählen. Änderungen werden erst mit dem Speichern wirksam.', 'Choose a name and permissions. Changes take effect only when saved.')}</p>
|
||||||
<label class="mcp-update-permission"><input type="checkbox" value="updates" data-mcp-updates> ${text('Offizielle App-Updates ohne erneute Bestätigung erlauben', 'Allow official app updates without another confirmation')}</label>
|
<div class="mcp-name-row" data-settings-search-entry><label for="mcpName">${text('Installationsname', 'Installation name')}</label><input id="mcpName" class="key-input" maxlength="100" disabled></div>
|
||||||
<p>${text('Standardmäßig aus. Gilt nur für geprüfte Installer einer exakt angeforderten Version. Laufende Uploads werden abgeschlossen und die Warteschlange nach dem Neustart wieder aufgenommen. Portable-Versionen werden nicht unterstützt.', 'Disabled by default. Limited to verified installers of the exact requested version. Running uploads finish and the queue resumes after restart. Portable versions are not supported.')}</p>
|
<fieldset class="mcp-permissions"><legend>${text('Lokale Berechtigungen', 'Local permissions')}</legend>${[
|
||||||
|
['read','Lesen und Diagnose','Read and diagnostics','Status, Uploads, Protokolle und Diagnose lesen.','Read status, uploads, logs and diagnostics.'],
|
||||||
|
['control','App steuern','Control app','Uploads und Konten verwalten. Kritische Aktionen lokal bestätigen.','Manage uploads and accounts. Confirm critical actions locally.'],
|
||||||
|
['files','Freigegebene Ordner','Granted directories','Auf ausgewählte Ordner zugreifen. Dateiinhalte separat freigeben.','Access selected directories. Allow file contents separately.'],
|
||||||
|
['updates','App-Updates installieren','Install app updates','Geprüfte Updates ohne erneute Bestätigung installieren. Uploads abschließen und danach fortsetzen. Keine Portable-Versionen.','Install verified updates without another confirmation. Finish uploads and resume afterwards. No portable versions.'],
|
||||||
|
['secrets','Zugangsdaten auslesen','Reveal credentials','Gespeicherte Zugangsdaten ausdrücklich freigeben. Zusätzliche lokale Bestätigung erforderlich.','Explicitly allow saved credentials to be read. Additional local confirmation required.']
|
||||||
|
].map(([value,de,en,description,englishDescription])=>`<label class="mcp-permission${value === 'secrets' ? ' mcp-permission-sensitive' : ''}" data-settings-search-entry data-settings-search-label="${de}"><input type="checkbox" value="${value}"${value === 'updates' ? ' data-mcp-updates' : ''} disabled><span><strong>${text(de,en)}</strong><span class="mcp-permission-description">${text(description,englishDescription)}</span></span></label>`).join('')}</fieldset>
|
||||||
|
<div class="mcp-save-row"><p data-mcp-save-state role="status">${text('Erst speichern und aktivieren, dann den Verbindungscode kopieren.', 'Save and enable first, then copy the connection code.')}</p><button type="button" class="btn btn-sm btn-primary" data-mcp-action="enable" disabled>${text('Speichern und aktivieren','Save and enable')}</button></div>
|
||||||
|
</section>
|
||||||
|
<section class="mcp-card" aria-labelledby="mcpGrantsTitle">
|
||||||
|
<div class="mcp-card-heading"><h4 id="mcpGrantsTitle">${text('Ordnerfreigaben', 'Directory access')}</h4><button type="button" class="btn btn-sm btn-secondary" data-mcp-action="grant" disabled>${text('Ordner freigeben','Grant directory')}</button></div>
|
||||||
|
<p>${text('Dateiinhalte werden nur nach zusätzlicher Freigabe pro Ordner übertragen. Bestehende Ordnerfreigaben erlauben dies nicht automatisch.', 'File contents are transferred only after additional permission for each directory. Existing directory grants do not allow this automatically.')}</p>
|
||||||
|
<p class="mcp-empty" data-mcp-grants-empty>${text('Keine Ordner freigegeben.', 'No directories granted.')}</p><div data-mcp-grants></div>
|
||||||
|
</section>
|
||||||
|
<section class="mcp-card" aria-labelledby="mcpAccessTitle">
|
||||||
|
<div class="mcp-card-heading"><h4 id="mcpAccessTitle">${text('Zugang verwalten', 'Manage access')}</h4></div>
|
||||||
|
<p>${text('Der Verbindungscode ist ein Zugangsschlüssel. Er wird weder im Backup gespeichert noch auf andere Installationen übertragen. Löschungen und andere gefährliche Aktionen verlangen eine lokale Bestätigung.', 'The connection code is a credential. It is not stored in backups or transferred to other installations. Deletions and other dangerous actions require local confirmation.')}</p>
|
||||||
|
<p>${text('Zugang erneuern macht den bisherigen Code ungültig. Deaktivieren beendet den Fernzugriff und widerruft den Zugang.', 'Rotating access invalidates the previous code. Disabling remote access revokes access.')}</p>
|
||||||
|
<div class="mcp-actions"><button type="button" class="btn btn-sm btn-secondary" data-mcp-action="rotate" disabled>${text('Zugang erneuern','Rotate access')}</button><button type="button" class="btn btn-sm btn-secondary" data-mcp-action="disable" disabled>${text('Deaktivieren und widerrufen','Disable and revoke')}</button></div>
|
||||||
|
</section>
|
||||||
|
<p class="mcp-footnote">${text('Strukturierter Fernzugriff über HTTPS. Nur bei laufender Anwendung; keine Portfreigabe erforderlich. Berechtigungen werden ausschließlich hier vergeben.', 'Structured remote access over HTTPS. Available while the app is running; no inbound port required. Permissions can only be granted here.')}</p>
|
||||||
</section>`;
|
</section>`;
|
||||||
window.bindMcpSettings = async () => {
|
window.bindMcpSettings = async () => {
|
||||||
const area = document.getElementById('mcpControls'); if (!area) return;
|
const area = document.getElementById('mcpControls'); if (!area) return;
|
||||||
const state = await window.api.mcpStatus(); if (!state) return;
|
const state = await window.api.mcpStatus(); if (!state || !area.isConnected) return;
|
||||||
renderStatus(state);
|
renderStatus(state, true);
|
||||||
area.querySelector('#mcpName').value = state.name || 'Multi-Hoster-Uploader';
|
for (const input of area.querySelectorAll('#mcpName, .mcp-permissions input')) input.addEventListener('input', refreshControls);
|
||||||
for (const input of area.querySelectorAll('.mcp-permissions input')) input.checked = state.capabilities?.includes(input.value) === true;
|
area.querySelector('[data-mcp-action="enable"]').onclick = () => act(() => window.api.mcpConfigure(configuration(area)), true);
|
||||||
area.querySelector('[data-mcp-updates]').checked = state.capabilities?.includes('updates') === true;
|
area.querySelector('[data-mcp-action="disable"]').onclick = () => act(() => window.api.mcpConfigure({ enabled: false, name: current.name, capabilities: current.capabilities }));
|
||||||
const configuration = enabled => ({ enabled, name: area.querySelector('#mcpName').value.trim(), capabilities: [...area.querySelectorAll('.mcp-permissions input:checked, [data-mcp-updates]:checked')].map(input => input.value) });
|
|
||||||
area.querySelector('[data-mcp-action="enable"]').onclick = () => act(() => window.api.mcpConfigure(configuration(true)));
|
|
||||||
area.querySelector('[data-mcp-action="disable"]').onclick = () => act(() => window.api.mcpConfigure(configuration(false)));
|
|
||||||
area.querySelector('[data-mcp-action="rotate"]').onclick = () => act(() => window.api.mcpRotate());
|
area.querySelector('[data-mcp-action="rotate"]').onclick = () => act(() => window.api.mcpRotate());
|
||||||
area.querySelector('[data-mcp-action="copy"]').onclick = () => act(async () => { await window.api.mcpCopyCode(); showCopyToast(text('Verbindungscode kopiert.', 'Connection code copied.')); });
|
area.querySelector('[data-mcp-action="copy"]').onclick = () => act(async () => { await window.api.mcpCopyCode(); showCopyToast(text('Verbindungscode kopiert.', 'Connection code copied.')); });
|
||||||
area.querySelector('[data-mcp-action="grant"]').onclick = () => act(() => window.api.mcpAddGrant());
|
area.querySelector('[data-mcp-action="grant"]').onclick = () => act(() => window.api.mcpAddGrant());
|
||||||
|
|||||||
Reference in new issue
Block a user