-
Notifications
You must be signed in to change notification settings - Fork 0
/
slack-deleter.js
75 lines (60 loc) · 1.61 KB
/
slack-deleter.js
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
var http = require("https");
var token = '';//Add token here
var today = new Date();
var thirtyDaysAgo = Math.floor(today.setDate(today.getDate()-150) / 1000);
var host = 'slack.com';
var getPath = '/api/files.list?token=' + token + '&ts_to=' + thirtyDaysAgo + '&count=1000';
var fileIDs = []
var options = {
"method": "GET",
"hostname": host,
"port": null,
"path": getPath,
"headers": {
"cache-control": "no-cache"
},
"timeout": 50000
};
var req = http.request(options, function (res) {
var chunks = [];
res.on("data", function (chunk) {
chunks.push(chunk);
});
res.on("end", function () {
var body = JSON.parse(Buffer.concat(chunks));
var files = body.files;
for (var i = 0; i < files.length; i++) {
fileIDs.push(files[i].id);
}
console.log(fileIDs.length);
deleteFiles(fileIDs);
});
});
req.end();
function deleteFiles(ids) {
var totalFiles = ids.length;
for (var i = 0; i < ids.length; i++) {
deleteRequest(ids[i], i, totalFiles);
}
}
function deleteRequest(id, count, totalFiles) {
var options = {
"method": "GET",
"hostname": "slack.com",
"port": null,
"path": "/api/files.delete?token=" + token + "&file=" + id,
"headers": {
"cache-control": "no-cache",
"postman-token": "85a6dc06-7c93-02c9-e107-9c15494178c5"
},
"timeout": 50000
};
var req = http.request(options, function (res) {
var chunks = [];
res.on("data", function (chunk) {
var response = JSON.parse(chunk.toString())['ok'];
console.log(count + ' of ' + totalFiles + ' - ' + id + ' ' + response);
});
});
req.end();
}