@lighthouse-web3/sdk
Version:
NPM package and CLI tool to interact with lighthouse protocol
29 lines (28 loc) • 928 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const lighthouse_config_1 = require("../../../lighthouse.config");
exports.default = async (blob, apiKey, 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();
formData.set('file', blob);
const response = await fetch(endpoint, {
method: 'POST',
body: formData,
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);
}
};