Implement cleanup of old compressed CSV files after successful write in CMS
Some checks failed
Code Analysis (JS/Vue) / analyze (push) Failing after 46s

This commit adds logic to remove outdated `.gz` and `.br` files after a successful CSV write operation in the CMS. This ensures that users do not encounter inconsistent content due to leftover pre-compressed assets, enhancing data integrity and reliability in the application.
This commit is contained in:
Torsten Schulz (local)
2026-01-19 08:13:02 +01:00
parent 75f4262320
commit 27312cc118

View File

@@ -82,6 +82,14 @@ export default defineEventHandler(async (event) => {
if (st.size !== expectedSize) { if (st.size !== expectedSize) {
throw new Error(`Size mismatch after write. expected=${expectedSize} actual=${st.size}`) throw new Error(`Size mismatch after write. expected=${expectedSize} actual=${st.size}`)
} }
// Wenn beim Build pre-komprimierte Assets erzeugt wurden, können für CSVs
// noch alte `.gz`/`.br` Dateien liegen bleiben. Nach einem Update würden dann
// ggf. inkonsistente Inhalte ausgeliefert (Browser meldet Partial Transfer).
// Daher: nach erfolgreichem Schreiben alte Varianten entfernen.
for (const ext of ['.gz', '.br']) {
try { await fs.unlink(`${targetPath}${ext}`) } catch (_e3) {}
}
} catch (e) { } catch (e) {
// best-effort cleanup // best-effort cleanup
try { await fs.unlink(tmpPath) } catch (_e2) {} try { await fs.unlink(tmpPath) } catch (_e2) {}