diff --git a/README.md b/README.md index d6d6cfb..482b916 100644 --- a/README.md +++ b/README.md @@ -280,7 +280,7 @@ You can always install manually from the [GitHub releases page](https://github.c ## Clouddrop log sync -Settings → Logs & Support includes an optional Clouddrop connection for upload logs. Enter an unrestricted Clouddrop API key and select **Verify and enable**. Verification creates an empty test file in a folder named after the device's public IP address; ipify provides the public IP. The key is stored using the operating system's credential encryption. +Settings → Logs & Support includes an optional Clouddrop connection for upload logs. Enter an unrestricted Clouddrop API key and select **Verify and enable**. Verification creates an empty test file in a folder named after the device's public IP address; ipify provides the public IP. IPv4 is preferred, with readable IPv6 as a fallback. The key is stored using the operating system's credential encryption. Multiple instances can use the same key; each writes its own files, including when instances share a public IP. New successful upload entries for hosts with file logging enabled are synchronized automatically as TXT files. The single-file, daily and per-session log modes apply. Files have unique suffixes so separate instances using the same key do not overwrite one another. Large logs are split into separate files before they reach the text API size limit. Existing local log contents are not imported automatically. diff --git a/lib/clouddrop-log-api.js b/lib/clouddrop-log-api.js index 9ecb7e9..5272b01 100644 --- a/lib/clouddrop-log-api.js +++ b/lib/clouddrop-log-api.js @@ -61,15 +61,20 @@ class ClouddropLogApi { || Number(expires) <= Date.now() || !/^[a-f0-9]{64}$/.test(signature || '') || extra !== undefined) { throw new CloudLogError('INVALID_RESPONSE'); } - const response = await this.request('https://api64.ipify.org?format=json', { - signal, maxRedirections: 0, headersTimeout: 15000, bodyTimeout: 15000, - headers: { Accept: 'application/json' } - }); - const text = await response.body.text(); - let ip; - try { ip = JSON.parse(text).ip; } catch {} - if (response.statusCode !== 200 || !isIP(ip || '')) throw new CloudLogError('IP_UNAVAILABLE'); - return { accountId, ip, folderName: ip.replaceAll(':', '_') }; + for (const endpoint of ['https://api.ipify.org?format=json', 'https://api64.ipify.org?format=json']) { + try { + const response = await this.request(endpoint, { + signal, maxRedirections: 0, headersTimeout: 10000, bodyTimeout: 10000, + headers: { Accept: 'application/json' } + }); + const text = await response.body.text(); + const ip = JSON.parse(text).ip; + if (response.statusCode === 200 && isIP(ip || '')) return { accountId, ip, folderName: ip }; + } catch { + if (signal?.aborted) throw new CloudLogError('IP_UNAVAILABLE'); + } + } + throw new CloudLogError('IP_UNAVAILABLE'); } async ensureFolder(name, signal) { @@ -91,6 +96,7 @@ class ClouddropLogApi { } async createFile(folderId, name, id, signal) { + const verificationRoute = `/check-duplicate?parent=${encodeURIComponent(folderId)}&filename=${encodeURIComponent(name)}`; let created; try { created = await this.call('/create-file', { @@ -99,14 +105,13 @@ class ClouddropLogApi { }); } catch (error) { if (error.status !== 409) throw error; - const existing = await this.call(`/files?parent=${encodeURIComponent(folderId)}&limit=2500&sync=${encodeURIComponent(id)}`, { signal }); - const file = existing.files?.find(item => item.filename === name && item.parentId === folderId && !item.isFolder); - if (!file) throw error; - created = { id: file.id, filename: file.filename }; + const existing = await this.call(verificationRoute, { signal }); + if (!existing.exists || !existing.existingId) throw error; + created = { id: existing.existingId, filename: name }; } if (!created.id || created.filename !== name) throw new CloudLogError('INVALID_RESPONSE'); - const listing = await this.call(`/files?parent=${encodeURIComponent(folderId)}&limit=2500&sync=${encodeURIComponent(id)}`, { signal }); - if (!Array.isArray(listing.files) || !listing.files.some(file => file.id === created.id && file.parentId === folderId)) { + const verification = await this.call(verificationRoute, { signal }); + if (verification.exists !== true || verification.existingId !== created.id) { throw new CloudLogError('UNRESTRICTED_KEY_REQUIRED'); } return String(created.id); diff --git a/renderer/app.js b/renderer/app.js index cc8079d..c4a3da1 100644 --- a/renderer/app.js +++ b/renderer/app.js @@ -6409,7 +6409,7 @@ function renderCloudLogStatus(status) { if (!status || !document.getElementById('cloudLogPhase')) return; const phases = { disabled: 'Inaktiv', checking: 'Verbindung wird geprüft…', ready: 'Aktiv', syncing: 'Wird synchronisiert…', error: 'Synchronisierung fehlgeschlagen' }; document.getElementById('cloudLogPhase').textContent = localizeUiText(phases[status.phase] || phases.disabled); - document.getElementById('cloudLogIp').textContent = status.ip ? status.ip.replaceAll(':', '_') : '—'; + document.getElementById('cloudLogIp').textContent = status.ip || '—'; document.getElementById('cloudLogLastSync').textContent = status.lastSyncedAt ? new Date(status.lastSyncedAt).toLocaleString(getUiLocale()) : localizeUiText('Noch nicht synchronisiert'); document.getElementById('cloudLogPending').textContent = (Number(status.pendingFiles) || 0).toLocaleString(getUiLocale());