modified api calls

pull/11/head
ioedeveloper 4 years ago
parent 2f05d081c3
commit eaefa3ca61
  1. 87
      apps/remix-ide/src/app/files/remixDProvider.js
  2. 2
      apps/remix-ide/src/app/files/remixd-handle.js

@ -60,7 +60,8 @@ module.exports = class RemixDProvider {
} }
init (cb) { init (cb) {
this._appManager.call('remixd', 'folderIsReadOnly', {}).then((result) => { this._appManager.call('remixd', 'folderIsReadOnly', {})
.then((result) => {
this._isReady = true this._isReady = true
this._readOnlyMode = result this._readOnlyMode = result
cb && cb() cb && cb()
@ -82,7 +83,8 @@ module.exports = class RemixDProvider {
exists (path, cb) { exists (path, cb) {
const unprefixedpath = this.removePrefix(path) const unprefixedpath = this.removePrefix(path)
return this._appManager.call('remixd', 'exists', { path: unprefixedpath }).then((result) => { return this._appManager.call('remixd', 'exists', { path: unprefixedpath })
.then((result) => {
return cb(null, result) return cb(null, result)
}).catch((error) => { }).catch((error) => {
return cb(error) return cb(error)
@ -99,10 +101,11 @@ module.exports = class RemixDProvider {
get (path, cb) { get (path, cb) {
var unprefixedpath = this.removePrefix(path) var unprefixedpath = this.removePrefix(path)
this._appManager.call('remixd', 'get', { path: unprefixedpath }).then((file) => { this._appManager.call('remixd', 'get', { path: unprefixedpath })
.then((file) => {
this.filesContent[path] = file.content this.filesContent[path] = file.content
if (file.readonly) { this._readOnlyFiles[path] = 1 } if (file.readonly) { this._readOnlyFiles[path] = 1 }
cb(error, file.content) cb(null, file.content)
}).catch((error) => { }).catch((error) => {
// display the last known content. // display the last known content.
// TODO should perhaps better warn the user that the file is not synced. // TODO should perhaps better warn the user that the file is not synced.
@ -117,47 +120,52 @@ module.exports = class RemixDProvider {
const path = this.type + '/' + unprefixedpath const path = this.type + '/' + unprefixedpath
this.event.trigger('fileChanged', [path]) this.event.trigger('fileChanged', [path])
}).catch((error) => {
if (cb) cb(error)
}) })
return true
} }
isReadOnly (path) { isReadOnly (path) {
return this._readOnlyMode || this._readOnlyFiles[path] === 1 return this._readOnlyMode || this._readOnlyFiles[path] === 1
} }
async remove (path) { remove (path) {
var unprefixedpath = this.removePrefix(path) const unprefixedpath = this.removePrefix(path)
const callId = await this._appManager.call('remixd', 'remove', {path: unprefixedpath}, (error, result) => {
if (error) console.log(error) this._appManager.call('remixd', 'remove', { path: unprefixedpath })
var path = this.type + '/' + unprefixedpath .then(result => {
console.log('result: ', result)
const path = this.type + '/' + unprefixedpath
delete this.filesContent[path] delete this.filesContent[path]
this.init(() => { this.init(() => {
this.event.trigger('fileRemoved', [path]) this.event.trigger('fileRemoved', [path])
}) })
}).catch(error => {
if (error) console.log(error)
}) })
return await this._appManager.receiveResponse(callId)
} }
rename (oldPath, newPath, isFolder) { rename (oldPath, newPath, isFolder) {
var unprefixedoldPath = this.removePrefix(oldPath) const unprefixedoldPath = this.removePrefix(oldPath)
var unprefixednewPath = this.removePrefix(newPath) const unprefixednewPath = this.removePrefix(newPath)
this._appManager.call('remixd', 'rename', {oldPath: unprefixedoldPath, newPath: unprefixednewPath}, (error, result) => {
if (error) { return this._appManager.call('remixd', 'rename', { oldPath: unprefixedoldPath, newPath: unprefixednewPath })
console.log(error) .then(result => {
if (this.error[error.code]) error = this.error[error.code] const newPath = this.type + '/' + unprefixednewPath
this.event.trigger('fileRenamedError', [this.error[error.code]]) const oldPath = this.type + '/' + unprefixedoldPath
} else {
var newPath = this.type + '/' + unprefixednewPath
var oldPath = this.type + '/' + unprefixedoldPath
this.filesContent[newPath] = this.filesContent[oldPath] this.filesContent[newPath] = this.filesContent[oldPath]
delete this.filesContent[oldPath] delete this.filesContent[oldPath]
this.init(() => { this.init(() => {
this.event.trigger('fileRenamed', [oldPath, newPath, isFolder]) this.event.trigger('fileRenamed', [oldPath, newPath, isFolder])
}) })
} return result
}).catch(error => {
console.log(error)
if (this.error[error.code]) error = this.error[error.code]
this.event.trigger('fileRenamedError', [this.error[error.code]])
}) })
return true
} }
isExternalFolder (path) { isExternalFolder (path) {
@ -180,9 +188,8 @@ module.exports = class RemixDProvider {
async isDirectory (path) { async isDirectory (path) {
const unprefixedpath = this.removePrefix(path) const unprefixedpath = this.removePrefix(path)
const callId = await this._appManager.call('remixd', 'isDirectory', {path: unprefixedpath})
return await this._remixd.receiveResponse(callId) return await this._appManager.call('remixd', 'isDirectory', {path: unprefixedpath})
} }
async isFile (path) { async isFile (path) {
@ -192,26 +199,42 @@ module.exports = class RemixDProvider {
} }
} }
function remixapi (appManager, self) { function remixapi (appManager, remixd) {
const read = (path, callback) => { const read = (path, callback) => {
path = '' + (path || '') path = '' + (path || '')
path = pathtool.join('./', path) path = pathtool.join('./', path)
appManager.call('remixd', 'get', { path }, (error, content) => callback(error, content)) appManager.call('remixd', 'get', { path }).then((content) => {
callback(null, content)
}).catch((error) => {
callback(error)
})
} }
const write = (path, content, callback) => { const write = (path, content, callback) => {
path = '' + (path || '') path = '' + (path || '')
path = pathtool.join('./', path) path = pathtool.join('./', path)
appManager.call('remixd', 'set', { path, content }, (error, result) => callback(error, result)) appManager.call('remixd', 'set', { path, content }).then((result) => {
callback(null, result)
}).catch((error) => {
callback(error)
})
} }
const rename = (path, newpath, callback) => { const rename = (path, newpath, callback) => {
path = '' + (path || '') path = '' + (path || '')
path = pathtool.join('./', path) path = pathtool.join('./', path)
appManager.call('remixd', 'rename', { oldPath: path, newPath: newpath }, (error, result) => callback(error, result)) appManager.call('remixd', 'rename', { oldPath: path, newPath: newpath }).then((result) => {
callback(null, result)
}).catch((error) => {
callback(error)
})
} }
const remove = (path, callback) => { const remove = (path, callback) => {
path = '' + (path || '') path = '' + (path || '')
path = pathtool.join('./', path) path = pathtool.join('./', path)
appManager.call('remixd', 'remove', { path }, (error, result) => callback(error, result)) appManager.call('remixd', 'remove', { path }).then((result) => {
callback(null, result)
}).catch((error) => {
callback(error)
})
} }
const dir = (path, callback) => { const dir = (path, callback) => {
path = '' + (path || '') path = '' + (path || '')
@ -223,6 +246,6 @@ function remixapi (appManager, self) {
}) })
} }
const exit = () => { remixd.close() } const exit = () => { remixd.close() }
const api = { read, write, rename, remove, dir, exit, event: self.event } const api = { read, write, rename, remove, dir, exit, event: remixd.event }
return api return api
} }

@ -21,7 +21,7 @@ var css = csjs`
const profile = { const profile = {
name: 'remixd', name: 'remixd',
url: 'ws://127.0.0.1:65520', url: 'ws://127.0.0.1:65520',
methods: ['folderIsReadOnly', 'resolveDirectory', 'get', 'exists', 'isFile'], methods: ['folderIsReadOnly', 'resolveDirectory', 'get', 'exists', 'isFile', 'set', 'rename', 'remove', 'isDirectory', 'list'],
events: [], events: [],
description: 'Using Remixd daemon, allow to access file system', description: 'Using Remixd daemon, allow to access file system',
kind: 'other', kind: 'other',

Loading…
Cancel
Save