Skip to content

Commit

Permalink
turn off for now
Browse files Browse the repository at this point in the history
  • Loading branch information
motdotla committed Jun 16, 2024
1 parent 68d1782 commit e6b0713
Showing 1 changed file with 60 additions and 60 deletions.
120 changes: 60 additions & 60 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,66 +96,66 @@ app.get('/install.sh', (req, res) => {
})
})

app.get('/v2/:os/:arch(*)', async (req, res) => {
const os = req.params.os.toLowerCase()
let arch = req.params.arch.toLowerCase()
let version = req.query.version

// remove any extension from the arch parameter
arch = arch.replace(/\.[^/.]+$/, '')

// check if version is provided
if (version) {
if (version.startsWith('v')) {
version = version.replace(/^v/, '')
}
} else {
version = VERSION
}

const repo = `dotenvx-${os}-${arch}`
const filename = `${repo}-${version}.tgz`
const registryUrl = `https://registry.npmjs.org/@dotenvx/${repo}/-/${filename}`

try {
const response = await axios.get(registryUrl, { responseType: 'stream' })
const tmpDir = tmp.dirSync({ unsafeCleanup: true }).name
const tmpTarPath = path.join(tmpDir, filename)

// extract the downloaded tarball to the temporary directory
response.data.pipe(tar.x({
cwd: tmpDir,
strip: 1, // Strip the 'package' folder
filter: path => path.startsWith('package/dotenvx') // Only extract files within the 'package' folder
})).on('finish', () => {
// permissions
const dotenvxBinaryPath = path.join(tmpDir, 'dotenvx')
fs.chmodSync(dotenvxBinaryPath, 0o755)

// new tarball
execSync(`tar -czf ${tmpTarPath} -C ${tmpDir} .`)

// size of tarball
const stat = fs.statSync(tmpTarPath)
const tarballSize = stat.size

// set the response headers
res.setHeader('Content-Type', 'application/gzip')
res.setHeader('Content-Length', tarballSize)

// stream the tarball file to the response
const readStream = fs.createReadStream(tmpTarPath)
readStream.pipe(res).on('finish', () => {
// Cleanup the temporary directory
tmp.setGracefulCleanup()
})
}).on('error', error => {
res.status(500).send('Error occurred while extracting the file: ' + error.message)
})
} catch (error) {
res.status(500).send('Error occurred while fetching the file: ' + error.message)
}
})
// app.get('/v2/:os/:arch(*)', async (req, res) => {
// const os = req.params.os.toLowerCase()
// let arch = req.params.arch.toLowerCase()
// let version = req.query.version
//
// // remove any extension from the arch parameter
// arch = arch.replace(/\.[^/.]+$/, '')
//
// // check if version is provided
// if (version) {
// if (version.startsWith('v')) {
// version = version.replace(/^v/, '')
// }
// } else {
// version = VERSION
// }
//
// const repo = `dotenvx-${os}-${arch}`
// const filename = `${repo}-${version}.tgz`
// const registryUrl = `https://registry.npmjs.org/@dotenvx/${repo}/-/${filename}`
//
// try {
// const response = await axios.get(registryUrl, { responseType: 'stream' })
// const tmpDir = tmp.dirSync({ unsafeCleanup: true }).name
// const tmpTarPath = path.join(tmpDir, filename)
//
// // extract the downloaded tarball to the temporary directory
// response.data.pipe(tar.x({
// cwd: tmpDir,
// strip: 1, // Strip the 'package' folder
// filter: path => path.startsWith('package/dotenvx') // Only extract files within the 'package' folder
// })).on('finish', () => {
// // permissions
// const dotenvxBinaryPath = path.join(tmpDir, 'dotenvx')
// fs.chmodSync(dotenvxBinaryPath, 0o755)
//
// // new tarball
// execSync(`tar -czf ${tmpTarPath} -C ${tmpDir} .`)
//
// // size of tarball
// const stat = fs.statSync(tmpTarPath)
// const tarballSize = stat.size
//
// // set the response headers
// res.setHeader('Content-Type', 'application/gzip')
// res.setHeader('Content-Length', tarballSize)
//
// // stream the tarball file to the response
// const readStream = fs.createReadStream(tmpTarPath)
// readStream.pipe(res).on('finish', () => {
// // Cleanup the temporary directory
// tmp.setGracefulCleanup()
// })
// }).on('error', error => {
// res.status(500).send('Error occurred while extracting the file: ' + error.message)
// })
// } catch (error) {
// res.status(500).send('Error occurred while fetching the file: ' + error.message)
// }
// })

app.get('/:os/:arch', async (req, res) => {
const os = req.params.os.toLowerCase()
Expand Down

0 comments on commit e6b0713

Please sign in to comment.