diff --git a/lib/cache.js b/lib/cache.js index e194568..66a001e 100644 --- a/lib/cache.js +++ b/lib/cache.js @@ -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}` ) } @@ -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 } @@ -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)