Skip to content

Commit

Permalink
fix: yml with channel name return 404 (ArekSredzki#365)
Browse files Browse the repository at this point in the history
  • Loading branch information
winrey committed Apr 16, 2024
1 parent 042567b commit 9c5a681
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 11 deletions.
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
18 changes: 14 additions & 4 deletions config/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,14 @@ 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(.*\\.yml)': {
controller: 'VersionController',
action: 'electronUpdaterYmlFile',
skipAssets: false,
},
'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 +69,16 @@ 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(.*\\.yml)': {
controller: 'VersionController',
action: 'electronUpdaterYmlFile',
skipAssets: false,
},

'GET /notes/:version/:flavor?': 'VersionController.releaseNotes',

Expand Down

0 comments on commit 9c5a681

Please sign in to comment.