diff --git a/apps/website/pages/api/downloads/hostd/latest/[platform].ts b/apps/website/pages/api/downloads/hostd/latest/[platform].ts deleted file mode 100644 index 771ddae88..000000000 --- a/apps/website/pages/api/downloads/hostd/latest/[platform].ts +++ /dev/null @@ -1,32 +0,0 @@ -import { getHostdLatestRelease } from '../../../../../content/releases' -import fetch from 'node-fetch' - -export const config = { - api: { - responseLimit: false, - }, -} - -const daemon = 'hostd' - -export default async function handler(req, res) { - const { platform } = req.query - - try { - const latest = await getHostdLatestRelease() - const fileName = `${daemon}_${platform}.zip` - const githubUrl = `https://github.com/SiaFoundation/${daemon}/releases/download/${latest.tag_name}/${fileName}` - - const response = await fetch(githubUrl) - - if (!response.ok) throw new Error(`Failed to fetch ${githubUrl}`) - - res.setHeader('Content-Type', 'application/zip') - res.setHeader('Content-Disposition', `attachment; filename=${fileName}`) - - response.body.pipe(res) - } catch (error) { - console.error('Error fetching the file:', error) - res.status(500).send('Internal Server Error') - } -} diff --git a/apps/website/pages/api/downloads/latest/[name].ts b/apps/website/pages/api/downloads/latest/[name].ts new file mode 100644 index 000000000..99c62c6ea --- /dev/null +++ b/apps/website/pages/api/downloads/latest/[name].ts @@ -0,0 +1,46 @@ +import { GitHubRelease } from '@siafoundation/data-sources' +import { + getHostdLatestRelease, + getRenterdLatestRelease, + getWalletdLatestRelease, +} from '../../../../content/releases' +import fetch from 'node-fetch' + +export const config = { + api: { + responseLimit: false, + }, +} + +export default async function handler(req, res) { + const { name } = req.query + try { + let daemon = '' + let latest: GitHubRelease = null + if (name.includes('hostd')) { + daemon = 'hostd' + latest = await getHostdLatestRelease() + } + if (name.includes('renterd')) { + daemon = 'renterd' + latest = await getRenterdLatestRelease() + } + if (name.includes('walletd')) { + daemon = 'walletd' + latest = await getWalletdLatestRelease() + } + const githubUrl = `https://github.com/SiaFoundation/${daemon}/releases/download/${latest.tag_name}/${name}` + + const response = await fetch(githubUrl) + + if (!response.ok) throw new Error(`Failed to fetch ${githubUrl}`) + + res.setHeader('Content-Type', 'application/zip') + res.setHeader('Content-Disposition', `attachment; filename=${name}`) + + response.body.pipe(res) + } catch (error) { + console.error('Error fetching the file:', error) + res.status(500).send('Internal Server Error') + } +} diff --git a/apps/website/pages/api/downloads/renterd/latest/[platform].ts b/apps/website/pages/api/downloads/renterd/latest/[platform].ts deleted file mode 100644 index d38253892..000000000 --- a/apps/website/pages/api/downloads/renterd/latest/[platform].ts +++ /dev/null @@ -1,32 +0,0 @@ -import { getRenterdLatestRelease } from '../../../../../content/releases' -import fetch from 'node-fetch' - -export const config = { - api: { - responseLimit: false, - }, -} - -const daemon = 'renterd' - -export default async function handler(req, res) { - const { platform } = req.query - - try { - const latest = await getRenterdLatestRelease() - const fileName = `${daemon}_${platform}.zip` - const githubUrl = `https://github.com/SiaFoundation/${daemon}/releases/download/${latest.tag_name}/${fileName}` - - const response = await fetch(githubUrl) - - if (!response.ok) throw new Error(`Failed to fetch ${githubUrl}`) - - res.setHeader('Content-Type', 'application/zip') - res.setHeader('Content-Disposition', `attachment; filename=${fileName}`) - - response.body.pipe(res) - } catch (error) { - console.error('Error fetching the file:', error) - res.status(500).send('Internal Server Error') - } -} diff --git a/apps/website/pages/api/downloads/walletd/latest/[platform].ts b/apps/website/pages/api/downloads/walletd/latest/[platform].ts deleted file mode 100644 index b9f97d0e3..000000000 --- a/apps/website/pages/api/downloads/walletd/latest/[platform].ts +++ /dev/null @@ -1,32 +0,0 @@ -import { getWalletdLatestRelease } from '../../../../../content/releases' -import fetch from 'node-fetch' - -export const config = { - api: { - responseLimit: false, - }, -} - -const daemon = 'walletd' - -export default async function handler(req, res) { - const { platform } = req.query - - try { - const latest = await getWalletdLatestRelease() - const fileName = `${daemon}_${platform}.zip` - const githubUrl = `https://github.com/SiaFoundation/${daemon}/releases/download/${latest.tag_name}/${fileName}` - - const response = await fetch(githubUrl) - - if (!response.ok) throw new Error(`Failed to fetch ${githubUrl}`) - - res.setHeader('Content-Type', 'application/zip') - res.setHeader('Content-Disposition', `attachment; filename=${fileName}`) - - response.body.pipe(res) - } catch (error) { - console.error('Error fetching the file:', error) - res.status(500).send('Internal Server Error') - } -}