1
0
mirror of https://github.com/kremalicious/blowfish.git synced 2024-12-30 16:47:52 +01:00
blowfish/site/api/github.js

41 lines
1.0 KiB
JavaScript
Raw Normal View History

2020-03-11 04:08:32 +01:00
import axios from 'axios'
import 'dotenv'
2020-03-11 04:08:32 +01:00
export default async (req, res) => {
try {
const response = await axios(
'https://api.github.com/repos/kremalicious/blowfish/releases/latest',
{
headers: {
Authorization: `token ${process.env.GITHUB_TOKEN}`
}
}
)
2020-03-11 04:08:32 +01:00
const { assets, published_at, tag_name } = response.data
const downloads = assets
.filter(
asset =>
asset.name.includes('mac.zip') |
(asset.name.includes('.exe') &&
!asset.name.includes('.exe.blockmap')) |
asset.name.includes('.deb')
)
.map(asset => {
const isMac = asset.name.includes('mac.zip')
const isWin = asset.name.includes('.exe')
return {
name: isMac ? 'macOS' : isWin ? 'Windows' : 'Linux, deb',
url: asset.browser_download_url
}
})
res.status(200).json({ downloads, published_at, tag_name })
} catch (error) {
console.error(error.message)
2020-03-11 04:08:32 +01:00
res.status(500).send(error.message)
}
}