Skip to content

Commit

Permalink
feat: binary download routes
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfreska committed Nov 20, 2023
1 parent efe2955 commit 700a9d3
Show file tree
Hide file tree
Showing 7 changed files with 320 additions and 56 deletions.
5 changes: 5 additions & 0 deletions .changeset/polite-penguins-fail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'website': minor
---

The website now includes routes for downloading the latest binaries.
32 changes: 32 additions & 0 deletions apps/website/pages/api/downloads/hostd/latest/[platform].ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
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')
}
}
32 changes: 32 additions & 0 deletions apps/website/pages/api/downloads/renterd/latest/[platform].ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
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')
}
}
32 changes: 32 additions & 0 deletions apps/website/pages/api/downloads/walletd/latest/[platform].ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
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')
}
}
Loading

0 comments on commit 700a9d3

Please sign in to comment.