Skip to content

Commit

Permalink
move older download (github) to deprecated
Browse files Browse the repository at this point in the history
  • Loading branch information
motdotla committed Jun 15, 2024
1 parent 507dc1f commit c9eb98c
Showing 1 changed file with 67 additions and 67 deletions.
134 changes: 67 additions & 67 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,72 +43,6 @@ app.get('/VERSION', (req, res) => {
res.send(VERSION)
})

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

// Check if version is provided and prepend 'v' if necessary
if (version) {
if (!version.startsWith('v')) {
version = 'v' + version
}
} else {
version = 'latest'
}

// Convert .tgz to .tar.gz
if (arch.endsWith('.tgz')) {
arch = arch.replace('.tgz', '.tar.gz')
}

// Default to .tar.gz if no extension is provided
if (!arch.includes('.')) {
arch += '.tar.gz'
}

let filename = `dotenvx-${os}-${arch}`
if (version !== 'latest') {
filename = `dotenvx-${version.replace('v', '')}-${os}-${arch}`
}

// Constructing the URL to which we will proxy
let proxyUrl
if (version === 'latest') {
// dotenvx.com/releases URL for the latest version (https://github.com/dotenvx/releases)
proxyUrl = `https://dotenvx.com/releases/${version}/${filename}`
} else {
// GitHub releases URL for specific versions
// https://github.com/dotenvx/dotenvx/releases/download/v0.6.9/dotenvx-0.6.9-darwin-amd64.tar.gz
proxyUrl = `https://github.com/dotenvx/dotenvx/releases/download/${version}/${filename}`
}

try {
const config = {
responseType: 'stream'
}

// If the URL is a GitHub URL, add the Authorization header - 5,000 requests per hour
if (proxyUrl.includes('github.com')) {
config.headers = {
Authorization: `token ${GITHUB_TOKEN}`
}
}

// Using axios to get a response stream
const response = await axios.get(proxyUrl, config)

// Setting headers for the response
res.setHeader('Content-Type', response.headers['content-type'])
res.setHeader('Content-Length', response.headers['content-length'])

// Piping the response stream to the client
response.data.pipe(res)
} catch (error) {
res.status(500).send('Error occurred while fetching the file: ' + error.message)
}
})

app.get('/installer.sh', (req, res) => {
const scriptPath = path.join(__dirname, 'installer.sh')

Expand Down Expand Up @@ -151,7 +85,7 @@ app.get('/install.sh', (req, res) => {
})
})

app.get('/v2/:os/:arch(*)', async (req, res) => {
app.get('/:os/:arch(*)', async (req, res) => {
const os = req.params.os.toLowerCase()
let arch = req.params.arch.toLowerCase()
let version = req.query.version
Expand Down Expand Up @@ -202,6 +136,72 @@ app.get('/v2/:os/:arch(*)', async (req, res) => {
}
})

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

// Check if version is provided and prepend 'v' if necessary
if (version) {
if (!version.startsWith('v')) {
version = 'v' + version
}
} else {
version = 'latest'
}

// Convert .tgz to .tar.gz
if (arch.endsWith('.tgz')) {
arch = arch.replace('.tgz', '.tar.gz')
}

// Default to .tar.gz if no extension is provided
if (!arch.includes('.')) {
arch += '.tar.gz'
}

let filename = `dotenvx-${os}-${arch}`
if (version !== 'latest') {
filename = `dotenvx-${version.replace('v', '')}-${os}-${arch}`
}

// Constructing the URL to which we will proxy
let proxyUrl
if (version === 'latest') {
// dotenvx.com/releases URL for the latest version (https://github.com/dotenvx/releases)
proxyUrl = `https://dotenvx.com/releases/${version}/${filename}`
} else {
// GitHub releases URL for specific versions
// https://github.com/dotenvx/dotenvx/releases/download/v0.6.9/dotenvx-0.6.9-darwin-amd64.tar.gz
proxyUrl = `https://github.com/dotenvx/dotenvx/releases/download/${version}/${filename}`
}

try {
const config = {
responseType: 'stream'
}

// If the URL is a GitHub URL, add the Authorization header - 5,000 requests per hour
if (proxyUrl.includes('github.com')) {
config.headers = {
Authorization: `token ${GITHUB_TOKEN}`
}
}

// Using axios to get a response stream
const response = await axios.get(proxyUrl, config)

// Setting headers for the response
res.setHeader('Content-Type', response.headers['content-type'])
res.setHeader('Content-Length', response.headers['content-length'])

// Piping the response stream to the client
response.data.pipe(res)
} catch (error) {
res.status(500).send('Error occurred while fetching the file: ' + error.message)
}
})

app.listen(PORT, () => {
console.log(`Server is running on http://:${PORT}`)
})

0 comments on commit c9eb98c

Please sign in to comment.