Support importing IPFS files

pull/1/head
Alex Beregszaszi 8 years ago
parent a6ece05c5e
commit 4f0bed8e90
  1. 27
      src/app.js

@ -529,6 +529,22 @@ var run = function () {
}
})
}
function handleIPFS (url, cb) {
// replace ipfs:// with /ipfs/
url = url.replace(/^ipfs:\/\/?/, '/ipfs/')
$('#output').append($('<div/>').append($('<pre/>').text('Loading ' + url + ' ...')))
return $.get('https://gateway.ipfs.io/' + url)
.done(function (data) {
cb(null, data)
})
.fail(function (xhr, text, err) {
// NOTE: on some browsers, err equals to '' for certain errors (such as offline browser)
cb(err || 'Unknown transport error')
})
}
function handleImportCall (url, cb) {
var match
if (files.exists(url)) {
@ -553,6 +569,17 @@ var run = function () {
return
}
// FIXME: at some point we should invalidate the cache
files.addReadOnly(url, content)
cb(null, content)
})
} else if ((match = /^(\/?ipfs:?\/\/?.+)/.exec(url))) {
handleIPFS(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)

Loading…
Cancel
Save