diff --git a/lib/index.js b/lib/index.js index cc1dc526..f3af6495 100644 --- a/lib/index.js +++ b/lib/index.js @@ -161,6 +161,7 @@ module.exports = function nuts(opts) { var fullUrl = getFullUrl(req); var platform = req.params.platform; var tag = req.params.version; + var channel = req.query.channel; Q() .then(function() { @@ -170,9 +171,9 @@ module.exports = function nuts(opts) { platform = platforms.detect(platform); return versions.filter({ - tag: '>='+tag, + tag: tag, platform: platform, - channel: '*' + channel: channel }); }) .then(function(versions) { @@ -197,15 +198,16 @@ module.exports = function nuts(opts) { var fullUrl = getFullUrl(req); var platform = 'win_32'; var tag = req.params.version; + var channel = req.query.channel; Q() .then(function() { platform = platforms.detect(platform); return versions.filter({ - tag: '>='+tag, + tag: tag, platform: platform, - channel: '*' + channel: channel }); }) .then(function(versions) { @@ -251,7 +253,7 @@ module.exports = function nuts(opts) { Q() .then(function() { return versions.filter({ - tag: tag? '>='+tag : '*', + tag: tag? tag : '*', channel: '*' }); }) diff --git a/lib/versions.js b/lib/versions.js index 26db082d..b32621f3 100644 --- a/lib/versions.js +++ b/lib/versions.js @@ -88,7 +88,7 @@ module.exports = function(github, opts) { opts = _.defaults(opts || {}, { tag: 'latest', platform: null, - channel: 'stable' + channel: extractChannel(opts.tag) }); if (opts.platform) opts.platform = platforms.detect(opts.platform); @@ -97,18 +97,24 @@ module.exports = function(github, opts) { return _.chain(versions) .filter(function(version) { // Check channel - if (opts.channel != '*' && version.channel != opts.channel) return false; + if (!channelsMatch(version.channel, opts.channel)) return false; // Not available for requested paltform if (opts.platform && !platforms.satisfies(opts.platform, _.pluck(version.platforms, 'type'))) return false; // Check tag satisfies request version - return opts.tag == 'latest' || semver.satisfies(version.tag, opts.tag); + return opts.tag == 'latest' || (semver.rcompare(version.tag, opts.tag) < 0); }) .value(); }); } + function channelsMatch(versionChannel, currentChannel) { + if ((currentChannel === '*') || + (currentChannel === versionChannel) || + (currentChannel != 'stable' && versionChannel == 'stable')) return true; + } + // Resolve a platform function resolveVersion(opts) { return filterVersions(opts)