From 9c5a6816d2930edb9f9192a4f45350b95ce13d71 Mon Sep 17 00:00:00 2001 From: Winrey Date: Tue, 16 Apr 2024 19:10:44 +0800 Subject: [PATCH 1/3] fix: yml with channel name return 404 (#365) --- api/controllers/VersionController.js | 37 ++++++++++++++++++++++------ config/routes.js | 18 +++++++++++--- 2 files changed, 44 insertions(+), 11 deletions(-) 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..343e8f5e 100644 --- a/config/routes.js +++ b/config/routes.js @@ -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', @@ -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', From 6f38a875f68eeb4ee41a2ec1d85eee0e2dbee775 Mon Sep 17 00:00:00 2001 From: Winrey Date: Wed, 17 Apr 2024 13:12:21 +0800 Subject: [PATCH 2/3] fix: filter yaml --- config/routes.js | 8 ++++++-- package.json | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/config/routes.js b/config/routes.js index 343e8f5e..27505fce 100644 --- a/config/routes.js +++ b/config/routes.js @@ -53,10 +53,12 @@ module.exports.routes = { 'GET /update/:platform/latest.yml': 'VersionController.electronUpdaterWin', // GET /update/:platform/:channel-mac.yml // GET /update/:platform/:channel.yml - 'GET /update/:platform/:channelFileName(.*\\.yml)': { + 'GET /update/:platform/:channelFileName': { controller: 'VersionController', action: 'electronUpdaterYmlFile', skipAssets: false, + // Skip not ending with yml / yaml + skipRegex: /^(?!.*\.(yml|yaml)$).*$/, }, 'GET /update/:platform/:version': 'VersionController.general', 'GET /update/:platform/:channel/latest.yml': 'VersionController.electronUpdaterWin', @@ -74,10 +76,12 @@ module.exports.routes = { '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)': { + 'GET /update/flavor/:flavor/:platform/:channelFileName': { controller: 'VersionController', action: 'electronUpdaterYmlFile', skipAssets: false, + // Skip not ending with yml / yaml + skipRegex: /^(?!.*\.(yml|yaml)$).*$/, }, '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", From 20ea2cdecfb131d3132646601842708ecd3f565e Mon Sep 17 00:00:00 2001 From: Winrey Date: Mon, 22 Apr 2024 12:21:00 +0800 Subject: [PATCH 3/3] chore: allow query for yml file --- config/routes.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/config/routes.js b/config/routes.js index 27505fce..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' }, @@ -58,7 +60,7 @@ module.exports.routes = { action: 'electronUpdaterYmlFile', skipAssets: false, // Skip not ending with yml / yaml - skipRegex: /^(?!.*\.(yml|yaml)$).*$/, + skipRegex: notYamlRegex, }, 'GET /update/:platform/:version': 'VersionController.general', 'GET /update/:platform/:channel/latest.yml': 'VersionController.electronUpdaterWin', @@ -81,7 +83,7 @@ module.exports.routes = { action: 'electronUpdaterYmlFile', skipAssets: false, // Skip not ending with yml / yaml - skipRegex: /^(?!.*\.(yml|yaml)$).*$/, + skipRegex: notYamlRegex, }, 'GET /notes/:version/:flavor?': 'VersionController.releaseNotes',