UNPKG

@ethersphere/swarm-cli

Version:
104 lines (103 loc) 4.48 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.List = void 0; const bee_js_1 = require("@ethersphere/bee-js"); const chalk_1 = __importDefault(require("chalk")); const furious_commander_1 = require("furious-commander"); const process_1 = require("process"); const bzz_address_1 = require("../../utils/bzz-address"); const root_command_1 = require("../root-command"); class List extends root_command_1.RootCommand { constructor() { super(...arguments); Object.defineProperty(this, "name", { enumerable: true, configurable: true, writable: true, value: 'list' }); Object.defineProperty(this, "alias", { enumerable: true, configurable: true, writable: true, value: 'ls' }); Object.defineProperty(this, "description", { enumerable: true, configurable: true, writable: true, value: 'List manifest content' }); Object.defineProperty(this, "bzzUrl", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "printBzz", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "printBytes", { enumerable: true, configurable: true, writable: true, value: void 0 }); } async run() { super.init(); const address = await (0, bzz_address_1.makeBzzAddress)(this.bee, this.bzzUrl); const node = await bee_js_1.MantarayNode.unmarshal(this.bee, address.hash); await node.loadRecursively(this.bee); const nodes = node.collect().filter(x => x.fullPathString.startsWith(address.path || '')); if (nodes.length === 0) { this.console.error('No files found under the given path'); (0, process_1.exit)(1); } for (const node of nodes) { this.console.log(new bee_js_1.Reference(node.targetAddress).toHex() + ' ' + node.fullPathString); if (this.printBzz) { this.console.log(chalk_1.default.dim(this.beeApiUrl + '/bzz/' + address.hash + '/' + node.fullPathString)); } if (this.printBytes) { this.console.log(chalk_1.default.dim(this.beeApiUrl + '/bytes/' + new bee_js_1.Reference(node.targetAddress).toHex())); } if (this.verbose && node.metadata) { for (const entry of Object.entries(node.metadata)) { if (!entry[1]) { continue; } this.console.log(chalk_1.default.dim(entry[0] + ': ' + entry[1])); } } } } } __decorate([ (0, furious_commander_1.Argument)({ key: 'address', description: 'Manifest reference (with optional path)', required: true }), __metadata("design:type", String) ], List.prototype, "bzzUrl", void 0); __decorate([ (0, furious_commander_1.Option)({ key: 'print-bzz', description: 'Print /bzz urls', type: 'boolean' }), __metadata("design:type", Boolean) ], List.prototype, "printBzz", void 0); __decorate([ (0, furious_commander_1.Option)({ key: 'print-bytes', description: 'Print /bytes urls', type: 'boolean' }), __metadata("design:type", Boolean) ], List.prototype, "printBytes", void 0); exports.List = List;