Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export async function downloadRepo(organization: string, repo: string, branch: string): Promise {
const downloadUrl = `https://api.github.com/repos/${organization}/${repo}/tarball/${branch}` // TODO: use master instead of prisma2
const tmpFile = getTmpFile(`prisma-download-${organization}-${repo}-${branch}.tar.gz`)
const response = await fetch(downloadUrl, {
agent: getProxyAgent(downloadUrl),
headers: {
'User-Agent': 'prisma/prisma-init',
},
})
await new Promise((resolve, reject) => {
response.body
.pipe(fs.createWriteStream(tmpFile))
.on('error', reject)
.on('close', resolve)
})
return tmpFile
}
useEffect(() => {
if (resultCache[url]) {
setState(resultCache[url])
} else {
fetch(url, {
agent: getProxyAgent(url),
})
.then(res => res.json())
.then(res => {
const result = transform ? transform(res) : res
resultCache[url] = result
setState(result)
})
}
}, [url])