make compiler import reurn type and clean path

pull/3094/head
yann300 7 years ago
parent 39454fbeff
commit eaa0626cd7
  1. 4
      src/app.js
  2. 18
      src/app/compiler/compiler-imports.js

@ -200,10 +200,10 @@ function run () {
if (provider && provider.exists(url)) { if (provider && provider.exists(url)) {
return provider.get(url, cb) return provider.get(url, cb)
} }
handleImports.import(url, (error, content) => { handleImports.import(url, (error, content, cleanUrl, type) => {
if (!error) { if (!error) {
// FIXME: at some point we should invalidate the browser cache // FIXME: at some point we should invalidate the browser cache
filesProviders['browser'].addReadOnly(url, content) filesProviders[type].addReadOnly(cleanUrl, content)
cb(null, content) cb(null, content)
} else { } else {
cb(error) cb(error)

@ -8,7 +8,7 @@ module.exports = {
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) {
cb(null, base64.decode(data.content)) cb(null, base64.decode(data.content), root + '/' + path)
} else { } else {
cb('Content not received') cb('Content not received')
} }
@ -21,7 +21,7 @@ module.exports = {
handleSwarmImport: function (url, cb) { handleSwarmImport: function (url, cb) {
swarmgw.get(url, function (err, content) { swarmgw.get(url, function (err, content) {
cb(err, content) cb(err, content, url)
}) })
}, },
@ -31,7 +31,7 @@ module.exports = {
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, url)
}) })
.fail(function (xhr, text, err) { .fail(function (xhr, text, err) {
// NOTE: on some browsers, err equals to '' for certain errors (such as offline browser) // NOTE: on some browsers, err equals to '' for certain errors (such as offline browser)
@ -41,9 +41,9 @@ module.exports = {
import: function (url, cb) { import: function (url, cb) {
var handlers = [ var handlers = [
{ match: /^(https?:\/\/)?(www.)?github.com\/([^/]*\/[^/]*)\/(.*)/, handler: (match, cb) => { this.handleGithubCall(match[3], match[4], cb) } }, { type: 'github', match: /^(https?:\/\/)?(www.)?github.com\/([^/]*\/[^/]*)\/(.*)/, handler: (match, cb) => { this.handleGithubCall(match[3], match[4], cb) } },
{ match: /^(bzz[ri]?:\/\/?.*)$/, handler: (match, cb) => { this.handleSwarmImport(match[1], cb) } }, { type: 'swarm', match: /^(bzz[ri]?:\/\/?.*)$/, handler: (match, cb) => { this.handleSwarmImport(match[1], cb) } },
{ match: /^(ipfs:\/\/?.+)/, handler: (match, cb) => { this.handleIPFS(match[1], cb) } } { type: 'ipfs', match: /^(ipfs:\/\/?.+)/, handler: (match, cb) => { this.handleIPFS(match[1], cb) } }
] ]
var found = false var found = false
@ -57,13 +57,13 @@ module.exports = {
found = true found = true
$('#output').append($('<div/>').append($('<pre/>').text('Loading ' + url + ' ...'))) $('#output').append($('<div/>').append($('<pre/>').text('Loading ' + url + ' ...')))
handler.handler(match, function (err, content) { handler.handler(match, function (err, content, cleanUrl) {
if (err) { if (err) {
cb('Unable to import "' + url + '": ' + err) cb('Unable to import "' + cleanUrl + '": ' + err)
return return
} }
cb(null, content) cb(null, content, cleanUrl, handler.type)
}) })
} }
}) })

Loading…
Cancel
Save