@betacodd/lighthouse-package
Version:
NPM package and CLI tool to interact with lighthouse protocol
50 lines (49 loc) • 2.42 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const Lighthouse_1 = __importDefault(require("../Lighthouse"));
const getNetwork_1 = require("./utils/getNetwork");
const kleur_1 = require("kleur");
const showResponse = (uploadResponse) => {
for (let i = 0; i < uploadResponse.length; i++) {
if (uploadResponse[i]['fileStatus'] === 'Deleted') {
continue;
}
console.log((0, kleur_1.yellow)(`File Name: ${uploadResponse[i]['fileName']}\r\n`) +
Array(4).fill('\xa0').join('') + `pieceCid: ${uploadResponse[i]['pieceCid']}\r\n` +
Array(4).fill('\xa0').join('') + `payloadCid: ${uploadResponse[i]['payloadCid']}\r\n` +
Array(4).fill('\xa0').join('') + `fileStatus: ${uploadResponse[i]['fileStatus']}\r\n` +
Array(4).fill('\xa0').join('') + `carSize: ${uploadResponse[i]['carSize']}\r\n` +
Array(4).fill('\xa0').join('') + `fileSize: ${uploadResponse[i]['fileSize']}\r\n` +
Array(4).fill('\xa0').join('') + `pieceSize: ${uploadResponse[i]['pieceSize']}\r\n` +
Array(4).fill('\xa0').join('') +
`Download URL: https://data-depot.lighthouse.storage/api/download/download_car?fileId=${uploadResponse[i]['id']}.car\r\n`);
}
};
async function default_1(_path, options) {
if (!_path) {
console.log('lighthouse-web3 view-car-files\r\n\r\n' +
(0, kleur_1.green)('Description: ') +
'View car files with deal making data\r\n\r\n' +
(0, kleur_1.magenta)('Example:') +
Array(3).fill('\xa0').join('') +
'lighthouse-web3 view-car-files\r\n');
}
else {
try {
const apiKey = getNetwork_1.config.get('LIGHTHOUSE_GLOBAL_API_KEY');
if (!apiKey) {
throw new Error('Please create api-key first: use api-key command');
}
const authToken = (await Lighthouse_1.default.dataDepotAuth(apiKey)).data.access_token;
const uploadResponse = (await Lighthouse_1.default.viewCarFiles(1, authToken)).data;
showResponse(uploadResponse);
}
catch (error) {
console.log((0, kleur_1.red)(error.message));
}
}
}
exports.default = default_1;