UNPKG

@drovp/share

Version:

Upload a file and get a URL to share with others.

24 lines (23 loc) 873 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const FS = require("fs"); const Path = require("path"); const got_1 = require("got"); const manifest = require('../package.json'); exports.default = async ({ input }, { progress, output, appVersion }) => { const filename = Path.basename(input.path); const response = await got_1.default .put(`https://transfer.sh/${filename}`, { headers: { 'user-agent': `Drovp/${appVersion} ${manifest.name}/${manifest.version}`, }, body: FS.createReadStream(input.path), }) .on('uploadProgress', ({ transferred, total }) => progress(transferred, total)); if (response.statusCode === 200) { output.url(response.body); } else { output.error(`${response.statusCode}: ${response.statusMessage || response.body}`); } };