forked from alpha2319/cloudjot-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmicroService.js
More file actions
37 lines (26 loc) · 978 Bytes
/
microService.js
File metadata and controls
37 lines (26 loc) · 978 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
const {deleteUploadFile} = require('./s3.js')
var Record = require("./models/record");
var File = require("./models/file");
require('dotenv').config()
setInterval(async ()=>{
try{
let record = await Record.find({});
if(record){
for(let i=0;i<record.length;i++){
if( record[i].age >= 432000000){
let files = await File.find({record:record[i].id});
if(files){
for(let j=0;j<files.length;j++){
const result = await deleteUploadFile(files[j].key);
await File.findByIdAndRemove(files[j]._id)
console.log('File deleted'+ result)
}
}
}
}
}
}
catch(e){
console.log(e)
}
},900000)