UNPKG

@lighthouse-web3/sdk

Version:

NPM package and CLI tool to interact with lighthouse protocol

29 lines (28 loc) 1.02 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); /* istanbul ignore file */ const encryptionBrowser_1 = require("../encryptionBrowser"); const lighthouse_config_1 = require("../../../lighthouse.config"); const util_1 = require("../../utils/util"); exports.default = async (cid, fileEncryptionKey, mimeType) => { const response = await (0, util_1.fetchWithTimeout)(lighthouse_config_1.lighthouseConfig.lighthouseGateway + '/api/v0/cat/' + cid, { method: 'POST', timeout: 7200000, }); if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } const result = await response.blob(); const decrypted = await (0, encryptionBrowser_1.decryptFile)(await result.arrayBuffer(), fileEncryptionKey); if (decrypted) { if (mimeType) { return new Blob([decrypted], { type: mimeType }); } else { return new Blob([decrypted]); } } else { return null; } };