This commit is contained in:
1 parent
63abaa819c
commit
63296e7ad3
7 files changed
+226
-19
No files matched your search
+101
-3
@@ -3,6 +3,7 @@ const path = require('node:path');
|
|||||||
const { randomUUID, createHash } = require('node:crypto');
|
const { randomUUID, createHash } = require('node:crypto');
|
||||||
const { EventEmitter } = require('node:events');
|
const { EventEmitter } = require('node:events');
|
||||||
const { ClouddropLogApi, CloudLogError } = require('./clouddrop-log-api');
|
const { ClouddropLogApi, CloudLogError } = require('./clouddrop-log-api');
|
||||||
|
const { iterateUploadLogEntries } = require('./upload-log');
|
||||||
|
|
||||||
const MAX_DOCUMENT_BYTES = 700000;
|
const MAX_DOCUMENT_BYTES = 700000;
|
||||||
const hash = value => createHash('sha256').update(value).digest('hex');
|
const hash = value => createHash('sha256').update(value).digest('hex');
|
||||||
@@ -35,6 +36,9 @@ class CloudLogSync extends EventEmitter {
|
|||||||
this.closed = false;
|
this.closed = false;
|
||||||
this.retryBlocked = false;
|
this.retryBlocked = false;
|
||||||
this.documentTime = 0;
|
this.documentTime = 0;
|
||||||
|
this.backfillJob = null;
|
||||||
|
this.backfillContext = null;
|
||||||
|
this.backfillResult = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
async initialize() {
|
async initialize() {
|
||||||
@@ -71,7 +75,9 @@ class CloudLogSync extends EventEmitter {
|
|||||||
ip: this.connection?.ip || settings.ip || '',
|
ip: this.connection?.ip || settings.ip || '',
|
||||||
pendingFiles: pending.length,
|
pendingFiles: pending.length,
|
||||||
lastSyncedAt: Math.max(0, ...docs.map(doc => Number(doc.lastSyncedAt) || 0)),
|
lastSyncedAt: Math.max(0, ...docs.map(doc => Number(doc.lastSyncedAt) || 0)),
|
||||||
fileCount: docs.length
|
fileCount: docs.length,
|
||||||
|
backfillRunning: Boolean(this.backfillJob),
|
||||||
|
backfillResult: this.backfillResult ? { ...this.backfillResult } : null
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -158,7 +164,7 @@ class CloudLogSync extends EventEmitter {
|
|||||||
this.errorCode = this._errorCode(error);
|
this.errorCode = this._errorCode(error);
|
||||||
this.retryBlocked = blocksRetry(this.errorCode);
|
this.retryBlocked = blocksRetry(this.errorCode);
|
||||||
this.notify();
|
this.notify();
|
||||||
if (!blocksRetry(this.errorCode)) {
|
if (!this.closed && !blocksRetry(this.errorCode)) {
|
||||||
this.timer = setTimeout(() => { this.timer = null; void this.start(); }, 30000);
|
this.timer = setTimeout(() => { this.timer = null; void this.start(); }, 30000);
|
||||||
this.timer.unref?.();
|
this.timer.unref?.();
|
||||||
}
|
}
|
||||||
@@ -175,7 +181,7 @@ class CloudLogSync extends EventEmitter {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async append(sourcePath, line) {
|
async append(sourcePath, line, trackBackfill = true) {
|
||||||
await this.initialize();
|
await this.initialize();
|
||||||
const settings = this.loadSettings() || {};
|
const settings = this.loadSettings() || {};
|
||||||
if (!settings.enabled || !settings.accountId || typeof line !== 'string' || !line) return;
|
if (!settings.enabled || !settings.accountId || typeof line !== 'string' || !line) return;
|
||||||
@@ -193,6 +199,12 @@ class CloudLogSync extends EventEmitter {
|
|||||||
.find(doc => doc.accountId === settings.accountId && doc.source === hash('connection-check'))?.folderId;
|
.find(doc => doc.accountId === settings.accountId && doc.source === hash('connection-check'))?.folderId;
|
||||||
if (!connection.folderId) return;
|
if (!connection.folderId) return;
|
||||||
const source = hash(`${sourcePath}|${connection.ip}|${connection.folderId}`);
|
const source = hash(`${sourcePath}|${connection.ip}|${connection.folderId}`);
|
||||||
|
const backfill = this.backfillContext;
|
||||||
|
if (trackBackfill && backfill?.folderId === connection.folderId && backfill.accountId === settings.accountId) {
|
||||||
|
for (const entry of line.split(/\r?\n/).filter(Boolean)) {
|
||||||
|
backfill.counts.set(entry, (backfill.counts.get(entry) || 0) + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
let doc = known.filter(item => item.source === source).sort((a, b) => b.createdAt - a.createdAt)[0];
|
let doc = known.filter(item => item.source === source).sort((a, b) => b.createdAt - a.createdAt)[0];
|
||||||
if (!doc || Buffer.byteLength(doc.content) + Buffer.byteLength(line) > MAX_DOCUMENT_BYTES) {
|
if (!doc || Buffer.byteLength(doc.content) + Buffer.byteLength(line) > MAX_DOCUMENT_BYTES) {
|
||||||
doc = this._newDocument(connection, source, path.basename(sourcePath, path.extname(sourcePath)), '');
|
doc = this._newDocument(connection, source, path.basename(sourcePath, path.extname(sourcePath)), '');
|
||||||
@@ -206,6 +218,7 @@ class CloudLogSync extends EventEmitter {
|
|||||||
this.errorCode = this._errorCode(error);
|
this.errorCode = this._errorCode(error);
|
||||||
this.notify();
|
this.notify();
|
||||||
this.schedule();
|
this.schedule();
|
||||||
|
if (!trackBackfill) throw new CloudLogError('LOCAL_WRITE_FAILED');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -221,6 +234,90 @@ class CloudLogSync extends EventEmitter {
|
|||||||
return operation;
|
return operation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
backfill(sourcePath) {
|
||||||
|
if (this.backfillJob) return this.backfillJob;
|
||||||
|
const operation = this.control.then(() => this._backfill(sourcePath));
|
||||||
|
this.backfillJob = operation.finally(() => {
|
||||||
|
this.backfillJob = null;
|
||||||
|
this.backfillContext = null;
|
||||||
|
this.notify();
|
||||||
|
});
|
||||||
|
this.control = this.backfillJob.catch(() => {});
|
||||||
|
this.notify();
|
||||||
|
return this.backfillJob;
|
||||||
|
}
|
||||||
|
|
||||||
|
async _backfill(sourcePath) {
|
||||||
|
await this.initialize();
|
||||||
|
if (this.closed || !this.loadSettings()?.enabled || !this.connection || this.retryBlocked) {
|
||||||
|
throw new CloudLogError('CONNECTION_REQUIRED');
|
||||||
|
}
|
||||||
|
const connection = this.connection;
|
||||||
|
let file;
|
||||||
|
const result = { added: 0, skipped: 0 };
|
||||||
|
this.backfillResult = null;
|
||||||
|
try {
|
||||||
|
file = await fs.open(sourcePath, 'r');
|
||||||
|
const stat = await file.stat();
|
||||||
|
if (!stat.isFile()) throw new CloudLogError('LOG_READ_FAILED');
|
||||||
|
if (stat.size > 256 * 1024 * 1024) throw new CloudLogError('LOG_TOO_LARGE');
|
||||||
|
if (stat.size === 0) {
|
||||||
|
this.backfillResult = result;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
const counts = new Map();
|
||||||
|
for (const doc of this.documents.values()) {
|
||||||
|
if (doc.accountId !== connection.accountId || doc.folderId !== connection.folderId) continue;
|
||||||
|
for (const line of doc.content.split(/\r?\n/).filter(Boolean)) {
|
||||||
|
counts.set(line, (counts.get(line) || 0) + 1);
|
||||||
|
if (counts.size > 250000) throw new CloudLogError('LOG_TOO_LARGE');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.backfillContext = { folderId: connection.folderId, accountId: connection.accountId, counts };
|
||||||
|
const seen = new Map();
|
||||||
|
let pending = '';
|
||||||
|
let pendingLines = 0;
|
||||||
|
const savePending = async () => {
|
||||||
|
if (!pending) return;
|
||||||
|
const content = pending;
|
||||||
|
pending = '';
|
||||||
|
pendingLines = 0;
|
||||||
|
await this.append(sourcePath, content, false);
|
||||||
|
};
|
||||||
|
try {
|
||||||
|
for await (const entry of iterateUploadLogEntries(sourcePath, {
|
||||||
|
fs: { createReadStream: () => file.createReadStream({ encoding: 'utf8', highWaterMark: 32768, end: stat.size - 1, autoClose: false }) },
|
||||||
|
includeLine: true, requireCompleteLines: true
|
||||||
|
})) {
|
||||||
|
if (this.closed) throw new CloudLogError('BACKFILL_CANCELED');
|
||||||
|
if (!entry.confirmed) continue;
|
||||||
|
const count = (seen.get(entry.line) || 0) + 1;
|
||||||
|
seen.set(entry.line, count);
|
||||||
|
if (seen.size > 250000) throw new CloudLogError('LOG_TOO_LARGE');
|
||||||
|
if (count <= (counts.get(entry.line) || 0)) {
|
||||||
|
result.skipped++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
counts.set(entry.line, (counts.get(entry.line) || 0) + 1);
|
||||||
|
pending += entry.line + '\n';
|
||||||
|
pendingLines++;
|
||||||
|
result.added++;
|
||||||
|
if (pendingLines >= 100 || Buffer.byteLength(pending) >= 32768) await savePending();
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
await savePending();
|
||||||
|
}
|
||||||
|
this.backfillResult = result;
|
||||||
|
this.schedule(0);
|
||||||
|
return { ...result };
|
||||||
|
} catch (error) {
|
||||||
|
if (error instanceof CloudLogError) throw error;
|
||||||
|
throw new CloudLogError(error?.code === 'ENOENT' ? 'LOG_NOT_FOUND' : 'LOG_READ_FAILED');
|
||||||
|
} finally {
|
||||||
|
if (file) await file.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
flushLocal() {
|
flushLocal() {
|
||||||
const operation = this.localWrites.then(async () => {
|
const operation = this.localWrites.then(async () => {
|
||||||
for (const id of [...this.dirty]) {
|
for (const id of [...this.dirty]) {
|
||||||
@@ -298,6 +395,7 @@ class CloudLogSync extends EventEmitter {
|
|||||||
clearTimeout(this.timer);
|
clearTimeout(this.timer);
|
||||||
this.timer = null;
|
this.timer = null;
|
||||||
this.controller?.abort();
|
this.controller?.abort();
|
||||||
|
if (this.backfillJob) await this.backfillJob.catch(() => {});
|
||||||
if (this.worker) await this.worker;
|
if (this.worker) await this.worker;
|
||||||
await this.flushLocal();
|
await this.flushLocal();
|
||||||
await this.diskWrites;
|
await this.diskWrites;
|
||||||
|
|||||||
+4
-4
@@ -30,7 +30,7 @@
|
|||||||
return { hoster, fileName, ts, confirmed };
|
return { hoster, fileName, ts, confirmed };
|
||||||
}
|
}
|
||||||
|
|
||||||
async function* iterateBoundedUploadLogLines(chunks, maxLineLength) {
|
async function* iterateBoundedUploadLogLines(chunks, maxLineLength, requireCompleteLines) {
|
||||||
let buffer = '';
|
let buffer = '';
|
||||||
for await (const chunk of chunks) {
|
for await (const chunk of chunks) {
|
||||||
buffer += String(chunk);
|
buffer += String(chunk);
|
||||||
@@ -44,7 +44,7 @@
|
|||||||
}
|
}
|
||||||
if (buffer.length > maxLineLength) throw new Error('Upload-Log-Zeile ist zu lang');
|
if (buffer.length > maxLineLength) throw new Error('Upload-Log-Zeile ist zu lang');
|
||||||
}
|
}
|
||||||
if (buffer) yield buffer.replace(/\r$/, '');
|
if (buffer && !requireCompleteLines) yield buffer.replace(/\r$/, '');
|
||||||
}
|
}
|
||||||
|
|
||||||
async function* iterateBoundedUploadLogChunks(chunks, maxBytes, onBytes) {
|
async function* iterateBoundedUploadLogChunks(chunks, maxBytes, onBytes) {
|
||||||
@@ -67,13 +67,13 @@
|
|||||||
const maxBytes = Number.isFinite(Number(options.maxBytes)) ? Math.max(1, Math.floor(Number(options.maxBytes))) : 256 * 1024 * 1024;
|
const maxBytes = Number.isFinite(Number(options.maxBytes)) ? Math.max(1, Math.floor(Number(options.maxBytes))) : 256 * 1024 * 1024;
|
||||||
const yieldFn = typeof options.yieldFn === 'function' ? options.yieldFn : (() => new Promise(resolve => setImmediate(resolve)));
|
const yieldFn = typeof options.yieldFn === 'function' ? options.yieldFn : (() => new Promise(resolve => setImmediate(resolve)));
|
||||||
const input = options.lines ? null : fsImpl.createReadStream(filePath, { encoding: 'utf8', highWaterMark: 32768 });
|
const input = options.lines ? null : fsImpl.createReadStream(filePath, { encoding: 'utf8', highWaterMark: 32768 });
|
||||||
const lines = options.lines || iterateBoundedUploadLogLines(iterateBoundedUploadLogChunks(input, maxBytes, options.onBytes), maxLineLength);
|
const lines = options.lines || iterateBoundedUploadLogLines(iterateBoundedUploadLogChunks(input, maxBytes, options.onBytes), maxLineLength, options.requireCompleteLines);
|
||||||
let count = 0;
|
let count = 0;
|
||||||
try {
|
try {
|
||||||
for await (const line of lines) {
|
for await (const line of lines) {
|
||||||
if (String(line).length > maxLineLength) throw new Error('Upload-Log-Zeile ist zu lang');
|
if (String(line).length > maxLineLength) throw new Error('Upload-Log-Zeile ist zu lang');
|
||||||
const parsed = parseUploadLogLine(line);
|
const parsed = parseUploadLogLine(line);
|
||||||
if (parsed) yield parsed;
|
if (parsed) yield options.includeLine ? { ...parsed, line: String(line) } : parsed;
|
||||||
count++;
|
count++;
|
||||||
if (count % yieldEvery === 0) await yieldFn();
|
if (count % yieldEvery === 0) await yieldFn();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2060,6 +2060,19 @@ ipcMain.handle('cloud-log:configure', async (event, payload = {}) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
ipcMain.handle('cloud-log:backfill', async event => {
|
||||||
|
if (!isTrustedOnlineBackupIpcEvent(event)) return { ok: false, errorCode: 'ACCESS_DENIED' };
|
||||||
|
assertConfigWriteAllowed();
|
||||||
|
try {
|
||||||
|
await Promise.all([...cloudLogWrites]);
|
||||||
|
const result = await cloudLogSync.backfill(_cachedUploadLogTarget?.path || getLogFilePath());
|
||||||
|
return { ok: true, result, status: cloudLogSync.status() };
|
||||||
|
} catch (error) {
|
||||||
|
const allowed = ['CONNECTION_REQUIRED', 'LOG_NOT_FOUND', 'LOG_READ_FAILED', 'LOG_TOO_LARGE', 'LOCAL_WRITE_FAILED', 'BACKFILL_CANCELED'];
|
||||||
|
return { ok: false, errorCode: allowed.includes(error?.code) ? error.code : 'LOG_READ_FAILED', status: cloudLogSync.status() };
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
ipcMain.handle('save-config', async (_event, config) => {
|
ipcMain.handle('save-config', async (_event, config) => {
|
||||||
assertConfigWriteAllowed();
|
assertConfigWriteAllowed();
|
||||||
if (config?.globalSettings) config.globalSettings.cloudLogSync = configStore.load().globalSettings.cloudLogSync;
|
if (config?.globalSettings) config.globalSettings.cloudLogSync = configStore.load().globalSettings.cloudLogSync;
|
||||||
|
|||||||
@@ -90,6 +90,7 @@ contextBridge.exposeInMainWorld('api', {
|
|||||||
importUploadLog: () => ipcRenderer.invoke('import-upload-log'),
|
importUploadLog: () => ipcRenderer.invoke('import-upload-log'),
|
||||||
getCloudLogStatus: () => ipcRenderer.invoke('cloud-log:status'),
|
getCloudLogStatus: () => ipcRenderer.invoke('cloud-log:status'),
|
||||||
configureCloudLog: (settings) => ipcRenderer.invoke('cloud-log:configure', settings),
|
configureCloudLog: (settings) => ipcRenderer.invoke('cloud-log:configure', settings),
|
||||||
|
backfillCloudLog: () => ipcRenderer.invoke('cloud-log:backfill'),
|
||||||
onCloudLogStatus: callback => {
|
onCloudLogStatus: callback => {
|
||||||
const listener = (_event, status) => callback(status);
|
const listener = (_event, status) => callback(status);
|
||||||
ipcRenderer.on('cloud-log:status', listener);
|
ipcRenderer.on('cloud-log:status', listener);
|
||||||
|
|||||||
+65
-6
@@ -6404,6 +6404,7 @@ async function runHealthCheck(mode = 'manual', requestedHosters = null) {
|
|||||||
|
|
||||||
// --- Settings ---
|
// --- Settings ---
|
||||||
let cloudLogBusy = false;
|
let cloudLogBusy = false;
|
||||||
|
let cloudLogBackfillBusy = false;
|
||||||
let cloudLogLastStatus = null;
|
let cloudLogLastStatus = null;
|
||||||
const cloudLogErrors = {
|
const cloudLogErrors = {
|
||||||
KEY_STORAGE_UNAVAILABLE: 'Der API-Key konnte nicht im sicheren Zugangsdaten-Speicher gesichert werden.',
|
KEY_STORAGE_UNAVAILABLE: 'Der API-Key konnte nicht im sicheren Zugangsdaten-Speicher gesichert werden.',
|
||||||
@@ -6422,7 +6423,12 @@ const cloudLogErrors = {
|
|||||||
INVALID_RESPONSE: 'Clouddrop hat eine unerwartete Antwort geliefert.',
|
INVALID_RESPONSE: 'Clouddrop hat eine unerwartete Antwort geliefert.',
|
||||||
VERIFICATION_FAILED: 'Die Testdatei konnte nicht verifiziert werden.',
|
VERIFICATION_FAILED: 'Die Testdatei konnte nicht verifiziert werden.',
|
||||||
RESPONSE_TOO_LARGE: 'Die Clouddrop-Antwort überschreitet die zulässige Größe.',
|
RESPONSE_TOO_LARGE: 'Die Clouddrop-Antwort überschreitet die zulässige Größe.',
|
||||||
LINE_TOO_LARGE: 'Ein Log-Eintrag überschreitet die zulässige Größe.'
|
LINE_TOO_LARGE: 'Ein Log-Eintrag überschreitet die zulässige Größe.',
|
||||||
|
CONNECTION_REQUIRED: 'Bitte die CloudDrop-Verbindung zuerst prüfen und aktivieren.',
|
||||||
|
LOG_NOT_FOUND: 'Die aktuelle lokale Upload-Log-Datei wurde noch nicht angelegt.',
|
||||||
|
LOG_READ_FAILED: 'Die aktuelle lokale Upload-Log-Datei konnte nicht vollständig gelesen werden. Bereits übernommene Einträge bleiben gespeichert.',
|
||||||
|
LOG_TOO_LARGE: 'Die Upload-Log-Datei überschreitet das sichere Leselimit.',
|
||||||
|
BACKFILL_CANCELED: 'Die Nachsynchronisierung wurde beendet. Bereits übernommene Einträge bleiben gespeichert.'
|
||||||
};
|
};
|
||||||
|
|
||||||
function renderCloudLogStatus(status) {
|
function renderCloudLogStatus(status) {
|
||||||
@@ -6430,14 +6436,34 @@ function renderCloudLogStatus(status) {
|
|||||||
if (!status || !document.getElementById('cloudLogPhase')) return;
|
if (!status || !document.getElementById('cloudLogPhase')) return;
|
||||||
const phases = { disabled: 'Inaktiv', checking: 'Verbindung wird geprüft…', ready: 'Aktiv', syncing: 'Wird synchronisiert…', error: 'Synchronisierung fehlgeschlagen' };
|
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('cloudLogPhase').textContent = localizeUiText(phases[status.phase] || phases.disabled);
|
||||||
|
document.getElementById('cloudLogPhase').dataset.phase = status.phase || 'disabled';
|
||||||
|
const keyState = document.getElementById('cloudLogKeyState');
|
||||||
|
if (keyState) {
|
||||||
|
keyState.textContent = localizeUiText(status.hasApiKey ? 'API-Key gespeichert' : 'Kein API-Key gespeichert');
|
||||||
|
keyState.dataset.saved = String(Boolean(status.hasApiKey));
|
||||||
|
}
|
||||||
document.getElementById('cloudLogIp').textContent = status.ip || '—';
|
document.getElementById('cloudLogIp').textContent = status.ip || '—';
|
||||||
document.getElementById('cloudLogLastSync').textContent = status.lastSyncedAt
|
document.getElementById('cloudLogLastSync').textContent = status.lastSyncedAt
|
||||||
? new Date(status.lastSyncedAt).toLocaleString(getUiLocale()) : localizeUiText('Noch nicht synchronisiert');
|
? new Date(status.lastSyncedAt).toLocaleString(getUiLocale()) : localizeUiText('Noch nicht synchronisiert');
|
||||||
document.getElementById('cloudLogPending').textContent = (Number(status.pendingFiles) || 0).toLocaleString(getUiLocale());
|
document.getElementById('cloudLogPending').textContent = (Number(status.pendingFiles) || 0).toLocaleString(getUiLocale());
|
||||||
const key = document.getElementById('cloudLogKeyInput');
|
const key = document.getElementById('cloudLogKeyInput');
|
||||||
key.placeholder = localizeUiText(status.hasApiKey ? 'Gespeicherten API-Key verwenden' : 'API-Key eingeben');
|
key.placeholder = localizeUiText(status.hasApiKey ? 'Gespeicherten API-Key verwenden' : 'API-Key eingeben');
|
||||||
document.getElementById('cloudLogActivateBtn').disabled = cloudLogBusy;
|
const busy = cloudLogBusy || cloudLogBackfillBusy || status.backfillRunning;
|
||||||
document.getElementById('cloudLogDisableBtn').disabled = cloudLogBusy || !status.enabled;
|
document.getElementById('cloudLogActivateBtn').disabled = busy;
|
||||||
|
document.getElementById('cloudLogDisableBtn').disabled = busy || !status.enabled;
|
||||||
|
const backfillButton = document.getElementById('cloudLogBackfillBtn');
|
||||||
|
if (backfillButton) {
|
||||||
|
backfillButton.disabled = busy || !status.enabled || !['ready', 'syncing'].includes(status.phase);
|
||||||
|
backfillButton.textContent = localizeUiText(status.backfillRunning || cloudLogBackfillBusy ? 'Vorhandenes Log wird eingelesen…' : 'Vorhandenes Log nachsynchronisieren');
|
||||||
|
}
|
||||||
|
const backfillResult = document.getElementById('cloudLogBackfillResult');
|
||||||
|
if (backfillResult) {
|
||||||
|
backfillResult.hidden = !status.backfillResult;
|
||||||
|
backfillResult.textContent = status.backfillResult
|
||||||
|
? localizeUiText('Neu übernommen') + ': ' + Number(status.backfillResult.added || 0).toLocaleString(getUiLocale())
|
||||||
|
+ ' · ' + localizeUiText('Bereits vorhanden') + ': ' + Number(status.backfillResult.skipped || 0).toLocaleString(getUiLocale())
|
||||||
|
: '';
|
||||||
|
}
|
||||||
const error = document.getElementById('cloudLogError');
|
const error = document.getElementById('cloudLogError');
|
||||||
error.hidden = !status.errorCode;
|
error.hidden = !status.errorCode;
|
||||||
error.textContent = status.errorCode ? localizeUiText(cloudLogErrors[status.errorCode] || cloudLogErrors.CONNECTION_FAILED) : '';
|
error.textContent = status.errorCode ? localizeUiText(cloudLogErrors[status.errorCode] || cloudLogErrors.CONNECTION_FAILED) : '';
|
||||||
@@ -6448,7 +6474,7 @@ async function refreshCloudLogStatus() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function configureCloudLog(enabled) {
|
async function configureCloudLog(enabled) {
|
||||||
if (cloudLogBusy) return;
|
if (cloudLogBusy || cloudLogBackfillBusy || cloudLogLastStatus?.backfillRunning) return;
|
||||||
cloudLogBusy = true;
|
cloudLogBusy = true;
|
||||||
const key = document.getElementById('cloudLogKeyInput');
|
const key = document.getElementById('cloudLogKeyInput');
|
||||||
document.getElementById('cloudLogActivateBtn').disabled = true;
|
document.getElementById('cloudLogActivateBtn').disabled = true;
|
||||||
@@ -6469,6 +6495,28 @@ async function configureCloudLog(enabled) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function backfillCloudLog() {
|
||||||
|
if (cloudLogBusy || cloudLogBackfillBusy || cloudLogLastStatus?.backfillRunning) return;
|
||||||
|
cloudLogBackfillBusy = true;
|
||||||
|
renderCloudLogStatus(cloudLogLastStatus);
|
||||||
|
try {
|
||||||
|
const response = await window.api.backfillCloudLog();
|
||||||
|
if (response?.status) renderCloudLogStatus(response.status);
|
||||||
|
if (response?.ok) {
|
||||||
|
showCopyToast(response.result?.added > 0
|
||||||
|
? 'Vorhandene Log-Einträge wurden zur Synchronisierung übernommen.'
|
||||||
|
: 'Keine fehlenden Log-Einträge gefunden.');
|
||||||
|
} else {
|
||||||
|
showCopyToast(cloudLogErrors[response?.errorCode] || cloudLogErrors.LOG_READ_FAILED, 6500, 'error');
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
showCopyToast(cloudLogErrors.LOG_READ_FAILED, 6500, 'error');
|
||||||
|
} finally {
|
||||||
|
cloudLogBackfillBusy = false;
|
||||||
|
await refreshCloudLogStatus();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function _renderLogPathsList(el) {
|
async function _renderLogPathsList(el) {
|
||||||
if (!el || !window.api || !window.api.getLogPaths) return;
|
if (!el || !window.api || !window.api.getLogPaths) return;
|
||||||
try {
|
try {
|
||||||
@@ -6851,20 +6899,30 @@ function renderSettings() {
|
|||||||
</div>
|
</div>
|
||||||
<div class="settings-section-label">Clouddrop-Log-Synchronisierung</div>
|
<div class="settings-section-label">Clouddrop-Log-Synchronisierung</div>
|
||||||
<div class="cloud-log-settings">
|
<div class="cloud-log-settings">
|
||||||
|
<div class="cloud-log-heading" aria-live="polite">
|
||||||
|
<div><span class="cloud-log-heading-label">Status</span><strong class="cloud-log-phase" id="cloudLogPhase" data-phase="disabled">Inaktiv</strong></div>
|
||||||
|
<span class="cloud-log-key-state" id="cloudLogKeyState" data-saved="false">Kein API-Key gespeichert</span>
|
||||||
|
</div>
|
||||||
<p class="hint">Erfolgreiche Uploads automatisch als TXT in einem Clouddrop-Ordner mit der öffentlichen IP-Adresse dieses Geräts speichern. Die Übertragung beginnt mit der Aktivierung und folgt dem gewählten Log-Datei-Modus.</p>
|
<p class="hint">Erfolgreiche Uploads automatisch als TXT in einem Clouddrop-Ordner mit der öffentlichen IP-Adresse dieses Geräts speichern. Die Übertragung beginnt mit der Aktivierung und folgt dem gewählten Log-Datei-Modus.</p>
|
||||||
<div class="cloud-log-key-row">
|
<div class="cloud-log-key-row">
|
||||||
<label for="cloudLogKeyInput">Clouddrop-API-Key</label>
|
<label for="cloudLogKeyInput">Clouddrop-API-Key</label>
|
||||||
<input type="password" class="key-input" id="cloudLogKeyInput" autocomplete="off" spellcheck="false" placeholder="API-Key eingeben">
|
<input type="password" class="key-input" id="cloudLogKeyInput" autocomplete="off" spellcheck="false" placeholder="API-Key eingeben">
|
||||||
|
<div class="cloud-log-key-actions">
|
||||||
<button class="btn btn-secondary" type="button" id="cloudLogActivateBtn">Prüfen und aktivieren</button>
|
<button class="btn btn-secondary" type="button" id="cloudLogActivateBtn">Prüfen und aktivieren</button>
|
||||||
<button class="btn btn-secondary" type="button" id="cloudLogDisableBtn">Deaktivieren</button>
|
<button class="btn btn-secondary" type="button" id="cloudLogDisableBtn">Deaktivieren</button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<p class="hint">API-Key ohne Zielordner-Bindung verwenden. Bei der Prüfung wird eine leere Testdatei im IP-Ordner erstellt. Die öffentliche IP wird über ipify ermittelt.</p>
|
<p class="hint">API-Key ohne Zielordner-Bindung verwenden. Bei der Prüfung wird eine leere Testdatei im IP-Ordner erstellt. Die öffentliche IP wird über ipify ermittelt.</p>
|
||||||
<dl class="cloud-log-status" aria-live="polite">
|
<dl class="cloud-log-status" aria-live="polite">
|
||||||
<div><dt>Status</dt><dd id="cloudLogPhase">Inaktiv</dd></div>
|
|
||||||
<div><dt>IP-Ordner</dt><dd id="cloudLogIp">—</dd></div>
|
<div><dt>IP-Ordner</dt><dd id="cloudLogIp">—</dd></div>
|
||||||
<div><dt>Zuletzt synchronisiert</dt><dd id="cloudLogLastSync">—</dd></div>
|
<div><dt>Zuletzt synchronisiert</dt><dd id="cloudLogLastSync">—</dd></div>
|
||||||
<div><dt>Ausstehende Dateien</dt><dd id="cloudLogPending">0</dd></div>
|
<div><dt>Ausstehende Log-Dateien</dt><dd id="cloudLogPending">0</dd></div>
|
||||||
</dl>
|
</dl>
|
||||||
|
<div class="cloud-log-backfill">
|
||||||
|
<div><strong>Vorhandene Upload-Logs</strong><p class="hint">Überträgt fehlende Einträge aus der aktuellen lokalen Log-Datei. Bereits übernommene Einträge werden übersprungen; laufende Uploads bleiben aktiv.</p></div>
|
||||||
|
<button class="btn btn-secondary" type="button" id="cloudLogBackfillBtn" disabled>Vorhandenes Log nachsynchronisieren</button>
|
||||||
|
<p class="hint" id="cloudLogBackfillResult" role="status" hidden></p>
|
||||||
|
</div>
|
||||||
<p class="hint" id="cloudLogError" role="status" hidden></p>
|
<p class="hint" id="cloudLogError" role="status" hidden></p>
|
||||||
</div>
|
</div>
|
||||||
<div class="settings-option verbose-logging-option">
|
<div class="settings-option verbose-logging-option">
|
||||||
@@ -7262,6 +7320,7 @@ function renderSettings() {
|
|||||||
void refreshCloudLogStatus();
|
void refreshCloudLogStatus();
|
||||||
document.getElementById('cloudLogActivateBtn')?.addEventListener('click', () => configureCloudLog(true));
|
document.getElementById('cloudLogActivateBtn')?.addEventListener('click', () => configureCloudLog(true));
|
||||||
document.getElementById('cloudLogDisableBtn')?.addEventListener('click', () => configureCloudLog(false));
|
document.getElementById('cloudLogDisableBtn')?.addEventListener('click', () => configureCloudLog(false));
|
||||||
|
document.getElementById('cloudLogBackfillBtn')?.addEventListener('click', backfillCloudLog);
|
||||||
const testWebhookBtn = document.getElementById('testWebhookBtn');
|
const testWebhookBtn = document.getElementById('testWebhookBtn');
|
||||||
if (testWebhookBtn) {
|
if (testWebhookBtn) {
|
||||||
testWebhookBtn.addEventListener('click', async () => {
|
testWebhookBtn.addEventListener('click', async () => {
|
||||||
|
|||||||
@@ -25,6 +25,22 @@
|
|||||||
['IP-Ordner', 'IP folder'],
|
['IP-Ordner', 'IP folder'],
|
||||||
['Zuletzt synchronisiert', 'Last synced'],
|
['Zuletzt synchronisiert', 'Last synced'],
|
||||||
['Ausstehende Dateien', 'Pending files'],
|
['Ausstehende Dateien', 'Pending files'],
|
||||||
|
['Ausstehende Log-Dateien', 'Pending log files'],
|
||||||
|
['API-Key gespeichert', 'API key saved'],
|
||||||
|
['Kein API-Key gespeichert', 'No API key saved'],
|
||||||
|
['Vorhandene Upload-Logs', 'Existing upload logs'],
|
||||||
|
['Vorhandenes Log nachsynchronisieren', 'Sync existing log entries'],
|
||||||
|
['Vorhandenes Log wird eingelesen…', 'Reading existing log entries…'],
|
||||||
|
['Überträgt fehlende Einträge aus der aktuellen lokalen Log-Datei. Bereits übernommene Einträge werden übersprungen; laufende Uploads bleiben aktiv.', 'Transfers missing entries from the current local log file. Previously imported entries are skipped; running uploads remain active.'],
|
||||||
|
['Neu übernommen', 'Newly imported'],
|
||||||
|
['Bereits vorhanden', 'Already present'],
|
||||||
|
['Vorhandene Log-Einträge wurden zur Synchronisierung übernommen.', 'Existing log entries have been queued for synchronization.'],
|
||||||
|
['Keine fehlenden Log-Einträge gefunden.', 'No missing log entries found.'],
|
||||||
|
['Bitte die CloudDrop-Verbindung zuerst prüfen und aktivieren.', 'Please verify and enable the CloudDrop connection first.'],
|
||||||
|
['Die aktuelle lokale Upload-Log-Datei wurde noch nicht angelegt.', 'The current local upload log file has not been created yet.'],
|
||||||
|
['Die aktuelle lokale Upload-Log-Datei konnte nicht vollständig gelesen werden. Bereits übernommene Einträge bleiben gespeichert.', 'The current local upload log file could not be read completely. Previously imported entries remain saved.'],
|
||||||
|
['Die Upload-Log-Datei überschreitet das sichere Leselimit.', 'The upload log file exceeds the safe reading limit.'],
|
||||||
|
['Die Nachsynchronisierung wurde beendet. Bereits übernommene Einträge bleiben gespeichert.', 'Backfill has stopped. Previously imported entries remain saved.'],
|
||||||
['Noch nicht synchronisiert', 'Not synced yet'],
|
['Noch nicht synchronisiert', 'Not synced yet'],
|
||||||
['Verbindung wird geprüft…', 'Checking connection…'],
|
['Verbindung wird geprüft…', 'Checking connection…'],
|
||||||
['Wird synchronisiert…', 'Syncing…'],
|
['Wird synchronisiert…', 'Syncing…'],
|
||||||
|
|||||||
+26
-6
@@ -5532,16 +5532,36 @@ input[type="checkbox"] {
|
|||||||
margin-bottom: 16px;
|
margin-bottom: 16px;
|
||||||
}
|
}
|
||||||
.cloud-log-settings > .hint { margin: 0 0 12px; line-height: 1.5; }
|
.cloud-log-settings > .hint { margin: 0 0 12px; line-height: 1.5; }
|
||||||
.cloud-log-key-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 12px; }
|
.cloud-log-heading { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; padding-bottom: 16px; border-bottom: 1px solid var(--border); }
|
||||||
.cloud-log-key-row label { flex: 0 0 160px; font-size: 12px; }
|
.cloud-log-heading > div { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; min-width: 0; }
|
||||||
.cloud-log-key-row input { flex: 1 1 220px; min-width: 150px; }
|
.cloud-log-heading-label { font-size: 13px; color: var(--text-muted); }
|
||||||
.cloud-log-status { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 20px; margin: 0; }
|
.cloud-log-phase { display: inline-flex; align-items: center; gap: 9px; min-height: 38px; padding: 8px 12px; border: 1px solid var(--border); border-radius: 6px; background: var(--bg-input); font-size: 15px; line-height: 1.4; overflow-wrap: anywhere; }
|
||||||
|
.cloud-log-phase::before { content: ''; width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; background: currentColor; }
|
||||||
|
.cloud-log-phase[data-phase="ready"] { color: #a6e8c2; background: #23382e; border-color: #3e6650; }
|
||||||
|
.cloud-log-phase[data-phase="syncing"], .cloud-log-phase[data-phase="checking"] { color: #c6d8ff; background: #29354a; border-color: #51668a; }
|
||||||
|
.cloud-log-phase[data-phase="error"] { color: #ffb1b1; background: #432b2b; border-color: #754747; }
|
||||||
|
.cloud-log-key-state { display: inline-flex; align-items: center; gap: 8px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px; font-size: 13px; line-height: 1.4; }
|
||||||
|
.cloud-log-key-state[data-saved="true"] { color: #a6e8c2; }
|
||||||
|
.cloud-log-key-state[data-saved="true"]::before { content: '✓'; font-weight: 700; }
|
||||||
|
.cloud-log-key-state[data-saved="false"] { color: var(--text-muted); }
|
||||||
|
.cloud-log-key-row { display: grid; grid-template-columns: 150px minmax(0, 1fr); gap: 10px; align-items: center; margin-bottom: 12px; }
|
||||||
|
.cloud-log-key-row label { font-size: 13px; }
|
||||||
|
.cloud-log-key-row input { width: 100%; min-width: 0; }
|
||||||
|
.cloud-log-key-actions { grid-column: 2; display: flex; flex-wrap: wrap; gap: 10px; }
|
||||||
|
.cloud-log-status { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px 20px; margin: 18px 0 0; }
|
||||||
.cloud-log-status > div { min-width: 0; }
|
.cloud-log-status > div { min-width: 0; }
|
||||||
.cloud-log-status dt { color: var(--text-muted); font-size: 12px; margin-bottom: 4px; }
|
.cloud-log-status dt { color: var(--text-muted); font-size: 12px; margin-bottom: 4px; }
|
||||||
.cloud-log-status dd { margin: 0; font-size: 13px; overflow-wrap: anywhere; }
|
.cloud-log-status dd { margin: 0; font-size: 14px; font-weight: 600; overflow-wrap: anywhere; }
|
||||||
|
.cloud-log-backfill { display: flex; flex-wrap: wrap; align-items: center; gap: 14px; margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--border); }
|
||||||
|
.cloud-log-backfill > div { flex: 1 1 260px; min-width: 0; }
|
||||||
|
.cloud-log-backfill strong { font-size: 14px; }
|
||||||
|
.cloud-log-backfill .hint { margin: 6px 0 0; font-size: 12px; line-height: 1.6; }
|
||||||
|
.cloud-log-backfill > button { max-width: 100%; white-space: normal; min-height: 38px; }
|
||||||
|
.cloud-log-backfill > p { flex: 0 0 100%; }
|
||||||
.cloud-log-settings #cloudLogError:not([hidden]) { margin: 12px 0 0; padding: 10px; border: 1px solid var(--border); border-radius: 5px; }
|
.cloud-log-settings #cloudLogError:not([hidden]) { margin: 12px 0 0; padding: 10px; border: 1px solid var(--border); border-radius: 5px; }
|
||||||
@media (max-width: 900px) {
|
@media (max-width: 900px) {
|
||||||
.cloud-log-key-row label { flex-basis: 100%; }
|
.cloud-log-key-row { grid-template-columns: minmax(0, 1fr); }
|
||||||
|
.cloud-log-key-actions { grid-column: 1; }
|
||||||
.cloud-log-status { grid-template-columns: minmax(0, 1fr); }
|
.cloud-log-status { grid-template-columns: minmax(0, 1fr); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user