You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
890 B

  1. 'use strict'
  2. /* global wiki */
  3. const Promise = require('bluebird')
  4. const fs = Promise.promisifyAll(require('fs-extra'))
  5. const moment = require('moment')
  6. const path = require('path')
  7. module.exports = (job) => {
  8. return fs.readdirAsync(wiki.UPLTEMPPATH).then((ls) => {
  9. let fifteenAgo = moment().subtract(15, 'minutes')
  10. return Promise.map(ls, (f) => {
  11. return fs.statAsync(path.join(wiki.UPLTEMPPATH, f)).then((s) => { return { filename: f, stat: s } })
  12. }).filter((s) => { return s.stat.isFile() }).then((arrFiles) => {
  13. return Promise.map(arrFiles, (f) => {
  14. if (moment(f.stat.ctime).isBefore(fifteenAgo, 'minute')) {
  15. return fs.unlinkAsync(path.join(wiki.UPLTEMPPATH, f.filename))
  16. } else {
  17. return true
  18. }
  19. })
  20. })
  21. }).then(() => {
  22. wiki.logger.info('Purging temporary upload files: DONE')
  23. return true
  24. })
  25. }