|
|
@ -10,10 +10,11 @@ import { |
|
|
|
} from 'file-saver' |
|
|
|
} from 'file-saver' |
|
|
|
import http from 'isomorphic-git/http/web' |
|
|
|
import http from 'isomorphic-git/http/web' |
|
|
|
|
|
|
|
|
|
|
|
const JSZip = require('jszip') |
|
|
|
import JSZip from 'jszip' |
|
|
|
const path = require('path') |
|
|
|
import path from 'path' |
|
|
|
const FormData = require('form-data') |
|
|
|
import FormData from 'form-data' |
|
|
|
const axios = require('axios') |
|
|
|
import axios from 'axios' |
|
|
|
|
|
|
|
import isElectron from 'is-electron' |
|
|
|
|
|
|
|
|
|
|
|
const profile = { |
|
|
|
const profile = { |
|
|
|
name: 'dGitProvider', |
|
|
|
name: 'dGitProvider', |
|
|
@ -25,6 +26,12 @@ const profile = { |
|
|
|
kind: 'file-system' |
|
|
|
kind: 'file-system' |
|
|
|
} |
|
|
|
} |
|
|
|
class DGitProvider extends Plugin { |
|
|
|
class DGitProvider extends Plugin { |
|
|
|
|
|
|
|
ipfsconfig: { host: string; port: number; protocol: string; ipfsurl: string } |
|
|
|
|
|
|
|
globalIPFSConfig: { host: string; port: number; protocol: string; ipfsurl: string } |
|
|
|
|
|
|
|
remixIPFS: { host: string; port: number; protocol: string; ipfsurl: string } |
|
|
|
|
|
|
|
ipfsSources: any[] |
|
|
|
|
|
|
|
ipfs: any |
|
|
|
|
|
|
|
filesToSend: any[] |
|
|
|
constructor() { |
|
|
|
constructor() { |
|
|
|
super(profile) |
|
|
|
super(profile) |
|
|
|
this.ipfsconfig = { |
|
|
|
this.ipfsconfig = { |
|
|
@ -48,9 +55,6 @@ class DGitProvider extends Plugin { |
|
|
|
this.ipfsSources = [this.remixIPFS, this.globalIPFSConfig, this.ipfsconfig] |
|
|
|
this.ipfsSources = [this.remixIPFS, this.globalIPFSConfig, this.ipfsconfig] |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async onActivation() { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async getGitConfig() { |
|
|
|
async getGitConfig() { |
|
|
|
|
|
|
|
|
|
|
|
if (isElectron()) { |
|
|
|
if (isElectron()) { |
|
|
@ -84,7 +88,7 @@ class DGitProvider extends Plugin { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async init(input) { |
|
|
|
async init(input?) { |
|
|
|
if (isElectron()) { |
|
|
|
if (isElectron()) { |
|
|
|
await this.call('isogit', 'init', { |
|
|
|
await this.call('isogit', 'init', { |
|
|
|
defaultBranch: (input && input.branch) || 'main' |
|
|
|
defaultBranch: (input && input.branch) || 'main' |
|
|
@ -346,7 +350,7 @@ class DGitProvider extends Plugin { |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async checkIpfsConfig(config) { |
|
|
|
async checkIpfsConfig(config?) { |
|
|
|
this.ipfs = IpfsHttpClient(config || this.ipfsconfig) |
|
|
|
this.ipfs = IpfsHttpClient(config || this.ipfsconfig) |
|
|
|
try { |
|
|
|
try { |
|
|
|
await this.ipfs.config.getAll() |
|
|
|
await this.ipfs.config.getAll() |
|
|
@ -395,7 +399,7 @@ class DGitProvider extends Plugin { |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
const permission = await this.askUserPermission('clone', 'Import multiple files into your workspaces.') |
|
|
|
const permission = await this.askUserPermission('clone', 'Import multiple files into your workspaces.') |
|
|
|
if (!permission) return false |
|
|
|
if (!permission) return false |
|
|
|
if (this.calculateLocalStorage() > 10000) throw new Error('The local storage of the browser is full.') |
|
|
|
if (parseFloat(this.calculateLocalStorage()) > 10000) throw new Error('The local storage of the browser is full.') |
|
|
|
if (!workspaceExists) await this.call('filePanel', 'createWorkspace', workspaceName || `workspace_${Date.now()}`, true) |
|
|
|
if (!workspaceExists) await this.call('filePanel', 'createWorkspace', workspaceName || `workspace_${Date.now()}`, true) |
|
|
|
const cmd = { |
|
|
|
const cmd = { |
|
|
|
url: input.url, |
|
|
|
url: input.url, |
|
|
@ -427,19 +431,19 @@ class DGitProvider extends Plugin { |
|
|
|
name: input.name, |
|
|
|
name: input.name, |
|
|
|
email: input.email |
|
|
|
email: input.email |
|
|
|
}, |
|
|
|
}, |
|
|
|
input |
|
|
|
input, |
|
|
|
} |
|
|
|
} |
|
|
|
if (isElectron()) { |
|
|
|
if (isElectron()) { |
|
|
|
return await this.call('isogit', 'push', cmd) |
|
|
|
return await this.call('isogit', 'push', cmd) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
|
|
|
|
|
|
|
|
cmd = { |
|
|
|
const cmd2 = { |
|
|
|
...cmd, |
|
|
|
...cmd, |
|
|
|
...await this.parseInput(input), |
|
|
|
...await this.parseInput(input), |
|
|
|
} |
|
|
|
} |
|
|
|
return await git.push({ |
|
|
|
return await git.push({ |
|
|
|
...await this.getGitConfig(), |
|
|
|
...await this.getGitConfig(), |
|
|
|
...cmd |
|
|
|
...cmd2 |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
@ -454,20 +458,20 @@ class DGitProvider extends Plugin { |
|
|
|
email: input.email |
|
|
|
email: input.email |
|
|
|
}, |
|
|
|
}, |
|
|
|
remote: input.remote, |
|
|
|
remote: input.remote, |
|
|
|
input |
|
|
|
input, |
|
|
|
} |
|
|
|
} |
|
|
|
let result |
|
|
|
let result |
|
|
|
if (isElectron()) { |
|
|
|
if (isElectron()) { |
|
|
|
result = await this.call('isogit', 'pull', cmd) |
|
|
|
result = await this.call('isogit', 'pull', cmd) |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
else { |
|
|
|
cmd = { |
|
|
|
const cmd2 = { |
|
|
|
...cmd, |
|
|
|
...cmd, |
|
|
|
...await this.parseInput(input), |
|
|
|
...await this.parseInput(input), |
|
|
|
} |
|
|
|
} |
|
|
|
result = await git.pull({ |
|
|
|
result = await git.pull({ |
|
|
|
...await this.getGitConfig(), |
|
|
|
...await this.getGitConfig(), |
|
|
|
...cmd |
|
|
|
...cmd2 |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
setTimeout(async () => { |
|
|
|
setTimeout(async () => { |
|
|
@ -491,13 +495,13 @@ class DGitProvider extends Plugin { |
|
|
|
if (isElectron()) { |
|
|
|
if (isElectron()) { |
|
|
|
result = await this.call('isogit', 'fetch', cmd) |
|
|
|
result = await this.call('isogit', 'fetch', cmd) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
cmd = { |
|
|
|
const cmd2 = { |
|
|
|
...cmd, |
|
|
|
...cmd, |
|
|
|
...await this.parseInput(input), |
|
|
|
...await this.parseInput(input), |
|
|
|
} |
|
|
|
} |
|
|
|
result = await git.fetch({ |
|
|
|
result = await git.fetch({ |
|
|
|
...await this.getGitConfig(), |
|
|
|
...await this.getGitConfig(), |
|
|
|
...cmd |
|
|
|
...cmd2 |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
setTimeout(async () => { |
|
|
|
setTimeout(async () => { |
|
|
@ -579,15 +583,15 @@ class DGitProvider extends Plugin { |
|
|
|
.post(url, data, { |
|
|
|
.post(url, data, { |
|
|
|
maxBodyLength: 'Infinity', |
|
|
|
maxBodyLength: 'Infinity', |
|
|
|
headers: { |
|
|
|
headers: { |
|
|
|
'Content-Type': `multipart/form-data; boundary=${data._boundary}`, |
|
|
|
'Content-Type': `multipart/form-data; boundary=${(data as any)._boundary}`, |
|
|
|
pinata_api_key: pinataApiKey, |
|
|
|
pinata_api_key: pinataApiKey, |
|
|
|
pinata_secret_api_key: pinataSecretApiKey |
|
|
|
pinata_secret_api_key: pinataSecretApiKey |
|
|
|
} |
|
|
|
} |
|
|
|
}).catch((e) => { |
|
|
|
} as any).catch((e) => { |
|
|
|
console.log(e) |
|
|
|
console.log(e) |
|
|
|
}) |
|
|
|
}) |
|
|
|
// also commit to remix IPFS for availability after pinning to Pinata
|
|
|
|
// also commit to remix IPFS for availability after pinning to Pinata
|
|
|
|
return await this.export(this.remixIPFS) || result.data.IpfsHash |
|
|
|
return await this.export(this.remixIPFS) || (result as any).data.IpfsHash |
|
|
|
} catch (error) { |
|
|
|
} catch (error) { |
|
|
|
throw new Error(error) |
|
|
|
throw new Error(error) |
|
|
|
} |
|
|
|
} |
|
|
@ -603,10 +607,10 @@ class DGitProvider extends Plugin { |
|
|
|
pinata_api_key: pinataApiKey, |
|
|
|
pinata_api_key: pinataApiKey, |
|
|
|
pinata_secret_api_key: pinataSecretApiKey |
|
|
|
pinata_secret_api_key: pinataSecretApiKey |
|
|
|
} |
|
|
|
} |
|
|
|
}).catch((e) => { |
|
|
|
} as any).catch((e) => { |
|
|
|
console.log('Pinata unreachable') |
|
|
|
console.log('Pinata unreachable') |
|
|
|
}) |
|
|
|
}) |
|
|
|
return result.data |
|
|
|
return (result as any).data |
|
|
|
} catch (error) { |
|
|
|
} catch (error) { |
|
|
|
throw new Error(error) |
|
|
|
throw new Error(error) |
|
|
|
} |
|
|
|
} |
|
|
@ -658,8 +662,8 @@ class DGitProvider extends Plugin { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
calculateLocalStorage() { |
|
|
|
calculateLocalStorage() { |
|
|
|
var _lsTotal = 0 |
|
|
|
let _lsTotal = 0 |
|
|
|
var _xLen; var _x |
|
|
|
let _xLen; let _x |
|
|
|
for (_x in localStorage) { |
|
|
|
for (_x in localStorage) { |
|
|
|
// eslint-disable-next-line no-prototype-builtins
|
|
|
|
// eslint-disable-next-line no-prototype-builtins
|
|
|
|
if (!localStorage.hasOwnProperty(_x)) { |
|
|
|
if (!localStorage.hasOwnProperty(_x)) { |
|
|
@ -674,7 +678,7 @@ class DGitProvider extends Plugin { |
|
|
|
async import(cmd) { |
|
|
|
async import(cmd) { |
|
|
|
const permission = await this.askUserPermission('import', 'Import multiple files into your workspaces.') |
|
|
|
const permission = await this.askUserPermission('import', 'Import multiple files into your workspaces.') |
|
|
|
if (!permission) return false |
|
|
|
if (!permission) return false |
|
|
|
if (this.calculateLocalStorage() > 10000) throw new Error('The local storage of the browser is full.') |
|
|
|
if (parseFloat(this.calculateLocalStorage()) > 10000) throw new Error('The local storage of the browser is full.') |
|
|
|
const cid = cmd.cid |
|
|
|
const cid = cmd.cid |
|
|
|
await this.call('filePanel', 'createWorkspace', `workspace_${Date.now()}`, true) |
|
|
|
await this.call('filePanel', 'createWorkspace', `workspace_${Date.now()}`, true) |
|
|
|
const workspace = await this.call('filePanel', 'getCurrentWorkspace') |
|
|
|
const workspace = await this.call('filePanel', 'getCurrentWorkspace') |