-
Notifications
You must be signed in to change notification settings - Fork 0
/
backend.js
50 lines (40 loc) · 1.34 KB
/
backend.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
// 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://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20music.track.search%20where%20keyword%3D%22kangen%20band%22&format=json
var param = { format: 'json', q: 'select * from music.track.search(1) where keyword="'+data.title+'"'};
var url = "http://query.yahooapis.com/v1/public/yql?" + 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);
}
);
});