This repository has been archived by the owner on Mar 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
106 lines (93 loc) · 2.62 KB
/
index.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
var aws = require('aws-sdk');
var builderMapsDone = false;
var config = require('./config.json');
var count = 0;
var currentIndex = 0;
var fs = require('fs');
var maps = [];
var request = require('request');
var webshot = require('webshot');
var interval;
var s3;
require('dotenv').config(); // Load in environment variables
aws.config.update({
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
region: process.env.AWS_REGION,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY
});
s3 = new aws.S3();
if (!fs.existsSync('./docs')) {
fs.mkdirSync('./docs');
}
function takeWebshot (map) {
var id = map.id;
var type;
var url;
if (map.table_name === 'builder_maps') {
type = 'Builder';
url = 'https://www.outerspatial.com/builder_maps/' + id + '/embed';
} else {
type = 'Paper';
url = 'https://www.outerspatial.com/paper_maps/' + id;
}
webshot(url, './docs/' + type.toLowerCase() + '-map-' + id + '.png', {
renderDelay: 5000,
windowSize: {
height: 500,
width: 500
}
}, function (error) {
if (error) {
console.log('Error taking webshot for ' + type + ' Map: ' + id);
} else {
console.log('Successfully created webshot for ' + type + ' Map: ' + id);
}
currentIndex++;
if (currentIndex < count) {
takeWebshot(maps[currentIndex]);
} else {
builderMapsDone = true;
}
});
}
request({
timeout: 30000,
url: 'https://api.outerspatial.com/v2/builder_maps/?access_token=' + process.env['OUTERSPATIAL_' + config.outerSpatialEnvironment.toUpperCase() + '_ACCESS_TOKEN'] + '&per_page=1000'
}, function (error, response, body) {
if (response) {
if (error || response.statusCode !== 200) {
console.log(response.statusCode);
} else {
maps = JSON.parse(body).data;
if (maps) {
count = maps.length;
takeWebshot(maps[currentIndex]);
}
}
} else {
console.log('No response');
}
});
interval = setInterval(function () {
if (builderMapsDone) {
clearInterval(interval);
request({
timeout: 30000,
url: 'https://api.outerspatial.com/v2/paper_maps/?access_token=' + process.env['OUTERSPATIAL_' + config.outerSpatialEnvironment.toUpperCase() + '_ACCESS_TOKEN'] + '&per_page=1000'
}, function (error, response, body) {
if (response) {
if (error || response.statusCode !== 200) {
console.log(response.statusCode);
} else {
maps = JSON.parse(body).data;
if (maps) {
count = maps.length;
takeWebshot(maps[currentIndex]);
}
}
} else {
console.log('No response');
}
});
}
}, 1000);