Skip to content

Commit

Permalink
add recommended files support from vercel#63
Browse files Browse the repository at this point in the history
  • Loading branch information
nickbeaulieu committed Jul 13, 2022
1 parent a06e6c5 commit 9ddf9e5
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,16 @@ module.exports = class Cache {
for (const asset of release.assets) {
const { name, browser_download_url, url, content_type, size } = asset

// Added new lines here
this.latest.files[name] = {
name,
api_url: url,
url: browser_download_url,
content_type,
size: Math.round(size / 1000000 * 10) / 10
}
// End new

if (name === 'RELEASES') {
try {
if (!this.latest.files) {
Expand Down
1 change: 1 addition & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ module.exports = config => {
router.get('/download/:platform', routes.downloadPlatform)
router.get('/update/:platform/:version', routes.update)
router.get('/update/win32/:version/RELEASES', routes.releases)
router.get('/files/:filename', routes.files);

return (req, res) => {
router(req, res, finalhandler(req, res))
Expand Down
21 changes: 21 additions & 0 deletions lib/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,27 @@ module.exports = ({ cache, config }) => {
res.end(content)
}

// ADDED this route
exports.files = async (req, res) => {
const { filename } = req.params;
const latest = await loadCache();

if (!latest.files[filename]) {
send(res, 404, `can't load ${filename}`)
return
}

if (shouldProxyPrivateDownload) {
proxyPrivateDownload(latest.files[filename], req, res);
return
}

res.writeHead(302, {
Location: latest.files[filename].url
})
res.end()
}

exports.overview = async (req, res) => {
const latest = await loadCache()

Expand Down

0 comments on commit 9ddf9e5

Please sign in to comment.