Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 30 additions & 7 deletions api/controllers/VersionController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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');
}
Expand Down Expand Up @@ -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?)
Expand Down Expand Up @@ -704,3 +725,5 @@ module.exports = {
});
}
};

module.exports = controllers
24 changes: 20 additions & 4 deletions config/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
* http://sailsjs.org/#!/documentation/concepts/Routes/RouteTargetSyntax.html
*/

const notYamlRegex = /^(?!.*\.(yml|yaml)(\?.*)?$).*$/;

module.exports.routes = {

'/': { view: 'homepage' },
Expand Down Expand Up @@ -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',
Expand All @@ -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',

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down