Support importing Swarm files

pull/1/head
Alex Beregszaszi 8 years ago
parent d2d88ce877
commit df9aa54ae7
  1. 1
      package.json
  2. 15
      src/app.js

@ -58,6 +58,7 @@
"nightwatch": "^0.9.3", "nightwatch": "^0.9.3",
"solc": "https://github.com/ethereum/solc-js", "solc": "https://github.com/ethereum/solc-js",
"standard": "^8.5.0", "standard": "^8.5.0",
"swarmgw": "^0.1.0",
"tape": "^4.5.1", "tape": "^4.5.1",
"web3": "^0.18.0", "web3": "^0.18.0",
"webworkify": "^1.2.1", "webworkify": "^1.2.1",

@ -3,6 +3,7 @@
var $ = require('jquery') var $ = require('jquery')
var base64 = require('js-base64').Base64 var base64 = require('js-base64').Base64
var swarmgw = require('swarmgw')
var QueryParams = require('./app/query-params') var QueryParams = require('./app/query-params')
var queryParams = new QueryParams() var queryParams = new QueryParams()
@ -516,7 +517,7 @@ var run = function () {
} }
function handleImportCall (url, cb) { function handleImportCall (url, cb) {
var githubMatch 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 ((githubMatch = /^(https?:\/\/)?(www.)?github.com\/([^/]*\/[^/]*)\/(.*)/.exec(url))) {
@ -526,6 +527,18 @@ var run = function () {
return return
} }
// FIXME: at some point we should invalidate the cache
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 // FIXME: at some point we should invalidate the cache
files.addReadOnly(url, content) files.addReadOnly(url, content)
cb(null, content) cb(null, content)

Loading…
Cancel
Save