2020-03-11 04:08:32 +01:00
|
|
|
import axios from 'axios'
|
|
|
|
import 'dotenv'
|
2020-03-06 03:10:05 +01:00
|
|
|
|
2020-03-11 04:08:32 +01:00
|
|
|
export default async (req, res) => {
|
2020-03-06 03:10:05 +01:00
|
|
|
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 })
|
2020-03-06 03:10:05 +01:00
|
|
|
} catch (error) {
|
|
|
|
console.error(error.message)
|
2020-03-11 04:08:32 +01:00
|
|
|
res.status(500).send(error.message)
|
2020-03-06 03:10:05 +01:00
|
|
|
}
|
|
|
|
}
|