Skip to content

Commit

Permalink
upgrade got
Browse files Browse the repository at this point in the history
  • Loading branch information
simon300000 committed Dec 10, 2019
1 parent 2557375 commit 36b6f73
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions api/latest.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ latest.get('/:name/:platform', async ctx => {
const ymlFile = fileMap[platform]
if (match && ymlFile) {
const ymlUrl = await getLatestURL({ file: ymlFile, ...match })
const { body: yml } = await got(ymlUrl)
const yml = await got(ymlUrl).text()
const { files } = yaml.safeLoad(yml)
const file = files
.map(({ url }) => url)
.find(url => ['exe', 'dmg', 'AppImage'].find(ext => url.endsWith(ext)))
if (file) {
const url = await getLatestURL({ file, ...match })
ctx.body = got(url, { stream: true })
ctx.body = got.stream(url)
}
}
})
Expand Down
2 changes: 1 addition & 1 deletion api/shared.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const got = require('got')

exports.getLatestURL = async ({ file, repo, owner = 'dd-center' }) => {
const { body: releases } = await got(`https://api.github.com/repos/${owner}/${repo}/releases`, { json: true })
const releases = await got(`https://api.github.com/repos/${owner}/${repo}/releases`).json()
const asset = releases
.flatMap(({ assets }) => assets)
.find(({ name }) => name === file)
Expand Down
4 changes: 2 additions & 2 deletions api/update.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const Router = require('koa-router')
const got = require('got')
const { stream } = require('got')

const { getLatestURL, relays } = require('./shared')

Expand All @@ -13,7 +13,7 @@ update.get('/:name/:file', async ctx => {
if (match) {
const url = await getLatestURL({ file, ...match })
if (url) {
ctx.body = got(url, { stream: true })
ctx.body = stream(url)
}
}
})
Expand Down

0 comments on commit 36b6f73

Please sign in to comment.