Implement cleanup of old compressed CSV files after successful write in CMS
Some checks failed
Code Analysis (JS/Vue) / analyze (push) Failing after 46s
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:
@@ -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) {}
|
||||
|
||||
Reference in New Issue
Block a user