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