2017-07-29 21:33:08 +00:00
|
|
|
'use strict'
|
|
|
|
|
2018-03-05 20:49:36 +00:00
|
|
|
/* 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')
|
|
|
|
|
2017-08-14 00:33:06 +00:00
|
|
|
module.exports = (job) => {
|
2018-03-05 20:49:36 +00:00
|
|
|
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) => {
|
2018-03-05 20:49:36 +00:00
|
|
|
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')) {
|
2018-03-05 20:49:36 +00:00
|
|
|
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(() => {
|
2018-03-05 20:49:36 +00:00
|
|
|
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
|
|
|
})
|
|
|
|
}
|