Skip to content

Commit

Permalink
Remove linux update notification fallback
Browse files Browse the repository at this point in the history
Not needed anymore since vercel/hyper#2497
Fixes vercel/hyper#2983 (comment)
  • Loading branch information
chabou committed May 17, 2018
1 parent 71efbdb commit ff70741
Showing 1 changed file with 0 additions and 33 deletions.
33 changes: 0 additions & 33 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,10 @@ const {join: joinPath} = require('path')
const {parse: parseUrl} = require('url')
const {readFileSync} = require('fs')

const got = require('got')
const ms = require('ms')
const {satisfies} = require('semver')

const news = JSON.parse(readFileSync(joinPath(__dirname, 'news.json'), 'utf-8'))
const legacyNews = JSON.parse(readFileSync(joinPath(__dirname, 'legacy-news.json'), 'utf-8'))
let latestReleaseNews

// fetches the latest release from github
// useful because we want hyper-news to notify our linux users that a new version is
// available – there's no auto updates there
function fetchLatestRelease() {
got('https://api.github.com/repos/zeit/hyper/releases', {json: true})
.then(res => res.body[0])
.then(release => {
latestReleaseNews = {
text: `Version ${release.tag_name} is available. ${release.body.split('\n')[0]}`,
url: `https://github.com/zeit/hyper/releases/tag/${release.tag_name}`,
dismissable: true,
versions: [`< ${release.tag_name}`],
platforms: ['linux']
}
})
.catch(console.log)
}

const matchVersion = (versions, clientVesion) => (
versions.some(v => v === '*' || satisfies(clientVesion, v))
Expand All @@ -37,9 +16,6 @@ const matchPlatform = (platforms, clientPlatform) => (
platforms.some(p => p === '*' || p === clientPlatform)
)

fetchLatestRelease()
setInterval(() => fetchLatestRelease(), ms('2m'))

module.exports = trackStatusCodes(async function (req) {
const platform = req.headers['x-hyper-platform']
const version = req.headers['x-hyper-version']
Expand All @@ -53,15 +29,6 @@ module.exports = trackStatusCodes(async function (req) {
return legacyNews
}

// NOTE: if the user is running an outdated version,
// the update news will always be sent instead of
// any other news defined on news.json
if (platform === 'linux') {
if (matchVersion(latestReleaseNews.versions, version)) {
return {message: latestReleaseNews}
}
}

const message = news.messages.find(msg => (
matchVersion(msg.versions, version) && matchPlatform(msg.platforms, platform)
)) || ''
Expand Down

0 comments on commit ff70741

Please sign in to comment.