Skip to content

Commit

Permalink
fix publish on swarm
Browse files Browse the repository at this point in the history
  • Loading branch information
yann300 committed May 21, 2019
1 parent 0a1bf37 commit 272961f
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 8 deletions.
15 changes: 13 additions & 2 deletions src/app/contract/publishOnSwarm.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '<Metadata inconsistency> - ' + item.fileName
}
if (!error && swarmVerifiedPublishCallBack) swarmVerifiedPublishCallBack(item)
item.output = result
uploaded.push(item)
Expand All @@ -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 inconsistency> - metadata.json'
}
if (!error && swarmVerifiedPublishCallBack) {
swarmVerifiedPublishCallBack({
content: contract.metadata,
content: metadataContent,
hash: contract.metadataHash
})
}
Expand Down
6 changes: 3 additions & 3 deletions src/app/files/basicReadOnlyExplorer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}
Expand All @@ -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
}

Expand Down
3 changes: 2 additions & 1 deletion src/app/files/file-explorer.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ function fileExplorer (localRegistry, files, menuItems) {
return yo`
<div class="${css.items}">
<label
class=${css.label}
title="${data.path}"
class="${css.label} ${!isRoot ? css.leaf : ''}"
data-path="${data.path}"
style="${isRoot ? 'font-weight:bold;' : ''}"
onkeydown=${editModeOff}
Expand Down
7 changes: 6 additions & 1 deletion src/app/files/styles/file-explorer-styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ var csjs = require('csjs-inject')

var css = csjs`
.label {
margin-top : 4px
margin-top : 4px;
}
.leaf {
overflow : hidden;
text-overflow : ellipsis;
width : 90%;
}
.fileexplorer {
box-sizing : border-box;
Expand Down
2 changes: 1 addition & 1 deletion src/app/tabs/compile-tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ class CompileTab extends CompilerApi {
modalDialogCustom.alert(yo`<span>Metadata published successfully.<br> <pre>${result}</pre> </span>`)
}
}, (item) => { // triggered each time there's a new verified publish (means hash correspond)
this.swarmfileProvider.addReadOnly(item.hash, item.content)
this.swarmfileProvider.addReadOnly('swarm/' + item.hash, item.content)
})
}
}
Expand Down

0 comments on commit 272961f

Please sign in to comment.