Sort match results, fix xbox url parsing
This commit is contained in:
parent
89d0779751
commit
2d029f1a0f
2 changed files with 20 additions and 6 deletions
|
@ -62,8 +62,11 @@ module.exports.parseUrl = function(url) {
|
|||
var parsed = parse(url);
|
||||
var parts = parsed.path.split("/");
|
||||
var type = parts[1];
|
||||
var id = parts[4];
|
||||
|
||||
var idMatches = parts[4].match(/[\w\-]+/);
|
||||
var id = idMatches[0];
|
||||
if (!id) {
|
||||
return false;
|
||||
}
|
||||
return module.exports.lookupId("music." + id, type);
|
||||
}
|
||||
|
||||
|
|
|
@ -11,6 +11,17 @@ var routes = require('../views/app.jsx').routes;
|
|||
|
||||
var services = require('../lib/services');
|
||||
|
||||
var formatAndSort = function(matches, serviceId) {
|
||||
matches = Object.keys(matches).map(function (key) {return matches[key]});
|
||||
matches.sort(function(a, b) {
|
||||
return a.id && !b.id;
|
||||
}).sort(function(a, b) {
|
||||
return b.type == "video";
|
||||
}).sort(function(a, b) {
|
||||
return a.service != serviceId;
|
||||
});
|
||||
return matches;
|
||||
}
|
||||
|
||||
module.exports = function(req, res, next) {
|
||||
var serviceId = req.params.service;
|
||||
|
@ -46,22 +57,22 @@ module.exports = function(req, res, next) {
|
|||
});
|
||||
});
|
||||
return req.db.matches.save({_id: item.service + "$$" + item.id, created_at: new Date(), services:matches}).then(function() {
|
||||
var shares = Object.keys(matches).map(function (key) {return matches[key]});
|
||||
var shares = formatAndSort(matches, serviceId);
|
||||
Router.run(routes, req.url, function (Handler) {
|
||||
var App = React.createFactory(Handler);
|
||||
var content = React.renderToString(App({shares: shares}));
|
||||
var content = React.renderToString(new App({shares: shares}));
|
||||
res.send('<!doctype html>\n' + content.replace("</body></html>", "<script>var shares = " + JSON.stringify(shares) + "</script></body></html>"));
|
||||
});
|
||||
});
|
||||
})
|
||||
}
|
||||
var shares = Object.keys(doc.services).map(function (key) {return doc.services[key]});
|
||||
var shares = formatAndSort(doc.services, serviceId);
|
||||
if (req.params.format == "json") {
|
||||
return res.json({shares:shares});
|
||||
}
|
||||
Router.run(routes, req.url, function (Handler) {
|
||||
var App = React.createFactory(Handler);
|
||||
var content = React.renderToString(App({shares: shares}));
|
||||
var content = React.renderToString(new App({shares: shares}));
|
||||
res.send('<!doctype html>\n' + content.replace("</body></html>", "<script>var shares = " + JSON.stringify(shares) + "</script></body></html>"));
|
||||
});
|
||||
}).catch(function (error) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue