Permalink
Browse files

add arch to url, defaulting to x64 (no breaking change)

  • Loading branch information...
juliangruber committed Sep 24, 2018
1 parent df46c31 commit 78d6e62385c7ceb64c2c6a2207dd0794698585a4
Showing with 46 additions and 29 deletions.
  1. +3 −3 README.md
  2. +35 −23 index.js
  3. +8 −3 test/index.js
View
@@ -52,12 +52,12 @@ Next, construct the URL of the update server and tell
```javascript
const server = 'https://update.electronjs.org'
const feed = `${server}/OWNER/REPO/${process.platform}/${app.getVersion()}`
const feed = `${server}/OWNER/REPO/${process.platform}-${process.arch}/${app.getVersion()}`
autoUpdater.setFeedURL(feed)
```
As the final step, check for updates. The example below will check every 10
As the final step, check for updates. The example below will check every 10
minutes:
```javascript
@@ -109,4 +109,4 @@ $ "example\out\make\squirrel.windows\x64\test-0.0.0 Setup.exe"
[update-electron-app API]: https://github.com/electron/update-electron-app#api
[update-electron-app]: https://github.com/electron/update-electron-app
[main process]: https://electronjs.org/docs/glossary#main-process
[code signed]: https://github.com/electron/electron/blob/master/docs/tutorial/code-signing.md
[code signed]: https://github.com/electron/electron/blob/master/docs/tutorial/code-signing.md
View
@@ -50,24 +50,31 @@ class Updates {
async handle (req, res) {
let segs = req.url.split(/[/?]/).filter(Boolean)
const [account, repository, platform, version, file] = segs
const [account, repository, , version, file] = segs
let platform = segs[2]
if (platform === 'win32') platform = 'win32-x64'
if (platform === 'darwin') platform = 'darwin-x64'
if (!account || !repository || !platform || !version) {
redirect(res, 'https://github.com/electron/update.electronjs.org')
} else if (platform !== 'darwin' && platform !== 'win32') {
const message = `Unsupported platform: "${platform}". Supported: darwin, win32.`
} else if (
platform !== 'darwin-x64' &&
platform !== 'win32-x64' &&
platform !== 'win32-ia32'
) {
const message = `Unsupported platform: "${platform}". Supported: darwin-x64, win32-x64, win32-ia32.`
notFound(res, message)
} else if (version && !semver.valid(version)) {
badRequest(res, `Invalid SemVer: "${version}"`)
} else if (file === 'RELEASES') {
await this.handleReleases(res, account, repository)
await this.handleReleases(res, account, repository, platform)
} else {
await this.handleUpdate(res, account, repository, platform, version)
}
}
async handleReleases (res, account, repository) {
const latest = await this.cachedGetLatest(account, repository, 'win32')
async handleReleases (res, account, repository, platform) {
const latest = await this.cachedGetLatest(account, repository, platform)
if (!latest || !latest.RELEASES) return notFound(res)
res.end(latest.RELEASES)
}
@@ -77,9 +84,9 @@ class Updates {
if (!latest) {
const message =
platform === 'darwin'
platform === 'darwin-x64'
? 'No updates found (needs asset matching *{mac,darwin,osx}*.zip in public repository)'
: 'No updates found (needs asset containing win32-x64 or .exe in public repository)'
: 'No updates found (needs asset containing win32-{x64,ia32} or .exe in public repository)'
notFound(res, message)
} else if (semver.eq(latest.version, version)) {
log.info({ account, repository, platform, version }, 'up to date')
@@ -179,25 +186,29 @@ class Updates {
notes: release.body
}
}
if (latest.darwin && latest.win32) break
if (latest['darwin-x64'] && latest['win32-x64'] && latest['win32-ia32']) { break }
}
if (latest.darwin && latest.win32) break
if (latest['darwin-x64'] && latest['win32-x64'] && latest['win32-ia32']) { break }
}
if (latest.win32) {
const rurl = `https://github.com/${account}/${repository}/releases/download/${
latest.win32.version
}/RELEASES`
const rres = await fetch(rurl)
if (rres.status < 400) {
const body = await rres.text()
const matches = body.match(/[^ ]*\.nupkg/gim)
const nuPKG = rurl.replace('RELEASES', matches[0])
latest.win32.RELEASES = body.replace(matches[0], nuPKG)
for (const key of ['win32-x64', 'win32-ia32']) {
if (latest[key]) {
const rurl = `https://github.com/${account}/${repository}/releases/download/${
latest[key].version
}/RELEASES`
const rres = await fetch(rurl)
if (rres.status < 400) {
const body = await rres.text()
const matches = body.match(/[^ ]*\.nupkg/gim)
const nuPKG = rurl.replace('RELEASES', matches[0])
latest[key].RELEASES = body.replace(matches[0], nuPKG)
}
}
}
return latest.darwin || latest.win32 ? latest : null
return latest['darwin-x64'] || latest['win32-x64'] || latest['win32-ia32']
? latest
: null
}
hashIp (ip) {
if (!ip) return
@@ -209,8 +220,9 @@ class Updates {
}
const assetPlatform = fileName => {
if (/.*(mac|darwin|osx).*\.zip/i.test(fileName)) return 'darwin'
if (/win32-x64|(\.exe$)/.test(fileName)) return 'win32'
if (/.*(mac|darwin|osx).*\.zip/i.test(fileName)) return 'darwin-x64'
if (/win32-ia32/.test(fileName)) return 'win32-ia32'
if (/win32-x64|(\.exe$)/.test(fileName)) return 'win32-x64'
return false
}
View
@@ -147,8 +147,10 @@ nock('https://github.com')
.get('/owner/repo-darwin/releases/download/v1.0.0/RELEASES')
.reply(404)
.get('/owner/repo-win32-zip/releases/download/v1.0.0/RELEASES')
.times(2)
.reply(404)
.get('/owner/repo-no-releases/releases/download/v1.0.0/RELEASES')
.times(2)
.reply(404)
test('Updates', async t => {
@@ -299,7 +301,7 @@ test('Updates', async t => {
const body = await res.text()
t.equal(
body,
'No updates found (needs asset containing win32-x64 or .exe in public repository)'
'No updates found (needs asset containing win32-{x64,ia32} or .exe in public repository)'
)
})
})
@@ -311,7 +313,7 @@ test('Updates', async t => {
const body = await res.text()
t.equal(
body,
'Unsupported platform: "linux". Supported: darwin, win32.'
'Unsupported platform: "linux". Supported: darwin-x64, win32-x64, win32-ia32.'
)
})
})
@@ -321,7 +323,10 @@ test('Updates', async t => {
const res = await fetch(`${address}/owner/repo/os/0.0.0`)
t.equal(res.status, 404)
const body = await res.text()
t.equal(body, 'Unsupported platform: "os". Supported: darwin, win32.')
t.equal(
body,
'Unsupported platform: "os". Supported: darwin-x64, win32-x64, win32-ia32.'
)
})
})
})

0 comments on commit 78d6e62

Please sign in to comment.