-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackend.js
More file actions
51 lines (43 loc) · 1.31 KB
/
Copy pathbackend.js
File metadata and controls
51 lines (43 loc) · 1.31 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
// IMDB -- backend.js
var http = require('blaast/simple-http');
var QS = require('querystring');
var _ = require('underscore');
var scaling = new (require('blaast/scaling').Scaling)();
app.message(function(client, action, data) {
if (action === 'search') {
//http://www.imdbapi.com/?t=dark%20night&plot=short&tomatoes=true
var param = {plot: 'short', r: 'json', t: data.title, tomatoes:'true'};
if (data.year && data.year.length !== 0) {
param = _.extend(param, {y: data.year});
}
var url = "http://www.imdbapi.com/?" + QS.stringify(param);
console.log('url : ' + url);
http.get(url, { type: 'binary' }, {
ok: function(data) {
console.log(data);
data = JSON.parse(data);
client.msg('search', data);
},
error: function(err) {
client.msg('search', {error: err});
}
});
}
});
app.setResourceHandler(function(request, response) {
app.debug('Client requested resource-id=' + request.id);
function sendReply(response, error, imageType, data) {
if (error) {
app.warn('Failed to load image: ' + error);
response.failed();
} else {
app.debug('Loaded image.');
response.reply(imageType, data);
}
}
scaling.scale(request.id, request.display_width, request.display_height, 'image/jpeg',
function(err, data) {
sendReply(response, err, 'image/jpeg', data);
}
);
});