mirror of
https://github.com/kremalicious/blowfish.git
synced 2024-11-22 09:47:00 +01:00
site: move asset filtering to api path
This commit is contained in:
parent
35f577dcc8
commit
5978e2d085
@ -1,7 +1,7 @@
|
|||||||
const axios = require('axios')
|
import axios from 'axios'
|
||||||
require('dotenv').config
|
import 'dotenv'
|
||||||
|
|
||||||
module.exports = async (req, res) => {
|
export default async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const response = await axios(
|
const response = await axios(
|
||||||
'https://api.github.com/repos/kremalicious/blowfish/releases/latest',
|
'https://api.github.com/repos/kremalicious/blowfish/releases/latest',
|
||||||
@ -11,8 +11,30 @@ module.exports = async (req, res) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
res.status(200).send(response.data)
|
|
||||||
|
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) {
|
} catch (error) {
|
||||||
console.error(error.message)
|
console.error(error.message)
|
||||||
|
res.status(500).send(error.message)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,30 +3,8 @@ async function init() {
|
|||||||
const release = await response.json()
|
const release = await response.json()
|
||||||
replaceDom(release)
|
replaceDom(release)
|
||||||
}
|
}
|
||||||
|
|
||||||
window.addEventListener('load', () => init())
|
window.addEventListener('load', () => init())
|
||||||
|
|
||||||
function getDownloads(release) {
|
|
||||||
const downloads = release.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
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
return downloads
|
|
||||||
}
|
|
||||||
|
|
||||||
function replaceDom(release) {
|
function replaceDom(release) {
|
||||||
if (!release) return
|
if (!release) return
|
||||||
|
|
||||||
@ -38,14 +16,13 @@ function replaceDom(release) {
|
|||||||
releaseTagElement.innerHTML = release.tag_name
|
releaseTagElement.innerHTML = release.tag_name
|
||||||
releaseDateElement.innerHTML = `on ${dateFormatted}`
|
releaseDateElement.innerHTML = `on ${dateFormatted}`
|
||||||
|
|
||||||
const downloads = getDownloads(release)
|
|
||||||
downloadsElement.innerHTML = ''
|
downloadsElement.innerHTML = ''
|
||||||
|
|
||||||
const isMac = navigator.userAgent.includes('Mac OS')
|
const isMac = navigator.userAgent.includes('Mac OS')
|
||||||
const isWin = navigator.userAgent.includes('Windows')
|
const isWin = navigator.userAgent.includes('Windows')
|
||||||
const isLinux = navigator.userAgent.includes('Linux')
|
const isLinux = navigator.userAgent.includes('Linux')
|
||||||
|
|
||||||
const downloadAll = downloads.map(download => {
|
const downloadAll = release.downloads.map(download => {
|
||||||
const isTargetOs =
|
const isTargetOs =
|
||||||
isMac & download.name.includes('mac') ||
|
isMac & download.name.includes('mac') ||
|
||||||
isWin & download.name.includes('Windows') ||
|
isWin & download.name.includes('Windows') ||
|
||||||
|
Loading…
Reference in New Issue
Block a user