Converted upload procedure to local SwarmGW lib

# Conflicts:
#	package-lock.json
This commit is contained in:
emizzle 2018-08-16 20:41:18 +10:00
parent 8c3ac34fac
commit b5e8546ebd
3 changed files with 10 additions and 20 deletions

View File

@ -1,7 +1,7 @@
const UploadSwarm = require('./upload.js'); const UploadSwarm = require('./upload.js');
const utils = require('../../utils/utils.js'); const utils = require('../../utils/utils.js');
const fs = require('../../core/fs.js'); const fs = require('../../core/fs.js');
const Web3Bzz = require('web3-bzz'); const SwarmGW = require('swarmgw');
// TODO: not great, breaks module isolation // TODO: not great, breaks module isolation
const StorageProcessesLauncher = require('../storage/storageProcessesLauncher'); const StorageProcessesLauncher = require('../storage/storageProcessesLauncher');
@ -26,8 +26,7 @@ class Swarm {
if (!this.isSwarmEnabledInTheConfig()) { if (!this.isSwarmEnabledInTheConfig()) {
return; return;
} }
this.swarm = new SwarmGW({gateway: this.providerUrl});
this.bzz = new Web3Bzz(this.providerUrl);
this.setServiceCheck(); this.setServiceCheck();
this.addProviderToEmbarkJS(); this.addProviderToEmbarkJS();
@ -56,7 +55,7 @@ class Swarm {
}); });
self.events.request("services:register", 'Swarm', function(cb){ 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) => { self._checkService((err, result) => {
if (err) { if (err) {
self.logger.trace("Check Swarm availability error: " + err); self.logger.trace("Check Swarm availability error: " + err);
@ -69,9 +68,7 @@ class Swarm {
} }
_checkService(cb) { _checkService(cb) {
this.bzz.isAvailable().then(result => { this.swarm.isAvailable(cb);
cb(null, result);
}).catch(cb);
} }
addProviderToEmbarkJS() { addProviderToEmbarkJS() {
@ -102,7 +99,7 @@ class Swarm {
buildDir: self.buildDir || 'dist/', buildDir: self.buildDir || 'dist/',
storageConfig: self.storageConfig, storageConfig: self.storageConfig,
getUrl: self.getUrl, getUrl: self.getUrl,
bzz: self.bzz swarm: self.swarm
}); });
upload_swarm.deploy(cb); upload_swarm.deploy(cb);

View File

@ -5,26 +5,18 @@ class Swarm {
constructor(options) { constructor(options) {
this.options = options; this.options = options;
this.buildDir = options.buildDir || 'dist/'; this.buildDir = options.buildDir || 'dist/';
this.bzz = options.bzz; this.swarm = options.swarm;
this.getUrl = options.getUrl; this.getUrl = options.getUrl;
} }
deploy(cb) { deploy(cb) {
console.log(__("deploying to swarm!")); console.log(__("deploying to swarm!"));
let self = this; const self = this;
let bzz = this.bzz; const swarm = this.swarm;
async.waterfall([ async.waterfall([
function runCommand(callback) { function runCommand(callback) {
console.log(("=== " + __("adding %s to swarm", self.buildDir)).green); console.log(("=== " + __("adding %s to swarm", self.buildDir)).green);
bzz.upload({ swarm.putDirectory(self.buildDir, callback);
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) { function printUrls(dir_hash, callback) {
if (!dir_hash) { if (!dir_hash) {

View File

@ -81,6 +81,7 @@
"solc": "0.4.24", "solc": "0.4.24",
"string-replace-async": "^1.2.1", "string-replace-async": "^1.2.1",
"style-loader": "^0.19.0", "style-loader": "^0.19.0",
"swarmgw": "file:../swarmgw",
"tar": "^3.1.5", "tar": "^3.1.5",
"toposort": "^1.0.0", "toposort": "^1.0.0",
"underscore": "^1.9.0", "underscore": "^1.9.0",