emizzle 0cb79d84a0 Dynamic selection of storage provider now working based on improved storage config.
swarm plugin now re-initialises the bzz object when it's availability is checked. this creates a much more stable swarm implementation on the dapp side.

surrounded the storage provider init code block with embark env ready

added alternate swarm gateway url

can now upload dapp to ipfs and run swarm storage and vice versa
2018-06-01 13:30:01 +10:00

54 lines
1.6 KiB
JavaScript

require('colors');
let async = require('async');
class Swarm {
constructor(options) {
this.options = options;
this.buildDir = options.buildDir || 'dist/';
this.bzz = options.bzz;
this.storageConfig = options.storageConfig;
this.providerUrl = options.providerUrl;
this.getUrl = options.getUrl;
}
deploy() {
return new Promise((resolve, reject) => {
console.log(__("deploying to swarm!"));
let self = this;
let bzz = this.bzz;
async.waterfall([
function runCommand(callback) {
console.log(("=== " + __("adding %s to swarm", self.buildDir)).green);
bzz.upload({
path: self.buildDir, // path to data / file / directory
kind: "directory", // could also be "file" or "data"
defaultFile: "index.html" // optional, and only for kind === "directory"
})
.then((success) => {
callback(null, success);
})
.catch(callback);
},
function printUrls(dir_hash, callback) {
if (!dir_hash) {
return callback('No directory hash was returned');
}
console.log(("=== " + __("DApp available at") + ` ${self.getUrl}${dir_hash}/`).green);
console.log(("=== " + __("DApp available at") + ` http://swarm-gateways.net/bzzr:/${dir_hash}`).green);
callback();
}
], function (err, _result) {
if (err) {
console.log(__("error uploading to swarm").red);
console.log(err);
return reject(err);
}
resolve(__('successfully uploaded to swarm'));
});
});
}
}
module.exports = Swarm;