Converted upload procedure to local SwarmGW lib
# Conflicts: # package-lock.json
This commit is contained in:
parent
8c3ac34fac
commit
b5e8546ebd
|
@ -1,7 +1,7 @@
|
|||
const UploadSwarm = require('./upload.js');
|
||||
const utils = require('../../utils/utils.js');
|
||||
const fs = require('../../core/fs.js');
|
||||
const Web3Bzz = require('web3-bzz');
|
||||
const SwarmGW = require('swarmgw');
|
||||
// TODO: not great, breaks module isolation
|
||||
const StorageProcessesLauncher = require('../storage/storageProcessesLauncher');
|
||||
|
||||
|
@ -26,8 +26,7 @@ class Swarm {
|
|||
if (!this.isSwarmEnabledInTheConfig()) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.bzz = new Web3Bzz(this.providerUrl);
|
||||
this.swarm = new SwarmGW({gateway: this.providerUrl});
|
||||
|
||||
this.setServiceCheck();
|
||||
this.addProviderToEmbarkJS();
|
||||
|
@ -56,7 +55,7 @@ class Swarm {
|
|||
});
|
||||
|
||||
self.events.request("services:register", 'Swarm', function(cb){
|
||||
self.logger.trace(`Checking Swarm availability on ${self.bzz.currentProvider}...`);
|
||||
self.logger.trace(`Checking Swarm availability on ${self.providerUrl}...`);
|
||||
self._checkService((err, result) => {
|
||||
if (err) {
|
||||
self.logger.trace("Check Swarm availability error: " + err);
|
||||
|
@ -69,9 +68,7 @@ class Swarm {
|
|||
}
|
||||
|
||||
_checkService(cb) {
|
||||
this.bzz.isAvailable().then(result => {
|
||||
cb(null, result);
|
||||
}).catch(cb);
|
||||
this.swarm.isAvailable(cb);
|
||||
}
|
||||
|
||||
addProviderToEmbarkJS() {
|
||||
|
@ -102,7 +99,7 @@ class Swarm {
|
|||
buildDir: self.buildDir || 'dist/',
|
||||
storageConfig: self.storageConfig,
|
||||
getUrl: self.getUrl,
|
||||
bzz: self.bzz
|
||||
swarm: self.swarm
|
||||
});
|
||||
|
||||
upload_swarm.deploy(cb);
|
||||
|
|
|
@ -5,26 +5,18 @@ class Swarm {
|
|||
constructor(options) {
|
||||
this.options = options;
|
||||
this.buildDir = options.buildDir || 'dist/';
|
||||
this.bzz = options.bzz;
|
||||
this.swarm = options.swarm;
|
||||
this.getUrl = options.getUrl;
|
||||
}
|
||||
|
||||
deploy(cb) {
|
||||
console.log(__("deploying to swarm!"));
|
||||
let self = this;
|
||||
let bzz = this.bzz;
|
||||
const self = this;
|
||||
const swarm = this.swarm;
|
||||
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);
|
||||
swarm.putDirectory(self.buildDir, callback);
|
||||
},
|
||||
function printUrls(dir_hash, callback) {
|
||||
if (!dir_hash) {
|
||||
|
|
|
@ -81,6 +81,7 @@
|
|||
"solc": "0.4.24",
|
||||
"string-replace-async": "^1.2.1",
|
||||
"style-loader": "^0.19.0",
|
||||
"swarmgw": "file:../swarmgw",
|
||||
"tar": "^3.1.5",
|
||||
"toposort": "^1.0.0",
|
||||
"underscore": "^1.9.0",
|
||||
|
|
Loading…
Reference in New Issue