| 14 | |
| 15 | |
| 16 | function removeFiles(appId, curr) { |
| 17 | try { |
| 18 | const collectionName = 'File'; |
| 19 | const collectionId = mongoUtil.collection.getId(appId, collectionName); |
| 20 | const collection = config.mongoClient.db(appId).collection(collectionId); |
| 21 | const query = { expires: { $lt: curr, $exists: true, $ne: null } }; |
| 22 | const promises = []; |
| 23 | collection.find(query).toArray().then((res) => { |
| 24 | for (let i = 0; i < res.length; i++) { |
| 25 | promises.push(fileService.delete(appId, res[i], null, true)); |
| 26 | } |
| 27 | q.all(promises).then(() => {}, () => {}); |
| 28 | }, () => {}); |
| 29 | } catch (err) { |
| 30 | winston.log('error', { error: String(err), stack: new Error().stack }); |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | function mongodb(appId, collectionName, curr) { |
| 35 | try { |