Skip to content

Commit

Permalink
Fixing downloads from private repository
Browse files Browse the repository at this point in the history
  • Loading branch information
bugii committed Dec 6, 2021
1 parent a06e6c5 commit 6a6bc2d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
26 changes: 16 additions & 10 deletions lib/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module.exports = class Cache {

if (token && !url) {
const error = new Error(
'Neither VERCEL_URL, nor URL are defined, which are mandatory for private repo mode'
'Neither NOW_URL, nor URL are defined, which are mandatory for private repo mode'
)
error.code = 'missing_configuration_properties'
throw error
Expand All @@ -37,19 +37,23 @@ module.exports = class Cache {

async cacheReleaseList(url) {
const { token } = this.config
const headers = { Accept: 'application/vnd.github.preview' }
const headers = { Accept: 'application/octet-stream' }

if (token && typeof token === 'string' && token.length > 0) {
headers.Authorization = `token ${token}`
}

const { status, body } = await retry(
const { body } = await retry(
async () => {
const response = await fetch(url, { headers })
const response = await fetch(url, { headers, redirect: 'manual' })

if (response.status === 302) {
return await fetch(response.headers.get('location'))
}

if (response.status !== 200) {
throw new Error(
`Tried to cache RELEASES, but failed fetching ${url}, status ${status}`
`Tried to cache RELEASES, but failed fetching ${url}, status ${response.status}`
)
}

Expand All @@ -67,10 +71,12 @@ module.exports = class Cache {
)
}

for (let i = 0; i < matches.length; i += 1) {
const nuPKG = url.replace('RELEASES', matches[i])
content = content.replace(matches[i], nuPKG)
}
content = content.replace(
matches[0],
`${this.config.url}/download/latest/${matches[0]}`
)
console.log('content', content)

return content
}

Expand Down Expand Up @@ -140,7 +146,7 @@ module.exports = class Cache {
this.latest.files = {}
}
this.latest.files.RELEASES = await this.cacheReleaseList(
browser_download_url
url
)
} catch (err) {
console.error(err)
Expand Down
4 changes: 2 additions & 2 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ const {
PRE: pre,
TOKEN: token,
URL: PRIVATE_BASE_URL,
VERCEL_URL
NOW_URL
} = process.env

const url = VERCEL_URL || PRIVATE_BASE_URL
const url = NOW_URL || PRIVATE_BASE_URL

module.exports = hazel({
interval,
Expand Down

0 comments on commit 6a6bc2d

Please sign in to comment.