-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmobiletest.js
More file actions
60 lines (58 loc) · 2.16 KB
/
mobiletest.js
File metadata and controls
60 lines (58 loc) · 2.16 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
// Need to figure out the template issue with this
if (Meteor.isClient) {
Handlebars.registerHelper('eachProperty', function(context, options) {
var ret = "";
for(var prop in context)
{
if(prop!="image" && prop!="height") {
ret = ret + options.fn({property:prop,value:context[prop]});
}
}
return ret;
});
Template.res_normal.data = function () {return Session.get("normal");};
Template.res_mobile.data = function () {return Session.get("mobile");};
Template.hello.events({
'click button': function (e) {
var url = $("#url").val();
Session.set("normal",{"loading":"...","height":"0"});
Session.set("mobile",{"loading":"...","height":"0"});
Meteor.call("crawl",url, "normal",function(err,res){
Session.set("normal",res);
});
Meteor.call("crawl",url, "mobile",function(err,res){
Session.set("mobile",res);
});
}
});
}
// Server side seems to be complete
if (Meteor.isServer) {
Meteor.methods({
crawl: function (url,t) {
var fut = new Future();
console.log(url);
var pname = CryptoJS.MD5(url).toString() + ".png";
var params = {"analyze-css":true,"user-agent":"Mozilla/5.0 (Linux; U; Android 2.1-update1; en-us; SAMSUNG-SGH-I897/I897UCJH7 Build/ECLAIR) AppleWebKit/530.17 (KHTML, like Gecko) Version/4.0 Mobile Safari/530.17","viewport":"480x800","screenshot":"/tmp/"+pname};
if(t=="mobile") {
params["proxy"] = "173.193.215.18:8001";
}
phantomas(url,params,function(err,res){
var image_data = fs.readFileSync("/tmp/"+pname);
var image_b64 = new Buffer(image_data).toString('base64');
console.log("Done");
var ret = res["metrics"];
ret["image"] = image_b64;
ret["height"] = "800";
fut.return(res["metrics"]);
});
return fut.wait();
}
});
Meteor.startup(function () {
fs = Npm.require('fs');
Future = Npm.require('fibers/future');
phantomas = Meteor.require('phantomas');
// code to run on server at startup
});
}