Merge pull request #1519 from ethereum/fixdgit

ipfs pull fallbacks in dgit provider
pull/1517/head^2
bunsenstraat 3 years ago committed by GitHub
commit 30fac04161
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 57
      apps/remix-ide/src/app/files/dgitProvider.js

@ -38,6 +38,13 @@ class DGitProvider extends Plugin {
protocol: 'https', protocol: 'https',
ipfsurl: 'https://ipfs.io/ipfs/' 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 () { async getGitConfig () {
@ -287,19 +294,13 @@ class DGitProvider extends Plugin {
} }
}; };
async pull (cmd) { async importIPFSFiles (config, cid, workspace) {
const permission = await this.askUserPermission('pull', 'Import multiple files into your workspaces.') const ipfs = IpfsHttpClient(config)
console.log(this.ipfsconfig) let result = false
if (!permission) return false try {
const cid = cmd.cid const data = ipfs.get(cid, { timeout: 10000 })
if (!cmd.local) { for await (const file of data) {
this.ipfs = IpfsHttpClient(this.globalIPFSConfig) if (file.path) result = true
} 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, '') file.path = file.path.replace(cid, '')
if (!file.content) { if (!file.content) {
continue continue
@ -316,7 +317,35 @@ class DGitProvider extends Plugin {
window.remixFileSystem.writeFileSync(`${workspace.absolutePath}/${file.path}`, Buffer.concat(content) || new Uint8Array()) window.remixFileSystem.writeFileSync(`${workspace.absolutePath}/${file.path}`, Buffer.concat(content) || new Uint8Array())
} catch (e) {} } catch (e) {}
} }
this.call('fileManager', 'refresh') } 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.')
if (!permission) return false
if (this.calculateLocalStorage() > 10000) throw new Error('Local browser storage is full.')
const cid = cmd.cid
await this.call('filePanel', 'createWorkspace', `workspace_${Date.now()}`, false)
const workspace = await this.call('filePanel', 'getCurrentWorkspace')
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) { async getItem (name) {

Loading…
Cancel
Save