Skip to content

Commit

Permalink
Merge pull request #218 from PhyrexTsai/master
Browse files Browse the repository at this point in the history
v0.1.28
  • Loading branch information
PhyrexTsai committed Feb 4, 2020
2 parents b01a338 + 4d1ba48 commit 3c88852
Show file tree
Hide file tree
Showing 7 changed files with 312 additions and 157 deletions.
87 changes: 87 additions & 0 deletions build/components/Upload/Swarm/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
"use strict";

function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }

function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }

var path = require('path');

var fs = require('fs');

var Log = require('../../../lib/Log');

var Spinner = require('../../../lib/Spinner');

var axios = require('axios');

function builder(yargs) {
return yargs.positional('file', {
type: 'string',
describe: 'the file which you want to upload to swarm',
require: true
}).option('provider', {
type: 'string',
describe: 'swarm endpoint',
default: 'https://swarm-gateways.net/bzz:/',
require: true
}).example('kaizen upload swarm [file] => to upload the file').demandOption(['file'], '');
}

function handler(_x) {
return _handler.apply(this, arguments);
}

function _handler() {
_handler = _asyncToGenerator(
/*#__PURE__*/
regeneratorRuntime.mark(function _callee(argv) {
var provider, targetPath, response;
return regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
_context.prev = 0;
provider = argv.provider;
Log.NormalLog('Start upload to swarm, please wait a second...');
Spinner.start();
targetPath = path.resolve('./', argv.file);
_context.next = 7;
return axios({
method: 'POST',
headers: {
'content-type': 'text/plain'
},
data: fs.readFileSync(targetPath).toString(),
url: provider || 'https://swarm-gateways.net/bzz:/'
});

case 7:
response = _context.sent;
Spinner.stop();
Log.SuccessLog('Upload success, swarm hash: ' + response.data);
Log.SuccessLog('You can view on: ' + provider + response.data);
_context.next = 18;
break;

case 13:
_context.prev = 13;
_context.t0 = _context["catch"](0);
Spinner.stop();
Log.ErrorLog('something went wrong!');
console.error(_context.t0);

case 18:
case "end":
return _context.stop();
}
}
}, _callee, this, [[0, 13]]);
}));
return _handler.apply(this, arguments);
}

module.exports = function (yargs) {
var command = 'swarm [file]';
var commandDescription = 'Upload file to swarm';
yargs.command(command, commandDescription, builder, handler);
};
4 changes: 3 additions & 1 deletion build/components/Upload/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ function builder(yargs) {

require('./Btfs')(yargs);

return yargs.example('kaizen upload ipfs').example('kaizen upload btfs').demandCommand(1, '');
require('./Swarm')(yargs);

return yargs.example('kaizen upload ipfs').example('kaizen upload btfs').example('kaizen upload swarm').demandCommand(1, '');
}

function handler(_x) {
Expand Down
24 changes: 22 additions & 2 deletions commands/upload.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ Upload project to server or decentralized storage

```
Commands:
kaizen upload ipfs [file] To upload file or folder to IPFS
kaizen upload btfs [file] To upload file or folder to BTFS
kaizen upload ipfs [file] Upload file or folder to IPFS
kaizen upload btfs [file] Upload file or folder to BTFS
kaizen upload swarm [file] Upload file to swarm
Options:
--help Show help [boolean]
Expand All @@ -21,6 +22,7 @@ Options:
Examples:
kaizen upload ipfs
kaizen upload btfs
kaizen upload swarm
```

## `kaizen upload ipfs`
Expand Down Expand Up @@ -67,4 +69,22 @@ Examples:
kaizen upload btfs . => to upload the current folder
kaizen upload btfs ./build => to upload the build folder in the current
folder
```

## `kaizen upload swarm`

Upload file to swarm

```
Positionals:
file the file which you want to upload to swarm [string] [required]
Options:
--help Show help [boolean]
--version Show version number [boolean]
--provider swarm endpoint
[string] [required] [default: "https://swarm-gateways.net/bzz:/"]
Examples:
kaizen upload swarm [file] => to upload the file
```

0 comments on commit 3c88852

Please sign in to comment.