diff --git a/api/controllers/VersionController.js b/api/controllers/VersionController.js index a50919c2..838e0afc 100644 --- a/api/controllers/VersionController.js +++ b/api/controllers/VersionController.js @@ -10,11 +10,11 @@ var url = require('url'); var Promise = require('bluebird'); var semver = require('semver'); var compareVersions = require('compare-versions'); +var channelsConfig = require('../../config/channels'); const availabilityFilter = () => ({ '<=': (new Date()).toISOString() }); -module.exports = { - +const controllers = { /** * Set availability date of specified version * @@ -450,9 +450,9 @@ module.exports = { * (GET /update/flavor/:flavor/:platform/:channel.yml) * (GET /update/flavor/:flavor/:platform/:channel/latest.yml) */ - electronUpdaterWin: function(req, res) { + electronUpdaterWin: function(req, res, channel) { var platform = req.param('platform'); - var channel = req.param('channel') || 'stable'; + channel = channel || req.param('channel') || 'stable'; const flavor = req.params.flavor || 'default'; if (!platform) { @@ -539,11 +539,11 @@ module.exports = { * (GET /update/flavor/:flavor/:platform/:channel-mac.yml) * (GET /update/flavor/:flavor/:platform/:channel/latest-mac.yml) */ - electronUpdaterMac: function(req, res) { + electronUpdaterMac: function(req, res, channel) { var platform = req.param('platform'); - var channel = req.param('channel') || 'stable'; + channel = channel || req.param('channel') || 'stable'; const flavor = req.params.flavor || 'default'; - + if (!platform) { return res.badRequest('Requires `platform` parameter'); } @@ -617,6 +617,27 @@ module.exports = { }); }, + + electronUpdaterYmlFile: function(req, res) { + const fileName = req.param('channelFileName'); + const fileWithoutExt = fileName.replace('.yml', '').replace('.yaml', ''); + const isMac = fileWithoutExt.endsWith('-mac'); + const pure = fileWithoutExt.replace('-mac', '').replace('-win', ''); + let channel = req.param('channel') || 'stable'; + if (pure !== 'latest') { + if (!channelsConfig.channels.includes(pure)) { + return res.notFound(); + } + channel = pure; + } + + if (isMac) { + return controllers.electronUpdaterMac(req, res, channel); + } + + return controllers.electronUpdaterWin(req, res, channel); + }, + /** * Get release notes for a specific version * (GET /notes/:version/:flavor?) @@ -704,3 +725,5 @@ module.exports = { }); } }; + +module.exports = controllers diff --git a/config/routes.js b/config/routes.js index 3ee96148..eefe4bf3 100644 --- a/config/routes.js +++ b/config/routes.js @@ -20,6 +20,8 @@ * http://sailsjs.org/#!/documentation/concepts/Routes/RouteTargetSyntax.html */ +const notYamlRegex = /^(?!.*\.(yml|yaml)(\?.*)?$).*$/; + module.exports.routes = { '/': { view: 'homepage' }, @@ -50,9 +52,16 @@ module.exports.routes = { 'GET /update': 'VersionController.redirect', 'GET /update/:platform/latest-mac.yml': 'VersionController.electronUpdaterMac', - 'GET /update/:platform/:channel-mac.yml': 'VersionController.electronUpdaterMac', 'GET /update/:platform/latest.yml': 'VersionController.electronUpdaterWin', - 'GET /update/:platform/:channel.yml': 'VersionController.electronUpdaterWin', + // GET /update/:platform/:channel-mac.yml + // GET /update/:platform/:channel.yml + 'GET /update/:platform/:channelFileName': { + controller: 'VersionController', + action: 'electronUpdaterYmlFile', + skipAssets: false, + // Skip not ending with yml / yaml + skipRegex: notYamlRegex, + }, 'GET /update/:platform/:version': 'VersionController.general', 'GET /update/:platform/:channel/latest.yml': 'VersionController.electronUpdaterWin', 'GET /update/:platform/:channel/latest-mac.yml': 'VersionController.electronUpdaterMac', @@ -64,11 +73,18 @@ module.exports.routes = { 'GET /update/flavor/:flavor/:platform/:version/RELEASES': 'VersionController.windows', 'GET /update/flavor/:flavor/:platform/:version/:channel/RELEASES': 'VersionController.windows', 'GET /update/flavor/:flavor/:platform/latest.yml': 'VersionController.electronUpdaterWin', - 'GET /update/flavor/:flavor/:platform/:channel.yml': 'VersionController.electronUpdaterWin', 'GET /update/flavor/:flavor/:platform/:channel/latest.yml': 'VersionController.electronUpdaterWin', 'GET /update/flavor/:flavor/:platform/latest-mac.yml': 'VersionController.electronUpdaterMac', - 'GET /update/flavor/:flavor/:platform/:channel-mac.yml': 'VersionController.electronUpdaterMac', 'GET /update/flavor/:flavor/:platform/:channel/latest-mac.yml': 'VersionController.electronUpdaterMac', + // GET /update/flavor/:flavor/:platform/:channel-mac.yml + // GET /update/flavor/:flavor/:platform/:channel.yml + 'GET /update/flavor/:flavor/:platform/:channelFileName': { + controller: 'VersionController', + action: 'electronUpdaterYmlFile', + skipAssets: false, + // Skip not ending with yml / yaml + skipRegex: notYamlRegex, + }, 'GET /notes/:version/:flavor?': 'VersionController.releaseNotes', diff --git a/package.json b/package.json index f87ab617..7e2ace01 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "electron-release-server", "private": true, - "version": "2.1.3", + "version": "2.1.4", "description": "A version server for hosting and serving the your electron desktop app releases.", "dependencies": { "@sailshq/upgrade": "^1.0.9",