wikijs-fork/server/queues/upl-clear-temp.js

30 lines
890 B
JavaScript
Raw Normal View History

2017-07-29 21:33:08 +00:00
'use strict'
/* global WIKI */
2017-07-29 21:33:08 +00:00
const Promise = require('bluebird')
const fs = Promise.promisifyAll(require('fs-extra'))
const moment = require('moment')
const path = require('path')
module.exports = (job) => {
return fs.readdirAsync(WIKI.UPLTEMPPATH).then((ls) => {
2017-07-29 21:33:08 +00:00
let fifteenAgo = moment().subtract(15, 'minutes')
return Promise.map(ls, (f) => {
return fs.statAsync(path.join(WIKI.UPLTEMPPATH, f)).then((s) => { return { filename: f, stat: s } })
2017-07-29 21:33:08 +00:00
}).filter((s) => { return s.stat.isFile() }).then((arrFiles) => {
return Promise.map(arrFiles, (f) => {
if (moment(f.stat.ctime).isBefore(fifteenAgo, 'minute')) {
return fs.unlinkAsync(path.join(WIKI.UPLTEMPPATH, f.filename))
2017-07-29 21:33:08 +00:00
} else {
return true
}
})
})
2017-08-03 03:47:11 +00:00
}).then(() => {
WIKI.logger.info('Purging temporary upload files: DONE')
2017-08-03 03:47:11 +00:00
return true
2017-07-29 21:33:08 +00:00
})
}