ConversionOutputCleaner.js 613 B

1234567891011121314151617181920212223
  1. import fs from 'node:fs/promises'
  2. import Path from 'node:path'
  3. import logger from '@overleaf/logger'
  4. import Settings from '@overleaf/settings'
  5. const TTL_MS = 60 * 1000
  6. function scheduleCleanup(conversionId, ttlMs = TTL_MS) {
  7. const conversionOutputDir = Path.join(Settings.path.outputDir, conversionId)
  8. setTimeout(() => {
  9. fs.rm(conversionOutputDir, { recursive: true, force: true }).catch(err => {
  10. logger.warn(
  11. { err, conversionId, conversionOutputDir },
  12. 'failed to clean up conversion output directory'
  13. )
  14. })
  15. }, ttlMs)
  16. }
  17. export default {
  18. TTL_MS,
  19. scheduleCleanup,
  20. }