-
Notifications
You must be signed in to change notification settings - Fork 0
/
screenshot.js
86 lines (75 loc) · 2.12 KB
/
screenshot.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
var fs = require('fs');
var url = phantom.args[0];
var settings = fs.read("settings.json");
var dir;
settings = JSON.parse(settings);
if (settings.mode == "dev") {
dir = settings.devPaths.webshotDir;
} else {
dir = settings.livePaths.webshotDir;
}
var filename = phantom.args[1];
var uA = settings.userAgents[Math.floor(Math.random() * settings.userAgents.length)];
var page;
var errors = [];
var response;
requestPage = function () {
page.settings.userAgent = uA;
page.viewportSize = {
width: 1270,
height: 1116
};
page.open(url, function (status) { // executed after
if (status !== "success" && status[0] !== 'success') {
console.log('{"status": "failure"}');
slimer.exit();
}
}).then(function () {
if (page.content.includes("Denied")) {
page.render(dir + filename + ".denied.png");
response = {
status: "denied",
filename: filename + ".denied.png"
};
//data.content = page.content;
//console.log('{"status": "denied"}');
console.log(JSON.stringify(response));
slimer.exit();
} else {
page.render(dir + filename + ".jpg", {
format: "jpeg",
quality: 25
});
response = {
status: "success",
filename: filename + ".jpg"
};
response.errors = errors;
console.log(JSON.stringify(response))
slimer.exit();
}
});
};
if (!url || !filename) {
console.log('{"status": "failed"}');
phantom.exit();
} else {
page = require('webpage').create();
var target = dir + filename + ".png";
requestPage();
}
page.onError = function (message, line, file) {
var error = {
"status": "error",
"message": message,
"line": line,
"file": file
};
errors.push(error);
};
if (!String.prototype.includes) {
String.prototype.includes = function () {
'use strict';
return String.prototype.indexOf.apply(this, arguments) !== -1;
};
}