UNPKG

@lighthouse-web3/sdk

Version:

NPM package and CLI tool to interact with lighthouse protocol

33 lines (32 loc) 1.13 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const lighthouse_config_1 = require("../../../lighthouse.config"); const util_1 = require("../../utils/util"); exports.default = async (text, apiKey, name, cidVersion) => { try { const token = 'Bearer ' + apiKey; const endpoint = lighthouse_config_1.lighthouseConfig.lighthouseNode + `/api/v0/add?cid-version=${cidVersion}`; // Upload file const formData = new FormData(); const blob = new Blob([Buffer.from(text)]); formData.append('file', blob, name); const response = await (0, util_1.fetchWithTimeout)(endpoint, { method: 'POST', body: formData, credentials: 'include', timeout: 7200000, headers: { Authorization: token, }, }); if (!response.ok) { const res = (await response.json()); throw new Error(res.error); } const data = await response.json(); return { data }; } catch (error) { throw new Error(error); } };