From 76ecb3aba4789a7da5eab2589f2a1386bdaff27c Mon Sep 17 00:00:00 2001 From: yann300 Date: Tue, 21 May 2019 23:10:43 +0200 Subject: [PATCH] fix publish on swarm --- src/app/contract/publishOnSwarm.js | 15 +++++++++++++-- src/app/files/basicReadOnlyExplorer.js | 6 +++--- src/app/files/file-explorer.js | 3 ++- src/app/files/styles/file-explorer-styles.js | 7 ++++++- src/app/tabs/compile-tab.js | 2 +- 5 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/app/contract/publishOnSwarm.js b/src/app/contract/publishOnSwarm.js index d072f72288..f4dc32b833 100644 --- a/src/app/contract/publishOnSwarm.js +++ b/src/app/contract/publishOnSwarm.js @@ -47,6 +47,11 @@ module.exports = (contract, fileManager, cb, swarmVerifiedPublishCallBack) => { var uploaded = [] async.eachSeries(sources, function (item, cb) { swarmVerifiedPublish(item.content, item.hash, (error, result) => { + try { + item.hash = result.url.match('bzz-raw://(.+)')[1] + } catch (e) { + item.hash = ' - ' + item.fileName + } if (!error && swarmVerifiedPublishCallBack) swarmVerifiedPublishCallBack(item) item.output = result uploaded.push(item) @@ -55,10 +60,16 @@ module.exports = (contract, fileManager, cb, swarmVerifiedPublishCallBack) => { cb(error) }) }, () => { - swarmVerifiedPublish(JSON.stringify(metadata), '', (error, result) => { + const metadataContent = JSON.stringify(metadata) + swarmVerifiedPublish(metadataContent, '', (error, result) => { + try { + contract.metadataHash = result.url.match('bzz-raw://(.+)')[1] + } catch (e) { + contract.metadataHash = ' - metadata.json' + } if (!error && swarmVerifiedPublishCallBack) { swarmVerifiedPublishCallBack({ - content: contract.metadata, + content: metadataContent, hash: contract.metadataHash }) } diff --git a/src/app/files/basicReadOnlyExplorer.js b/src/app/files/basicReadOnlyExplorer.js index df4f17c11c..67a1a1f874 100644 --- a/src/app/files/basicReadOnlyExplorer.js +++ b/src/app/files/basicReadOnlyExplorer.js @@ -41,13 +41,13 @@ class BasicReadOnlyExplorer { } set (path, content, cb) { - var unprefixedPath = this.removePrefix(path) - this.addReadOnly(unprefixedPath, content) + this.addReadOnly(path, content) if (cb) cb() return true } addReadOnly (path, content, rawPath) { + path = this.removePrefix(path) try { // lazy try to format JSON content = JSON.stringify(JSON.parse(content), null, '\t') } catch (e) {} @@ -67,7 +67,7 @@ class BasicReadOnlyExplorer { this.paths[this.type][split] = { isDirectory: folder } this.files[path] = content this.normalizedNames[rawPath] = path - this.event.trigger('fileAdded', [path, true]) + this.event.trigger('fileAdded', [this.type + '/' + path, true]) return true } diff --git a/src/app/files/file-explorer.js b/src/app/files/file-explorer.js index 891e5a1692..007073f351 100644 --- a/src/app/files/file-explorer.js +++ b/src/app/files/file-explorer.js @@ -158,7 +158,8 @@ function fileExplorer (localRegistry, files, menuItems) { return yo`