-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
62 lines (53 loc) · 1.73 KB
/
Copy pathindex.js
File metadata and controls
62 lines (53 loc) · 1.73 KB
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
var readline = require('readline');
var AWS = require('aws-sdk');
var s3 = new AWS.S3();
var urlPrefix = 'http://dm8eklel4s62k.cloudfront.net/images/';
var foldersRegex = /images\/(small|medium|large)\/(.*)/;
function search(term, nextMarker, acc) {
var settings = {
Bucket: 'polaris-assets',
Prefix: 'images'
};
if (nextMarker) {
settings['Marker'] = nextMarker;
}
s3.listObjects(settings, function(err, data) {
var marker;
var collection = acc;
if (acc) {
collection = acc;
} else {
collection = {};
collection['panelImage'] = collection['tileImage'] = {};
}
data.Contents.forEach(function(item) {
marker = item.Key;
if (item.Key.toLowerCase().indexOf(term.toLowerCase()) > -1) {
var parts = item.Key.match(foldersRegex);
if (parts) {
var size = parts[1];
var filename = encodeURIComponent(parts[2]);
collection['panelImage'][size] = urlPrefix + size + "/" + filename;
}
}
});
if (data.IsTruncated) {
search(term, marker, collection);
} else {
console.log('"tileImage":', JSON.stringify(collection['tileImage'], null, ' ') + ',');
console.log('"panelImage":', JSON.stringify(collection['panelImage'], null, ' ') + ',');
promptForSearch();
}
});
}
function promptForSearch() {
var rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
rl.question("Search: ", function(answer) {
rl.close();
search(answer);
});
}
promptForSearch();