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
9dc30c32
Commit
9dc30c32
authored
Aug 25, 2021
by
filip mertens
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ipfs pull fallbacks in dgit provider
lint up timeout
parent
ff5f8866
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
53 additions
and
24 deletions
+53
-24
dgitProvider.js
apps/remix-ide/src/app/files/dgitProvider.js
+53
-24
No files found.
apps/remix-ide/src/app/files/dgitProvider.js
View file @
9dc30c32
...
...
@@ -38,6 +38,13 @@ class DGitProvider extends Plugin {
protocol
:
'https'
,
ipfsurl
:
'https://ipfs.io/ipfs/'
}
this
.
remixIPFS
=
{
host
:
'ipfs.remixproject.org'
,
port
:
443
,
protocol
:
'https'
,
ipfsurl
:
'https://ipfs.remixproject.org/ipfs/'
}
this
.
ipfsSources
=
[
this
.
remixIPFS
,
this
.
globalIPFSConfig
,
this
.
ipfsconfig
]
}
async
getGitConfig
()
{
...
...
@@ -287,36 +294,58 @@ class DGitProvider extends Plugin {
}
};
async
importIPFSFiles
(
config
,
cid
,
workspace
)
{
const
ipfs
=
IpfsHttpClient
(
config
)
let
result
=
false
try
{
const
data
=
ipfs
.
get
(
cid
,
{
timeout
:
10000
})
for
await
(
const
file
of
data
)
{
if
(
file
.
path
)
result
=
true
file
.
path
=
file
.
path
.
replace
(
cid
,
''
)
if
(
!
file
.
content
)
{
continue
}
const
content
=
[]
for
await
(
const
chunk
of
file
.
content
)
{
content
.
push
(
chunk
)
}
const
dir
=
path
.
dirname
(
file
.
path
)
try
{
this
.
createDirectories
(
`
${
workspace
.
absolutePath
}
/
${
dir
}
`
)
}
catch
(
e
)
{}
try
{
window
.
remixFileSystem
.
writeFileSync
(
`
${
workspace
.
absolutePath
}
/
${
file
.
path
}
`
,
Buffer
.
concat
(
content
)
||
new
Uint8Array
())
}
catch
(
e
)
{}
}
}
catch
(
e
)
{
}
return
result
}
calculateLocalStorage
()
{
var
_lsTotal
=
0
var
_xLen
;
var
_x
for
(
_x
in
localStorage
)
{
// eslint-disable-next-line no-prototype-builtins
if
(
!
localStorage
.
hasOwnProperty
(
_x
))
{
continue
}
_xLen
=
((
localStorage
[
_x
].
length
+
_x
.
length
)
*
2
)
_lsTotal
+=
_xLen
};
return
(
_lsTotal
/
1024
).
toFixed
(
2
)
}
async
pull
(
cmd
)
{
const
permission
=
await
this
.
askUserPermission
(
'pull'
,
'Import multiple files into your workspaces.'
)
console
.
log
(
this
.
ipfsconfig
)
if
(
!
permission
)
return
false
if
(
this
.
calculateLocalStorage
()
>
10000
)
throw
new
Error
(
'Local browser storage is full.'
)
const
cid
=
cmd
.
cid
if
(
!
cmd
.
local
)
{
this
.
ipfs
=
IpfsHttpClient
(
this
.
globalIPFSConfig
)
}
else
{
if
(
!
this
.
checkIpfsConfig
())
return
false
}
await
this
.
call
(
'filePanel'
,
'createWorkspace'
,
`workspace_
${
Date
.
now
()}
`
,
false
)
const
workspace
=
await
this
.
call
(
'filePanel'
,
'getCurrentWorkspace'
)
for
await
(
const
file
of
this
.
ipfs
.
get
(
cid
))
{
file
.
path
=
file
.
path
.
replace
(
cid
,
''
)
if
(
!
file
.
content
)
{
continue
}
const
content
=
[]
for
await
(
const
chunk
of
file
.
content
)
{
content
.
push
(
chunk
)
}
const
dir
=
path
.
dirname
(
file
.
path
)
try
{
this
.
createDirectories
(
`
${
workspace
.
absolutePath
}
/
${
dir
}
`
)
}
catch
(
e
)
{}
try
{
window
.
remixFileSystem
.
writeFileSync
(
`
${
workspace
.
absolutePath
}
/
${
file
.
path
}
`
,
Buffer
.
concat
(
content
)
||
new
Uint8Array
())
}
catch
(
e
)
{}
}
this
.
call
(
'fileManager'
,
'refresh'
)
const
result
=
await
this
.
importIPFSFiles
(
this
.
remixIPFS
,
cid
,
workspace
)
||
await
this
.
importIPFSFiles
(
this
.
ipfsconfig
,
cid
,
workspace
)
||
await
this
.
importIPFSFiles
(
this
.
globalIPFSConfig
,
cid
,
workspace
)
await
this
.
call
(
'fileManager'
,
'refresh'
)
if
(
!
result
)
throw
new
Error
(
`Cannot pull files from IPFS at
${
cid
}
`
)
}
async
getItem
(
name
)
{
...
...
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