UNPKG

oidc-plus4u-vault

Version:

CLI tool for managing access codes for insomnia-plugin-oidc-plus4u.

26 lines (21 loc) 613 B
const r2 = require("r2"); class HttpUtils { constructor(token) { this._token = token; } async getResource(uri) { let headers = { contentDisposition: "attachment" }; if (this._token) { headers.authorization = `Bearer ${this._token}`; } let resp = await r2(uri, {headers}).response; if (resp.status !== 200) { throw new Error(`Cannot load resource ${uri}. HTTP status: ${resp.status} - ${resp.statusText}. Response text: ${await resp.text()}.`); } const data = await resp.arrayBuffer(); return Buffer.from(data); } } module.exports = HttpUtils;