UNPKG

@betacodd/lighthouse-package

Version:

NPM package and CLI tool to interact with lighthouse protocol

33 lines (32 loc) 1.3 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const axios_1 = __importDefault(require("axios")); const form_data_1 = __importDefault(require("form-data")); const lighthouse_config_1 = require("../../../lighthouse.config"); exports.default = async (text, apiKey, name) => { try { const token = 'Bearer ' + apiKey; const endpoint = lighthouse_config_1.lighthouseConfig.lighthouseNode + '/api/v0/add'; // Upload file const formData = new form_data_1.default(); formData.append('file', Buffer.from(text), { filename: name }); const response = await axios_1.default.post(endpoint, formData, { withCredentials: true, maxContentLength: Infinity, maxBodyLength: Infinity, headers: { 'Content-type': `multipart/form-data; boundary= ${formData.getBoundary()}`, Encryption: 'false', 'Mime-Type': 'text/plain', Authorization: token, }, }); return { data: response.data }; } catch (error) { throw new Error(error?.message); } };