Skip to content

Commit

Permalink
Fixing downloads from private repository
Browse files Browse the repository at this point in the history
  • Loading branch information
rastiqdev committed Jul 2, 2023
1 parent 50f558d commit 85098f1
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions lib/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 @@ -144,7 +150,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

0 comments on commit 85098f1

Please sign in to comment.