Implement cleanup of old compressed CSV files after successful write in CMS

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 20e343c625
commit cee9fb468f

View File

@@ -82,6 +82,14 @@ export default defineEventHandler(async (event) => {
if (st.size !== expectedSize) {
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) {
// best-effort cleanup
try { await fs.unlink(tmpPath) } catch (_e2) {}