UNPKG

@onboardbase/cli

Version:

[![Version](https://img.shields.io/npm/v/@onboardbase/cli.svg)](https://www.npmjs.com/package/@onboardbase/cli) [![Downloads/week](https://img.shields.io/npm/dw/@onboardbase/cli.svg)](https://www.npmjs.com/package/@onboardbase/cli) [![License](https://img

107 lines (106 loc) 5.25 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const fs_1 = require("fs"); const path_1 = require("path"); const command_1 = require("@oclif/command"); const chalk = require("chalk"); const mime = require("mime"); const disposable_1 = require("../../http/disposable"); const disposable_2 = require("../../utils/disposable"); const config_1 = require("../../configuration/config"); class DisposableShare extends command_1.Command { async run() { var _a, _b, _c, _d; const { flags: { file, expires, message }, args, } = this.parse(DisposableShare); const fileToRun = file !== null && file !== void 0 ? file : args.file; if (!fileToRun && !message) this.error(chalk.red("Please add a message or a file to create a chat.")); const isFilePathExists = (0, fs_1.existsSync)(fileToRun); if (!isFilePathExists && fileToRun) this.error(chalk.red("Please pass a valid file path")); const expiryTime = expires !== null && expires !== void 0 ? expires : 5; let fileName; let fileURL; if (fileToRun) { fileName = (0, path_1.basename)(fileToRun); const fileType = mime.getType(fileToRun); const payload = { fileName, fileType, //I am giving 5 minutes to cater for the processes before it actually gets to the upload //The presigned urls shou expiresIn: 5, endpoint: "https://nyc3.digitaloceanspaces.com", region: "us-east-1", bucket: "cli-disposable-bucket-live", }; this.log("Uploading your file..."); //TODO handle expired presign URL const uploadPresignedURL = await (0, disposable_1.getPresignedURL)(payload); const fileContent = (0, fs_1.readFileSync)(fileToRun); await (0, disposable_1.uploadFileToPresignedURL)({ file: fileContent, fileType, url: uploadPresignedURL, }); //I am adding 5 minutes here to the expiry time of the download presign url, to cater for before //the file URL itself gets to the disposable endpoint and the timer kicks in. //I have found that between 3 to 6 minutes is the sweet spot. Lmaoooooooooooo fileURL = await (0, disposable_1.getFileDownloadPresignedURL)(Object.assign(Object.assign({}, payload), { expiresIn: expiryTime + 5 })); } this.log("Generating public/private key pair..."); const { id, publicKey: obbPublicKey } = await (0, disposable_1.getObbPublicKey)(); const { publicKey, secretKey } = (0, disposable_2.generateKeyPairForDC)(); const encryptedFileURL = fileToRun ? (0, disposable_2.encryptStr)(fileURL, obbPublicKey, secretKey) : null; const encryptedMessage = (0, disposable_2.encryptStr)(message !== null && message !== void 0 ? message : fileName, obbPublicKey, secretKey); let validity; switch (expiryTime) { case 5: validity = "five"; break; case 30: validity = "thirty"; break; case 60: validity = "oneHour"; break; case 1440: validity = "oneDay"; break; default: validity = "five"; break; } const quickShareInput = { id, publicKey, file: encryptedFileURL, message: encryptedMessage, validity, }; // console.log({ quickShareInput }); this.log("Encrypting your secret..."); const quickShare = await (0, disposable_1.createQuickShare)(quickShareInput); this.log(chalk.green("Your secret has been created.")); // console.log({ fileToRun, fileType, fileName, uploadPresignedURL, fileURL, obbPublicKey, publicKey, secretKey, quickShare }); const allConfigs = config_1.default.getConfigs(); const dashboard = (_d = (_b = (_a = allConfigs[process.cwd()]) === null || _a === void 0 ? void 0 : _a["disposable-host"]) !== null && _b !== void 0 ? _b : (_c = allConfigs["/"]) === null || _c === void 0 ? void 0 : _c["disposable-host"]) !== null && _d !== void 0 ? _d : "https://disposablebase.com"; const secretsURL = `${dashboard}/${quickShare.id}?tab=quick`; this.log(chalk.blue(`You can share the link: ${secretsURL}`)); } } exports.default = DisposableShare; DisposableShare.description = "Share sensitive files securely and quickly with end-to-end encryption and automatic deletion"; DisposableShare.flags = { file: command_1.flags.string({ char: "f", description: "The file to be shared." }), expires: command_1.flags.integer({ char: "e", description: "Time for file to expire in minutes. Default is 5 minutes.", options: ["5", "30", "60", "1440"], }), message: command_1.flags.string({ char: "m", description: "Add a message to accompany the file. Default is file name.", }), }; DisposableShare.args = [{ name: "file" }];