terraria-tml-latest-version-api

node v10.23.0
version: 1.0.2
endpointsharetweet
const url = require('url') const { send } = require('micro') const axios = require('axios') exports.endpoint = async function (req, res) { try { const redirect = new URL(req.url, 'https://localhost/').searchParams.get('dl') const latestReleaseEndpoint = `https://api.github.com/repos/tModLoader/tModLoader/releases/latest` const { assets } = await axios(latestReleaseEndpoint).then(res => res.data) const {browser_download_url} = assets.find(function (asset) { return /^tModLoader\.Linux\.v[0-9\.]*\.zip$/.test(asset.name) }); if (redirect == '1') { res.setHeader('Location', browser_download_url) send(res, 307) } else { send(res, 200, browser_download_url) } } catch (e) { console.log(e) send(res, 500, "Internal Server Error") } }
Loading…

no comments

    sign in to comment