Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
baas-ide
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
guxukai
baas-ide
Commits
37cf8a3f
Commit
37cf8a3f
authored
Mar 14, 2017
by
Alex Beregszaszi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove code duplication in handleImport
parent
36473dea
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
36 deletions
+33
-36
app.js
src/app.js
+33
-36
No files found.
src/app.js
View file @
37cf8a3f
...
@@ -544,48 +544,45 @@ var run = function () {
...
@@ -544,48 +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
$
(
'#output'
).
append
(
$
(
'<div/>'
).
append
(
$
(
'<pre/>'
).
text
(
'Loading github.com/'
+
match
[
3
]
+
'/'
+
match
[
4
]
+
' ...'
)))
}
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
)))
{
}
$
(
'#output'
).
append
(
$
(
'<div/>'
).
append
(
$
(
'<pre/>'
).
text
(
'Loading '
+
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'
)
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment