mirror of
https://github.com/JonasunderscoreJones/api-worker.git
synced 2025-10-23 18:39:19 +02:00
Initial commit (by create-cloudflare CLI)
This commit is contained in:
commit
58a42872a0
1745 changed files with 741893 additions and 0 deletions
44
node_modules/prebuild-install/asset.js
generated
vendored
Normal file
44
node_modules/prebuild-install/asset.js
generated
vendored
Normal file
|
@ -0,0 +1,44 @@
|
|||
const get = require('simple-get')
|
||||
const util = require('./util')
|
||||
const proxy = require('./proxy')
|
||||
|
||||
function findAssetId (opts, cb) {
|
||||
const downloadUrl = util.getDownloadUrl(opts)
|
||||
const apiUrl = util.getApiUrl(opts)
|
||||
const log = opts.log || util.noopLogger
|
||||
|
||||
log.http('request', 'GET ' + apiUrl)
|
||||
const reqOpts = proxy({
|
||||
url: apiUrl,
|
||||
json: true,
|
||||
headers: {
|
||||
'User-Agent': 'simple-get',
|
||||
Authorization: 'token ' + opts.token
|
||||
}
|
||||
}, opts)
|
||||
|
||||
const req = get.concat(reqOpts, function (err, res, data) {
|
||||
if (err) return cb(err)
|
||||
log.http(res.statusCode, apiUrl)
|
||||
if (res.statusCode !== 200) return cb(err)
|
||||
|
||||
// Find asset id in release
|
||||
for (const release of data) {
|
||||
if (release.tag_name === opts['tag-prefix'] + opts.pkg.version) {
|
||||
for (const asset of release.assets) {
|
||||
if (asset.browser_download_url === downloadUrl) {
|
||||
return cb(null, asset.id)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cb(new Error('Could not find GitHub release for version'))
|
||||
})
|
||||
|
||||
req.setTimeout(30 * 1000, function () {
|
||||
req.abort()
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = findAssetId
|
Loading…
Add table
Add a link
Reference in a new issue