Commit df9aa54a authored by Alex Beregszaszi's avatar Alex Beregszaszi

Support importing Swarm files

parent d2d88ce8
......@@ -58,6 +58,7 @@
"nightwatch": "^0.9.3",
"solc": "https://github.com/ethereum/solc-js",
"standard": "^8.5.0",
"swarmgw": "^0.1.0",
"tape": "^4.5.1",
"web3": "^0.18.0",
"webworkify": "^1.2.1",
......
......@@ -3,6 +3,7 @@
var $ = require('jquery')
var base64 = require('js-base64').Base64
var swarmgw = require('swarmgw')
var QueryParams = require('./app/query-params')
var queryParams = new QueryParams()
......@@ -516,7 +517,7 @@ var run = function () {
}
function handleImportCall (url, cb) {
var githubMatch
var match
if (files.exists(url)) {
cb(null, files.get(url))
} else if ((githubMatch = /^(https?:\/\/)?(www.)?github.com\/([^/]*\/[^/]*)\/(.*)/.exec(url))) {
......@@ -530,6 +531,18 @@ var run = function () {
files.addReadOnly(url, content)
cb(null, content)
})
} else if ((match = /^bzzr:\/\/?([0-9a-fA-F]{64}$)/.exec(url))) {
$('#output').append($('<div/>').append($('<pre/>').text('Loading ' + url + ' ...')))
swarmgw.get(match[1], function (err, content) {
if (err) {
cb('Unable to import "' + url + '": ' + err)
return
}
// FIXME: at some point we should invalidate the cache
files.addReadOnly(url, content)
cb(null, content)
})
} else if (/^[^:]*:\/\//.exec(url)) {
cb('Unable to import "' + url + '": Unsupported URL')
} else {
......
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