diff --git a/src/main/support-bundle.ts b/src/main/support-bundle.ts index ee153ed..0cdbe99 100644 --- a/src/main/support-bundle.ts +++ b/src/main/support-bundle.ts @@ -51,6 +51,27 @@ function addDirectoryIfExists(zip: AdmZip, dirPath: string, zipRoot: string): vo } } +/** Wie addDirectoryIfExists, aber nur Dateien die in den letzten maxAgeMs ms geaendert wurden. */ +function addRecentDirectoryFiles(zip: AdmZip, dirPath: string, zipRoot: string, maxAgeMs: number): number { + if (!fs.existsSync(dirPath)) { + return 0; + } + const cutoff = Date.now() - maxAgeMs; + let added = 0; + const entries = fs.readdirSync(dirPath, { withFileTypes: true }); + for (const entry of entries) { + if (!entry.isFile()) continue; + const fullPath = path.join(dirPath, entry.name); + try { + if (fs.statSync(fullPath).mtimeMs >= cutoff) { + zip.addLocalFile(fullPath, zipRoot, entry.name); + added += 1; + } + } catch { /* ignorieren */ } + } + return added; +} + function formatTimestampForFileName(date: Date): string { const y = date.getFullYear(); const mo = String(date.getMonth() + 1).padStart(2, "0"); @@ -164,10 +185,16 @@ export function buildSupportBundle(manager: DownloadManager, baseDir: string, op addFileIfExists(zip, getTraceLogPath(), "logs/trace.log"); addFileIfExists(zip, getTraceLogPath() ? `${getTraceLogPath()}.old` : null, "logs/trace.log.old"); + // Granulare Per-Item/-Package/-Session-Logs nur der letzten 8h. + // Vorher wurden alle logs-Unterordner rekursiv gepackt → tausende Item-Logs + // → 200+ MB, unhandlich zum Verschicken. Mit 8h-Fenster bleibt das Bundle + // klein genug und enthaelt alles fuer aktuelle Fehler + Rename-Probleme. + const SUPPORT_BUNDLE_LOG_WINDOW_MS = 8 * 60 * 60 * 1000; addDirectoryIfExists(zip, path.join(baseDir, "session-logs"), "logs/session-logs"); - addDirectoryIfExists(zip, path.join(baseDir, "package-logs"), "logs/package-logs"); - addDirectoryIfExists(zip, path.join(baseDir, "item-logs"), "logs/item-logs"); + addRecentDirectoryFiles(zip, path.join(baseDir, "package-logs"), "logs/package-logs", SUPPORT_BUNDLE_LOG_WINDOW_MS); + addRecentDirectoryFiles(zip, path.join(baseDir, "item-logs"), "logs/item-logs", SUPPORT_BUNDLE_LOG_WINDOW_MS); + // Live-Logs der aktiven Queue (aktuelle Session) immer vollstaendig mitsichern. for (const packageId of packageIds) { addFileIfExists(zip, manager.getPackageLogPath(packageId) || getPackageLogPath(packageId), `logs/live/package-${packageId}.txt`); }