save raw url so it can be resolved later on.

pull/3094/head
yann300 7 years ago
parent eca5d1e2a0
commit a59ccdcce0
  1. 5
      src/app.js
  2. 10
      src/app/compiler/compiler-imports.js
  3. 7
      src/app/files/basicReadOnlyExplorer.js

@ -201,10 +201,9 @@ 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, cleanUrl, type) => { handleImports.import(url, (error, content, cleanUrl, type, url) => {
if (!error) { if (!error) {
// FIXME: at some point we should invalidate the browser cache filesProviders[type].addReadOnly(cleanUrl, content, url)
filesProviders[type].addReadOnly(cleanUrl, content)
cb(null, content) cb(null, content)
} else { } else {
cb(error) cb(error)

@ -39,12 +39,16 @@ module.exports = {
}) })
}, },
import: function (url, cb) { handlers: function () {
var handlers = [ return [
{ type: 'github', 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) } },
{ type: 'swarm', match: /^(bzz[ri]?:\/\/?.*)$/, handler: (match, cb) => { this.handleSwarmImport(match[1], cb) } }, { type: 'swarm', match: /^(bzz[ri]?:\/\/?.*)$/, handler: (match, cb) => { this.handleSwarmImport(match[1], cb) } },
{ type: 'ipfs', match: /^(ipfs:\/\/?.+)/, handler: (match, cb) => { this.handleIPFS(match[1], cb) } } { type: 'ipfs', match: /^(ipfs:\/\/?.+)/, handler: (match, cb) => { this.handleIPFS(match[1], cb) } }
] ]
},
import: function (url, cb) {
var handlers = this.handlers()
var found = false var found = false
handlers.forEach(function (handler) { handlers.forEach(function (handler) {
@ -63,7 +67,7 @@ module.exports = {
return return
} }
cb(null, content, cleanUrl, handler.type) cb(null, content, cleanUrl, handler.type, url)
}) })
} }
}) })

@ -5,6 +5,7 @@ class BasicReadOnlyExplorer {
constructor (type) { constructor (type) {
this.event = new EventManager() this.event = new EventManager()
this.files = {} this.files = {}
this.normalizedNames = {} // contains the raw url associated with the displayed path
this.type = type this.type = type
this.readonly = true this.readonly = true
} }
@ -25,6 +26,9 @@ class BasicReadOnlyExplorer {
get (path, cb) { get (path, cb) {
var content = this.files[path] var content = this.files[path]
if (!content) {
content = this.files[this.type + '/' + this.normalizedNames[path]]
}
if (cb) { if (cb) {
cb(null, content) cb(null, content)
} }
@ -37,12 +41,13 @@ class BasicReadOnlyExplorer {
return true return true
} }
addReadOnly (path, content) { addReadOnly (path, content, rawPath) {
var unprefixedPath = this.removePrefix(path) var unprefixedPath = this.removePrefix(path)
try { // lazy try to format JSON try { // lazy try to format JSON
content = JSON.stringify(JSON.parse(content), null, '\t') content = JSON.stringify(JSON.parse(content), null, '\t')
} catch (e) {} } catch (e) {}
this.files[this.type + '/' + unprefixedPath] = content this.files[this.type + '/' + unprefixedPath] = content
this.normalizedNames[rawPath] = path
this.event.trigger('fileAdded', [this.type + '/' + unprefixedPath, true]) this.event.trigger('fileAdded', [this.type + '/' + unprefixedPath, true])
return true return true
} }

Loading…
Cancel
Save