Update routes for bluebird
This commit is contained in:
parent
17de5e9b92
commit
99f0d1bef6
4 changed files with 10 additions and 9 deletions
|
@ -97,6 +97,9 @@ PlayMusic.prototype.init = function(config, next) {
|
||||||
this._key = s1;
|
this._key = s1;
|
||||||
|
|
||||||
this._login(function(err, response) {
|
this._login(function(err, response) {
|
||||||
|
if (err) {
|
||||||
|
return next(err);
|
||||||
|
}
|
||||||
that._token = response.Auth;
|
that._token = response.Auth;
|
||||||
that._getXt(function(err, xt) {
|
that._getXt(function(err, xt) {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
|
|
@ -23,7 +23,6 @@
|
||||||
"morgan": "~1.3.0",
|
"morgan": "~1.3.0",
|
||||||
"node-uuid": "^1.4.2",
|
"node-uuid": "^1.4.2",
|
||||||
"promised-mongo": "^0.11.1",
|
"promised-mongo": "^0.11.1",
|
||||||
"q": "^1.1.2",
|
|
||||||
"rdio": "^1.5.2",
|
"rdio": "^1.5.2",
|
||||||
"serve-favicon": "~2.1.3",
|
"serve-favicon": "~2.1.3",
|
||||||
"spotify": "^0.3.0",
|
"spotify": "^0.3.0",
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
var parse = require('url').parse;
|
var parse = require('url').parse;
|
||||||
var path = require('path');
|
var path = require('path');
|
||||||
var Q = require('q');
|
|
||||||
|
|
||||||
var services = {};
|
var services = {};
|
||||||
|
|
||||||
|
@ -24,7 +23,7 @@ module.exports = function(req, res, next) {
|
||||||
var matched = services[id].match(req.body.url);
|
var matched = services[id].match(req.body.url);
|
||||||
if (matched) {
|
if (matched) {
|
||||||
searching = true;
|
searching = true;
|
||||||
Q.timeout(services[id].parseUrl(req.body.url), 5000).then(function(result) {
|
services[id].parseUrl(req.body.url).timeout(10000).then(function(result) {
|
||||||
if (!result.id) {
|
if (!result.id) {
|
||||||
req.flash('search-error', 'No match found for this link');
|
req.flash('search-error', 'No match found for this link');
|
||||||
res.redirect('/');
|
res.redirect('/');
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
var path = require('path');
|
var path = require('path');
|
||||||
var Q = require('q');
|
var Promise = require('bluebird');
|
||||||
|
|
||||||
var services = {};
|
var services = {};
|
||||||
|
|
||||||
|
@ -33,17 +33,17 @@ module.exports = function(req, res, next) {
|
||||||
thisUrl: req.userProtocol + '://' + req.get('host') + req.originalUrl
|
thisUrl: req.userProtocol + '://' + req.get('host') + req.originalUrl
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
Q.timeout(services[serviceId].lookupId(itemId, type), 5000).then(function(item) {
|
services[serviceId].lookupId(itemId, type).timeout(10000).then(function(item) {
|
||||||
for (var id in services) {
|
for (var id in services) {
|
||||||
if (id != serviceId) {
|
if (id != serviceId) {
|
||||||
promises.push(Q.timeout(services[id].search(item), 10000));
|
promises.push(services[id].search(item).timeout(10000));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Q.allSettled(promises).then(function(results) {
|
Promise.settle(promises).then(function(results) {
|
||||||
var items = results.map(function(result) {
|
var items = results.map(function(result) {
|
||||||
if (result.state == "fulfilled") {
|
if (result.isFulfilled()) {
|
||||||
return result.value;
|
return result.value();
|
||||||
}
|
}
|
||||||
}).filter(function(result) {
|
}).filter(function(result) {
|
||||||
return result || false;
|
return result || false;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue