Skip to content

Commit 739f0b6

Browse files
committed
add initial RELEASES support
1 parent dfe4501 commit 739f0b6

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

index.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,32 @@ class Updates {
2828

2929
async handle (req, res) {
3030
this.log(req.method, req.url, '...')
31-
const segs = req.url.split('/').filter(Boolean)
32-
const [account, repository, platform, version] = segs
31+
const segs = req.url.split(/[/?]/).filter(Boolean)
32+
const [account, repository, platform, version, file] = segs
3333
if (!account || !repository || !platform || !version) {
3434
notFound(res)
35+
} else if (file === 'RELEASES') {
36+
await this.handleReleases(res, account, repository)
3537
} else {
3638
await this.handleUpdate(res, account, repository, platform, version)
3739
}
3840
this.log(req.method, req.url, res.statusCode)
3941
}
4042

43+
async handleReleases (res, account, repository) {
44+
const latest = await this.getLatest(account, repository, 'win32')
45+
if (!latest) return notFound(res)
46+
47+
const url = `https://github.com/${account}/${repository}/releases/download/${
48+
latest.version
49+
}/RELEASES`
50+
const rres = await fetch(url)
51+
const body = await rres.text()
52+
const matches = body.match(/[^ ]*\.nupkg/gim)
53+
const nuPKG = url.replace('RELEASES', matches[0])
54+
res.end(body.replace(matches[0], nuPKG))
55+
}
56+
4157
async handleUpdate (res, account, repository, platform, version) {
4258
const latest = await this.getLatest(account, repository, platform)
4359

test/index.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,22 @@ test('Updates', async t => {
7777
})
7878

7979
await t.test('Win32', async t => {
80-
let res = await fetch(`${address}/zeit/hyper/win32/0.0.0`)
80+
const res = await fetch(`${address}/zeit/hyper/win32/0.0.0`)
8181
t.equal(res.status, 200)
82-
let body = await res.json()
82+
const body = await res.json()
8383
t.match(body.url, /\.exe$/)
84+
85+
await t.test('RELEASES', async t => {
86+
const res = await fetch(
87+
`${address}/zeit/hyper/win32/0.0.0/RELEASES?some-extra`
88+
)
89+
t.equal(res.status, 200)
90+
const body = await res.text()
91+
t.match(
92+
body,
93+
/^[^ ]+ https:\/\/github.com\/zeit\/hyper\/releases\/download\/[^/]+\/hyper-[^-]+-full.nupkg [^ ]+$/
94+
)
95+
})
8496
})
8597
})
8698

0 commit comments

Comments
 (0)