|
|
@ -503,7 +503,6 @@ var run = function () { |
|
|
|
// ----------------- compiler ----------------------
|
|
|
|
// ----------------- compiler ----------------------
|
|
|
|
|
|
|
|
|
|
|
|
function handleGithubCall (root, path, cb) { |
|
|
|
function handleGithubCall (root, path, cb) { |
|
|
|
$('#output').append($('<div/>').append($('<pre/>').text('Loading github.com/' + root + '/' + path + ' ...'))) |
|
|
|
|
|
|
|
return $.getJSON('https://api.github.com/repos/' + root + '/contents/' + path) |
|
|
|
return $.getJSON('https://api.github.com/repos/' + root + '/contents/' + path) |
|
|
|
.done(function (data) { |
|
|
|
.done(function (data) { |
|
|
|
if ('content' in data) { |
|
|
|
if ('content' in data) { |
|
|
@ -534,7 +533,6 @@ var run = function () { |
|
|
|
// replace ipfs:// with /ipfs/
|
|
|
|
// replace ipfs:// with /ipfs/
|
|
|
|
url = url.replace(/^ipfs:\/\/?/, 'ipfs/') |
|
|
|
url = url.replace(/^ipfs:\/\/?/, 'ipfs/') |
|
|
|
|
|
|
|
|
|
|
|
$('#output').append($('<div/>').append($('<pre/>').text('Loading ' + url + ' ...'))) |
|
|
|
|
|
|
|
return $.ajax({ type: 'GET', url: 'https://gateway.ipfs.io/' + url }) |
|
|
|
return $.ajax({ type: 'GET', url: 'https://gateway.ipfs.io/' + url }) |
|
|
|
.done(function (data) { |
|
|
|
.done(function (data) { |
|
|
|
cb(null, data) |
|
|
|
cb(null, data) |
|
|
@ -546,46 +544,45 @@ var run = function () { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function handleImportCall (url, cb) { |
|
|
|
function handleImportCall (url, cb) { |
|
|
|
var match |
|
|
|
|
|
|
|
if (files.exists(url)) { |
|
|
|
if (files.exists(url)) { |
|
|
|
cb(null, files.get(url)) |
|
|
|
cb(null, files.get(url)) |
|
|
|
} else if ((match = /^(https?:\/\/)?(www.)?github.com\/([^/]*\/[^/]*)\/(.*)/.exec(url))) { |
|
|
|
return |
|
|
|
handleGithubCall(match[3], match[4], function (err, content) { |
|
|
|
} |
|
|
|
if (err) { |
|
|
|
|
|
|
|
cb('Unable to import "' + url + '": ' + err) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// FIXME: at some point we should invalidate the cache
|
|
|
|
var handlers = [ |
|
|
|
files.addReadOnly(url, content) |
|
|
|
{ match: /^https?:\/\/?www.?github.com\/([^/]*\/[^/]*)\/(.*)/, handler: function (match, cb) { handleGithubCall(match[3], match[4], cb) } }, |
|
|
|
cb(null, content) |
|
|
|
{ match: /^(bzz[ri]?:\/\/?.*)$/, handler: function (match, cb) { handleSwarmImport(match[1], cb) } }, |
|
|
|
}) |
|
|
|
{ match: /^(ipfs:\/\/?.+)/, handler: function (match, cb) { handleIPFS(match[1], cb) } } |
|
|
|
} else if ((match = /^(bzz[ri]?:\/\/?.*)$/.exec(url))) { |
|
|
|
] |
|
|
|
// Supported: bzz:, bzzr:, bzzi:
|
|
|
|
|
|
|
|
$('#output').append($('<div/>').append($('<pre/>').text('Loading ' + url + ' ...'))) |
|
|
|
|
|
|
|
handleSwarmImport(match[1], function (err, content) { |
|
|
|
|
|
|
|
if (err) { |
|
|
|
|
|
|
|
cb('Unable to import "' + url + '": ' + err) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// FIXME: at some point we should invalidate the cache
|
|
|
|
var found = false |
|
|
|
files.addReadOnly(url, content) |
|
|
|
handlers.forEach(function (handler) { |
|
|
|
cb(null, content) |
|
|
|
if (found) { |
|
|
|
}) |
|
|
|
return |
|
|
|
} 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
|
|
|
|
var match = handler.match.exec(url) |
|
|
|
files.addReadOnly(url, content) |
|
|
|
if (match) { |
|
|
|
cb(null, content) |
|
|
|
found = true |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
$('#output').append($('<div/>').append($('<pre/>').text('Loading ' + url + ' ...'))) |
|
|
|
|
|
|
|
handler.handler(match, 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) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (found) { |
|
|
|
|
|
|
|
return |
|
|
|
} else if (/^[^:]*:\/\//.exec(url)) { |
|
|
|
} else if (/^[^:]*:\/\//.exec(url)) { |
|
|
|
cb('Unable to import "' + url + '": Unsupported URL') |
|
|
|
cb('Unable to import "' + url + '": Unsupported URL schema') |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
cb('Unable to import "' + url + '": File not found') |
|
|
|
cb('Unable to import "' + url + '": File not found') |
|
|
|
} |
|
|
|
} |
|
|
|