Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing downloads from private repository #134

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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