diff --git a/install.js b/install.js index db9f546..16d7353 100644 --- a/install.js +++ b/install.js @@ -6,47 +6,32 @@ const got = require('got'); const tmp = require('tmp'); const config = require('./config'); -const utils = require('./utils'); -const CDN_URL = 'https://www.googleapis.com/download/storage/v1/b/chromium-browser-snapshots/o/'; +const CDN_URL = 'https://download-chromium.appspot.com/dl/OS_TYPE?type=snapshots'; function getOsCdnUrl() { - let url = CDN_URL; + let osType = ''; const platform = process.platform; if (platform === 'linux') { - url += 'Linux'; + osType += 'Linux'; if (process.arch === 'x64') { - url += '_x64'; + osType += '_x64'; } } else if (platform === 'win32') { - url += 'Win'; + osType += 'Win'; if (process.arch === 'x64') { - url += '_x64'; + osType += '_x64'; } } else if (platform === 'darwin') { - url += 'Mac'; + osType += 'Mac'; } else { console.log('Unknown platform or architecture found:', process.platform, process.arch); throw new Error('Unsupported platform'); } - return url; -} - -function getLatestRevisionNumber() { - return new Promise((resolve, reject) => { - const url = getOsCdnUrl() + '%2FLAST_CHANGE?alt=media'; - got(url) - .then(response => { - resolve(response.body); - }) - .catch(err => { - console.log('An error occured while trying to retrieve latest revision number', err); - reject(err); - }); - }); + return CDN_URL.replace(/OS_TYPE/, osType); } function createTempFile() { @@ -62,12 +47,12 @@ function createTempFile() { }); } -function downloadChromiumRevision(revision) { +function downloadChromium() { return new Promise((resolve, reject) => { createTempFile() .then(path => { console.log('Downloading Chromium archive from Google CDN'); - const url = getOsCdnUrl() + `%2F${revision}%2F` + utils.getOsChromiumFolderName() + '.zip?alt=media'; + const url = getOsCdnUrl(); got.stream(url) .on('error', error => { console.log('An error occurred while trying to download Chromium archive', error); @@ -100,8 +85,7 @@ function unzipArchive(archivePath, outputFolder) { }); } -module.exports = getLatestRevisionNumber() - .then(downloadChromiumRevision) +module.exports = downloadChromium() .then(path => unzipArchive(path, config.BIN_OUT_PATH)) .catch(err => console.error('An error occurred while trying to setup Chromium. Resolve all issues and restart the process', err));