Commit 7359d273 authored by Alex Beregszaszi's avatar Alex Beregszaszi

Support downloading Swarm objects via RPC

parent ca2301de
...@@ -516,12 +516,23 @@ var run = function () { ...@@ -516,12 +516,23 @@ var run = function () {
}) })
} }
function handleSwarmImport (url, cb) {
swarmgw.get(url, function (err, content) {
// retry if this failed and we're connected via RPC
if (err && !executionContext.isVM()) {
var web3 = executionContext.web3()
web3.swarm.download(url, cb)
} else {
cb(err, content)
}
})
}
function handleImportCall (url, cb) { function handleImportCall (url, cb) {
var match var match
if (files.exists(url)) { if (files.exists(url)) {
cb(null, files.get(url)) cb(null, files.get(url))
} else if ((githubMatch = /^(https?:\/\/)?(www.)?github.com\/([^/]*\/[^/]*)\/(.*)/.exec(url))) { } else if ((match = /^(https?:\/\/)?(www.)?github.com\/([^/]*\/[^/]*)\/(.*)/.exec(url))) {
handleGithubCall(githubMatch[3], githubMatch[4], function (err, content) { handleGithubCall(match[3], match[4], function (err, content) {
if (err) { if (err) {
cb('Unable to import "' + url + '": ' + err) cb('Unable to import "' + url + '": ' + err)
return return
...@@ -533,7 +544,7 @@ var run = function () { ...@@ -533,7 +544,7 @@ var run = function () {
}) })
} else if ((match = /^(bzzr?:\/\/?.*)$/.exec(url))) { } else if ((match = /^(bzzr?:\/\/?.*)$/.exec(url))) {
$('#output').append($('<div/>').append($('<pre/>').text('Loading ' + url + ' ...'))) $('#output').append($('<div/>').append($('<pre/>').text('Loading ' + url + ' ...')))
swarmgw.get(match[1], function (err, content) { handleSwarmImport(match[1], function (err, content) {
if (err) { if (err) {
cb('Unable to import "' + url + '": ' + err) cb('Unable to import "' + url + '": ' + err)
return return
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment