UNPKG

@rsksmart/rif-storage-pinning

Version:

Application for providing your storage space to other to use in exchange of RIF Tokens

65 lines (64 loc) 2.76 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const fs_1 = __importDefault(require("fs")); const command_1 = require("@oclif/command"); const utils_1 = __importDefault(require("../utils")); const agreement_model_1 = __importDefault(require("../models/agreement.model")); const logger_1 = require("../logger"); const logger = logger_1.loggingFactory('cli:cleanup'); class CleanupCommand extends utils_1.default { purgeDb(path) { return fs_1.default.promises.unlink(path); } unpinAgreements() { return __awaiter(this, void 0, void 0, function* () { const provider = yield this.getProviderManager(); // Unpin agreements for (const agreement of yield agreement_model_1.default.findAll()) { yield provider.unpin(agreement.dataReference) .catch(e => { logger.warn(e); }); } }); } run() { return __awaiter(this, void 0, void 0, function* () { const { flags: originalFlags } = this.parsedArgs; const flags = originalFlags; if (flags.unpin) { this.spinner.start('Unpinning files...'); yield this.unpinAgreements(); this.spinner.stop(); } this.spinner.start('Clean up db...'); yield this.purgeDb(this.dbPath); this.spinner.stop(); this.exit(); }); } } exports.default = CleanupCommand; CleanupCommand.flags = Object.assign(Object.assign({}, utils_1.default.flags), { unpin: command_1.flags.boolean({ char: 'u', description: 'Unpin all files', default: false }) }); CleanupCommand.description = 'Cleanup pinner files'; CleanupCommand.examples = [ '$ rif-pinning cleanup', '$ rif-pinning cleanup --db myOffer.sqlite', '$ rif-pinning cleanup --unpin' ];