Skip to content

Commit

Permalink
fix: website binary downloads path structure
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfreska committed Nov 20, 2023
1 parent 5a5fb05 commit e02f29f
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 96 deletions.
32 changes: 0 additions & 32 deletions apps/website/pages/api/downloads/hostd/latest/[platform].ts

This file was deleted.

46 changes: 46 additions & 0 deletions apps/website/pages/api/downloads/latest/[name].ts
Original file line number Diff line number Diff line change
@@ -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')
}
}
32 changes: 0 additions & 32 deletions apps/website/pages/api/downloads/renterd/latest/[platform].ts

This file was deleted.

32 changes: 0 additions & 32 deletions apps/website/pages/api/downloads/walletd/latest/[platform].ts

This file was deleted.

0 comments on commit e02f29f

Please sign in to comment.