|
|
|
@ -4,26 +4,14 @@ import { |
|
|
|
|
Plugin |
|
|
|
|
} from '@remixproject/engine' |
|
|
|
|
import git, { ReadBlobResult, ReadCommitResult, StatusRow } from 'isomorphic-git' |
|
|
|
|
import IpfsHttpClient from 'ipfs-http-client' |
|
|
|
|
import { |
|
|
|
|
saveAs |
|
|
|
|
} from 'file-saver' |
|
|
|
|
import http from 'isomorphic-git/http/web' |
|
|
|
|
|
|
|
|
|
import JSZip from 'jszip' |
|
|
|
|
import path from 'path' |
|
|
|
|
import FormData from 'form-data' |
|
|
|
|
import axios from 'axios' |
|
|
|
|
import { Registry } from '@remix-project/remix-lib' |
|
|
|
|
import { Octokit, App } from "octokit" |
|
|
|
|
import { OctokitResponse } from '@octokit/types' |
|
|
|
|
import { Endpoints } from "@octokit/types" |
|
|
|
|
import { Octokit } from "octokit" |
|
|
|
|
import { IndexedDBStorage } from './filesystems/indexedDB' |
|
|
|
|
import { GitHubUser, branch, commitChange, remote, userEmails } from '@remix-ui/git' |
|
|
|
|
import { checkoutInputType, statusInput, logInputType, author, pagedCommits, remoteCommitsInputType, cloneInputType, fetchInputType, pullInputType, pushInputType, currentBranchInput, branchInputType, addInputType, rmInputType, resolveRefInput, readBlobInput, repositoriesInput, commitInputType, branchDifference, compareBranchesInput, initInputType, isoGitConfig} from '@remix-api' |
|
|
|
|
import { LibraryProfile, StatusEvents } from '@remixproject/plugin-utils' |
|
|
|
|
import { ITerminal } from '@remixproject/plugin-api/src/lib/terminal' |
|
|
|
|
import { partial } from 'lodash' |
|
|
|
|
import { branch, commitChange, remote } from '@remix-ui/git' |
|
|
|
|
import { checkoutInputType, statusInput, logInputType, author, pagedCommits, remoteCommitsInputType, cloneInputType, fetchInputType, pullInputType, pushInputType, currentBranchInput, branchInputType, addInputType, rmInputType, resolveRefInput, readBlobInput, repositoriesInput, commitInputType, branchDifference, compareBranchesInput, initInputType, isoGitFSConfig, GitHubUser, userEmails } from '@remix-api' |
|
|
|
|
import { LibraryProfile } from '@remixproject/plugin-utils' |
|
|
|
|
import { CustomRemixApi } from '@remix-api' |
|
|
|
|
import { isoGit } from "libs/remix-git/src/isogit" |
|
|
|
|
|
|
|
|
@ -37,49 +25,17 @@ const profile: LibraryProfile = { |
|
|
|
|
description: 'Decentralized git provider', |
|
|
|
|
icon: 'assets/img/fileManager.webp', |
|
|
|
|
version: '0.0.1', |
|
|
|
|
methods: ['init', 'localStorageUsed', 'addremote', 'delremote', 'remotes', 'fetch', 'clone', 'export', 'import', 'status', 'log', 'commit', 'add', 'remove', 'rm', 'readblob', 'resolveref', 'branches', 'branch', 'checkout', 'currentbranch', 'push', 'pull', 'setIpfsConfig', 'zip', 'setItem', 'getItem', 'version', 'updateSubmodules' |
|
|
|
|
methods: ['init', 'addremote', 'delremote', 'remotes', 'fetch', 'clone', 'status', 'log', 'commit', 'add', 'remove', 'rm', 'readblob', 'resolveref', 'branches', 'branch', 'checkout', 'currentbranch', 'push', 'pull', 'version', 'updateSubmodules' |
|
|
|
|
, 'getGitHubUser', 'remotebranches', 'remotecommits', 'repositories', 'getCommitChanges', 'compareBranches'], |
|
|
|
|
kind: 'file-system' |
|
|
|
|
} |
|
|
|
|
class DGitProvider extends Plugin<any, CustomRemixApi> { |
|
|
|
|
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 = { |
|
|
|
|
host: 'jqgt.remixproject.org', |
|
|
|
|
port: 443, |
|
|
|
|
protocol: 'https', |
|
|
|
|
ipfsurl: 'https://jqgt.remixproject.org/ipfs/' |
|
|
|
|
} |
|
|
|
|
this.globalIPFSConfig = { |
|
|
|
|
host: 'ipfs.io', |
|
|
|
|
port: 443, |
|
|
|
|
protocol: 'https', |
|
|
|
|
ipfsurl: 'https://ipfs.io/ipfs/' |
|
|
|
|
} |
|
|
|
|
this.remixIPFS = { |
|
|
|
|
host: 'jqgt.remixproject.org', |
|
|
|
|
port: 443, |
|
|
|
|
protocol: 'https', |
|
|
|
|
ipfsurl: 'https://jqgt.remixproject.org/ipfs/' |
|
|
|
|
} |
|
|
|
|
this.ipfsSources = [this.remixIPFS, this.globalIPFSConfig, this.ipfsconfig] |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
async addIsomorphicGitConfigFS(dir = '') { |
|
|
|
|
|
|
|
|
|
if ((Registry.getInstance().get('platform').api.isDesktop())) { |
|
|
|
|
return { |
|
|
|
|
fs: window.remixFileSystem, |
|
|
|
|
dir: '/' |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const workspace = await this.call('filePanel', 'getCurrentWorkspace') |
|
|
|
|
|
|
|
|
|
if (!workspace) return |
|
|
|
@ -89,61 +45,12 @@ class DGitProvider extends Plugin<any, CustomRemixApi> { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
async addIsomorphicGitConfig(input) { |
|
|
|
|
|
|
|
|
|
const token = await this.call('config' as any, 'getAppParameter', 'settings/gist-access-token') |
|
|
|
|
|
|
|
|
|
let config = { |
|
|
|
|
corsProxy: 'https://corsproxy.remixproject.org/', |
|
|
|
|
http, |
|
|
|
|
onAuth: url => { |
|
|
|
|
url |
|
|
|
|
const auth = { |
|
|
|
|
username: input.token || token, |
|
|
|
|
password: '' |
|
|
|
|
} |
|
|
|
|
return auth |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (input.url) { |
|
|
|
|
|
|
|
|
|
const url = new URL(input.url) |
|
|
|
|
if (url.hostname.includes('localhost')) { |
|
|
|
|
config = { |
|
|
|
|
...config, |
|
|
|
|
corsProxy: null |
|
|
|
|
async getToken() { |
|
|
|
|
return await this.call('config' as any, 'getAppParameter', 'settings/gist-access-token') |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if ((input.remote && input.remote.url)) { |
|
|
|
|
|
|
|
|
|
const url = new URL(input.remote.url) |
|
|
|
|
if (url.hostname.includes('localhost')) { |
|
|
|
|
config = { |
|
|
|
|
...config, |
|
|
|
|
corsProxy: null, |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (input.provider && input.provider === 'github') { |
|
|
|
|
config = { |
|
|
|
|
...config, |
|
|
|
|
corsProxy: 'https://corsproxy.remixproject.org/', |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (input.provider && input.provider === 'localhost') { |
|
|
|
|
config = { |
|
|
|
|
...config, |
|
|
|
|
corsProxy: null |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return config |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
async getCommandUser(input) { |
|
|
|
|
async getAuthor(input) { |
|
|
|
|
const author: author = { |
|
|
|
|
name: '', |
|
|
|
|
email: '' |
|
|
|
@ -351,7 +258,7 @@ class DGitProvider extends Plugin<any, CustomRemixApi> { |
|
|
|
|
return await isoGit.currentbranch(input, defaultConfig) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
async branches(config: isoGitConfig): Promise<branch[]> { |
|
|
|
|
async branches(config: isoGitFSConfig): Promise<branch[]> { |
|
|
|
|
|
|
|
|
|
if ((Registry.getInstance().get('platform').api.isDesktop())) { |
|
|
|
|
const branches = await this.call('isogit', 'branches') |
|
|
|
@ -416,22 +323,6 @@ class DGitProvider extends Plugin<any, CustomRemixApi> { |
|
|
|
|
return readBlobResult |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
async setIpfsConfig(config) { |
|
|
|
|
this.ipfsconfig = config |
|
|
|
|
return new Promise((resolve) => { |
|
|
|
|
resolve(this.checkIpfsConfig()) |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
async checkIpfsConfig(config?) { |
|
|
|
|
this.ipfs = IpfsHttpClient(config || this.ipfsconfig) |
|
|
|
|
try { |
|
|
|
|
await this.ipfs.config.getAll() |
|
|
|
|
return true |
|
|
|
|
} catch (e) { |
|
|
|
|
return false |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
async addremote(input: remote): Promise<void> { |
|
|
|
|
if ((Registry.getInstance().get('platform').api.isDesktop())) { |
|
|
|
@ -449,10 +340,6 @@ class DGitProvider extends Plugin<any, CustomRemixApi> { |
|
|
|
|
await git.deleteRemote({ ...await this.addIsomorphicGitConfigFS(), remote: input.name }) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
async localStorageUsed() { |
|
|
|
|
return this.calculateLocalStorage() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
async clone(input: cloneInputType) { |
|
|
|
|
|
|
|
|
|
if ((Registry.getInstance().get('platform').api.isDesktop())) { |
|
|
|
@ -481,14 +368,13 @@ class DGitProvider extends Plugin<any, CustomRemixApi> { |
|
|
|
|
} else { |
|
|
|
|
const permission = await this.askUserPermission('clone', 'Import multiple files into your workspaces.') |
|
|
|
|
if (!permission) return false |
|
|
|
|
if (parseFloat(this.calculateLocalStorage()) > 10000) throw new Error('The local storage of the browser is full.') |
|
|
|
|
if (!input.workspaceExists) await this.call('filePanel', 'createWorkspace', input.workspaceName || `workspace_${Date.now()}`, true) |
|
|
|
|
const cmd = { |
|
|
|
|
url: input.url, |
|
|
|
|
singleBranch: input.singleBranch, |
|
|
|
|
ref: input.branch, |
|
|
|
|
depth: input.depth || 10, |
|
|
|
|
...await this.addIsomorphicGitConfig(input), |
|
|
|
|
...await isoGit.addIsomorphicGitProxyConfig(input, this), |
|
|
|
|
...await this.addIsomorphicGitConfigFS() |
|
|
|
|
} |
|
|
|
|
this.call('terminal', 'logHtml', `Cloning ${input.url}... please wait...`) |
|
|
|
@ -575,10 +461,10 @@ class DGitProvider extends Plugin<any, CustomRemixApi> { |
|
|
|
|
url: module.url, |
|
|
|
|
singleBranch: true, |
|
|
|
|
depth: 1, |
|
|
|
|
...await this.addIsomorphicGitConfig({ |
|
|
|
|
...await isoGit.addIsomorphicGitProxyConfig({ |
|
|
|
|
...input, |
|
|
|
|
provider: 'github' |
|
|
|
|
}), |
|
|
|
|
provider: 'github', |
|
|
|
|
}, this), |
|
|
|
|
...await this.addIsomorphicGitConfigFS(dir) |
|
|
|
|
} |
|
|
|
|
this.call('terminal', 'logHtml', `Cloning submodule ${dir}...`) |
|
|
|
@ -602,10 +488,10 @@ class DGitProvider extends Plugin<any, CustomRemixApi> { |
|
|
|
|
if (result && result.length) { |
|
|
|
|
this.call('terminal', 'logHtml', `Checking out submodule ${dir} to ${result[0]} in directory ${dir}`) |
|
|
|
|
await git.fetch({ |
|
|
|
|
...await this.addIsomorphicGitConfig({ |
|
|
|
|
...await isoGit.addIsomorphicGitProxyConfig({ |
|
|
|
|
...input, |
|
|
|
|
provider: 'github' |
|
|
|
|
}), |
|
|
|
|
provider: 'github', |
|
|
|
|
}, this), |
|
|
|
|
...await this.addIsomorphicGitConfigFS(dir), |
|
|
|
|
singleBranch: true, |
|
|
|
|
ref: result[0] |
|
|
|
@ -652,61 +538,23 @@ class DGitProvider extends Plugin<any, CustomRemixApi> { |
|
|
|
|
|
|
|
|
|
async push(input: pushInputType) { |
|
|
|
|
|
|
|
|
|
const cmd = { |
|
|
|
|
force: input.force, |
|
|
|
|
ref: input.ref.name, |
|
|
|
|
remoteRef: input.remoteRef && input.remoteRef.name, |
|
|
|
|
remote: input.remote.name, |
|
|
|
|
author: await this.getCommandUser(input), |
|
|
|
|
input, |
|
|
|
|
} |
|
|
|
|
if ((Registry.getInstance().get('platform').api.isDesktop())) { |
|
|
|
|
return await this.call('isogit', 'push', { |
|
|
|
|
...input, |
|
|
|
|
author: await this.getCommandUser(input), |
|
|
|
|
}) |
|
|
|
|
return await this.call('isogit', 'push', input) |
|
|
|
|
} else { |
|
|
|
|
|
|
|
|
|
const cmd2 = { |
|
|
|
|
...cmd, |
|
|
|
|
...await this.addIsomorphicGitConfig(input), |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const result = await git.push({ |
|
|
|
|
...await this.addIsomorphicGitConfigFS(), |
|
|
|
|
...cmd2 |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
const result = await isoGit.push(input, await this.addIsomorphicGitConfigFS(), this) |
|
|
|
|
return result |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
async pull(input: pullInputType) { |
|
|
|
|
|
|
|
|
|
const cmd = { |
|
|
|
|
ref: input.ref.name, |
|
|
|
|
remoteRef: input.remoteRef && input.remoteRef.name, |
|
|
|
|
author: await this.getCommandUser(input), |
|
|
|
|
remote: input.remote.name, |
|
|
|
|
input, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
let result |
|
|
|
|
if ((Registry.getInstance().get('platform').api.isDesktop())) { |
|
|
|
|
result = await this.call('isogit', 'pull', { |
|
|
|
|
...input, |
|
|
|
|
author: await this.getCommandUser(input), |
|
|
|
|
}) |
|
|
|
|
result = await this.call('isogit', 'pull', input) |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
const cmd2 = { |
|
|
|
|
...cmd, |
|
|
|
|
...await this.addIsomorphicGitConfig(input), |
|
|
|
|
} |
|
|
|
|
result = await git.pull({ |
|
|
|
|
...await this.addIsomorphicGitConfigFS(), |
|
|
|
|
...cmd2 |
|
|
|
|
}) |
|
|
|
|
result = await isoGit.pull(input, await this.addIsomorphicGitConfigFS(), this) |
|
|
|
|
} |
|
|
|
|
setTimeout(async () => { |
|
|
|
|
await this.call('fileManager', 'refresh') |
|
|
|
@ -715,33 +563,15 @@ class DGitProvider extends Plugin<any, CustomRemixApi> { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
async fetch(input: fetchInputType) { |
|
|
|
|
const cmd = { |
|
|
|
|
ref: input.ref && input.ref.name, |
|
|
|
|
remoteRef: input.remoteRef && input.remoteRef.name, |
|
|
|
|
author: await this.getCommandUser(input), |
|
|
|
|
remote: input.remote && input.remote.name, |
|
|
|
|
depth: input.depth || 5, |
|
|
|
|
singleBranch: input.singleBranch, |
|
|
|
|
relative: input.relative, |
|
|
|
|
input |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let result |
|
|
|
|
if ((Registry.getInstance().get('platform').api.isDesktop())) { |
|
|
|
|
result = await this.call('isogit', 'fetch', { |
|
|
|
|
...input, |
|
|
|
|
author: await this.getCommandUser(input), |
|
|
|
|
}) |
|
|
|
|
} else { |
|
|
|
|
const cmd2 = { |
|
|
|
|
...cmd, |
|
|
|
|
...await this.addIsomorphicGitConfig(input), |
|
|
|
|
} |
|
|
|
|
result = await git.fetch({ |
|
|
|
|
...await this.addIsomorphicGitConfigFS(), |
|
|
|
|
...cmd2 |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
result = await isoGit.fetch(input, await this.addIsomorphicGitConfigFS(), this) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
setTimeout(async () => { |
|
|
|
@ -750,162 +580,6 @@ class DGitProvider extends Plugin<any, CustomRemixApi> { |
|
|
|
|
return result |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
async export(config) { |
|
|
|
|
if (!this.checkIpfsConfig(config)) return false |
|
|
|
|
const workspace = await this.call('filePanel', 'getCurrentWorkspace') |
|
|
|
|
const files = await this.getDirectory('/') |
|
|
|
|
this.filesToSend = [] |
|
|
|
|
for (const file of files) { |
|
|
|
|
const c = await window.remixFileSystem.readFile(`${workspace.absolutePath}/${file}`, null) |
|
|
|
|
const ob = { |
|
|
|
|
path: file, |
|
|
|
|
content: c |
|
|
|
|
} |
|
|
|
|
this.filesToSend.push(ob) |
|
|
|
|
} |
|
|
|
|
const addOptions = { |
|
|
|
|
wrapWithDirectory: true |
|
|
|
|
} |
|
|
|
|
const r = await this.ipfs.add(this.filesToSend, addOptions) |
|
|
|
|
return r.cid.string |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
async importIPFSFiles(config, cid, workspace) { |
|
|
|
|
const ipfs = IpfsHttpClient(config) |
|
|
|
|
let result = false |
|
|
|
|
try { |
|
|
|
|
const data = ipfs.get(cid, { timeout: 60000 }) |
|
|
|
|
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 { |
|
|
|
|
await this.createDirectories(`${workspace.absolutePath}/${dir}`) |
|
|
|
|
} catch (e) { throw new Error(e) } |
|
|
|
|
try { |
|
|
|
|
await window.remixFileSystem.writeFile(`${workspace.absolutePath}/${file.path}`, Buffer.concat(content) || new Uint8Array(), null) |
|
|
|
|
} catch (e) { throw new Error(e) } |
|
|
|
|
} |
|
|
|
|
} catch (e) { |
|
|
|
|
throw new Error(e) |
|
|
|
|
} |
|
|
|
|
return result |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
calculateLocalStorage() { |
|
|
|
|
let _lsTotal = 0 |
|
|
|
|
let _xLen; let _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 import(cmd) { |
|
|
|
|
const permission = await this.askUserPermission('import', 'Import multiple files into your workspaces.') |
|
|
|
|
if (!permission) return false |
|
|
|
|
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') |
|
|
|
|
let result |
|
|
|
|
if (cmd.local) { |
|
|
|
|
result = await this.importIPFSFiles(this.ipfsconfig, cid, workspace) |
|
|
|
|
} else { |
|
|
|
|
result = await this.importIPFSFiles(this.remixIPFS, cid, workspace) || await this.importIPFSFiles(this.ipfsconfig, cid, workspace) || await this.importIPFSFiles(this.globalIPFSConfig, cid, workspace) |
|
|
|
|
} |
|
|
|
|
setTimeout(async () => { |
|
|
|
|
await this.call('fileManager', 'refresh') |
|
|
|
|
}, 1000) |
|
|
|
|
if (!result) throw new Error(`Cannot pull files from IPFS at ${cid}`) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
async getItem(name) { |
|
|
|
|
if (typeof window !== 'undefined') { |
|
|
|
|
return window.localStorage.getItem(name) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
async setItem(name, content) { |
|
|
|
|
try { |
|
|
|
|
if (typeof window !== 'undefined') { |
|
|
|
|
window.localStorage.setItem(name, content) |
|
|
|
|
} |
|
|
|
|
} catch (e) { |
|
|
|
|
console.log(e) |
|
|
|
|
return false |
|
|
|
|
} |
|
|
|
|
return true |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
async zip() { |
|
|
|
|
const zip = new JSZip() |
|
|
|
|
const workspace = await this.call('filePanel', 'getCurrentWorkspace') |
|
|
|
|
const files = await this.getDirectory('/') |
|
|
|
|
this.filesToSend = [] |
|
|
|
|
for (const file of files) { |
|
|
|
|
const c = await window.remixFileSystem.readFile(`${workspace.absolutePath}/${file}`, null) |
|
|
|
|
zip.file(file, c) |
|
|
|
|
} |
|
|
|
|
await zip.generateAsync({ |
|
|
|
|
type: 'blob' |
|
|
|
|
}) |
|
|
|
|
.then(function (content) { |
|
|
|
|
saveAs(content, `${workspace.name}.zip`) |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
async createDirectories(strdirectories) { |
|
|
|
|
const ignore = ['.', '/.', ''] |
|
|
|
|
if (ignore.indexOf(strdirectories) > -1) return false |
|
|
|
|
const directories = strdirectories.split('/') |
|
|
|
|
for (let i = 0; i < directories.length; i++) { |
|
|
|
|
let previouspath = '' |
|
|
|
|
if (i > 0) previouspath = '/' + directories.slice(0, i).join('/') |
|
|
|
|
const finalPath = previouspath + '/' + directories[i] |
|
|
|
|
try { |
|
|
|
|
if (!await window.remixFileSystem.exists(finalPath)) { |
|
|
|
|
await window.remixFileSystem.mkdir(finalPath) |
|
|
|
|
} |
|
|
|
|
} catch (e) { |
|
|
|
|
console.log(e) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
async getDirectory(dir) { |
|
|
|
|
let result = [] |
|
|
|
|
const files = await this.call('fileManager', 'readdir', dir) |
|
|
|
|
const fileArray = normalize(files) |
|
|
|
|
for (const fi of fileArray) { |
|
|
|
|
if (fi) { |
|
|
|
|
const type = fi.data.isDirectory |
|
|
|
|
if (type === true) { |
|
|
|
|
result = [ |
|
|
|
|
...result, |
|
|
|
|
...(await this.getDirectory( |
|
|
|
|
`${fi.filename}` |
|
|
|
|
)) |
|
|
|
|
] |
|
|
|
|
} else { |
|
|
|
|
result = [...result, fi.filename] |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return result |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// OCTOKIT FEATURES
|
|
|
|
|
|
|
|
|
@ -1042,23 +716,4 @@ const addSlash = (file) => { |
|
|
|
|
return file |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const normalize = (filesList) => { |
|
|
|
|
const folders = [] |
|
|
|
|
const files = [] |
|
|
|
|
Object.keys(filesList || {}).forEach(key => { |
|
|
|
|
if (filesList[key].isDirectory) { |
|
|
|
|
folders.push({ |
|
|
|
|
filename: key, |
|
|
|
|
data: filesList[key] |
|
|
|
|
}) |
|
|
|
|
} else { |
|
|
|
|
files.push({ |
|
|
|
|
filename: key, |
|
|
|
|
data: filesList[key] |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
return [...folders, ...files] |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
module.exports = DGitProvider |
|
|
|
|