-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresources-types.js
80 lines (72 loc) · 1.85 KB
/
resources-types.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
76
77
78
79
80
const request = require('request');
const uri = '';
const getResources = (callback) => {
request.get({ uri }, callback);
}
const attachmentTypes = (attachments) => {
if (!attachments) {
return [ 'no-attachments' ];
}
return Object.keys(attachments).map((key) => {
return attachments[key].content_type
});
}
const uniqueCount = (array) => {
return array.reduce((obj, item) => {
if (!obj[item]) {
obj[item] = 0;
}
obj[item]++;
return obj;
}, {});
}
const logResults = (allTypes) => {
const counts = uniqueCount(allTypes);
Object.keys(counts).forEach((key) => {
console.log(key, ': ', counts[key]);
});
}
const equalsTypes = (types) => {
// Uncomment to list resource titles of that type
const equalTypes = [
// 'application/msword',
// 'application/vnd.ms-excel',
// 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
// 'application/x-sh',
// 'application/vnd.android.package-archive',
// 'application/ogg',
// 'image/jpg',
// 'image/svg+xml',
// 'image/x-icon',
// 'image/png',
// 'image/jpeg'
// 'application/octet-stream'
// 'video/quicktime',
// 'video/x-flv',
// 'video/webm',
// 'video/flv',
// 'video/3gpp',
// 'video/ogg'
];
return types.reduce((isMatch, type) => {
return isMatch || (equalTypes.indexOf(type) > -1);
}, false);
}
const findLargest = (err, response) => {
let count = 0;
const allTypes = JSON.parse(response.body).rows.reduce((all, item, index, arr) => {
const doc = item.doc;
const types = attachmentTypes(doc._attachments);
if (equalsTypes(types)) {
count++;
console.log(doc.title);
}
if (types.length > 0) {
return all.concat(types);
}
return all;
}, []);
console.log('Total:' + count);
logResults(allTypes);
}
getResources(findLargest);