|
|
|
@ -201,15 +201,15 @@ class FileManager extends Plugin { |
|
|
|
|
* @param {string} data content to write on the file |
|
|
|
|
* @returns {void} |
|
|
|
|
*/ |
|
|
|
|
async writeFile(path, data, isBuffer?) { |
|
|
|
|
async writeFile(path, data, options?) { |
|
|
|
|
try { |
|
|
|
|
path = this.normalize(path) |
|
|
|
|
path = this.limitPluginScope(path) |
|
|
|
|
if (await this.exists(path)) { |
|
|
|
|
await this._handleIsFile(path, `Cannot write file ${path}`) |
|
|
|
|
return await this.setFileContent(path, data, isBuffer) |
|
|
|
|
return await this.setFileContent(path, data, options) |
|
|
|
|
} else { |
|
|
|
|
const ret = await this.setFileContent(path, data, isBuffer) |
|
|
|
|
const ret = await this.setFileContent(path, data, options) |
|
|
|
|
this.emit('fileAdded', path) |
|
|
|
|
return ret |
|
|
|
|
} |
|
|
|
@ -255,13 +255,13 @@ class FileManager extends Plugin { |
|
|
|
|
* @param {string} path path of the file |
|
|
|
|
* @returns {string} content of the file |
|
|
|
|
*/ |
|
|
|
|
async readFile(path, isBuffer?) { |
|
|
|
|
async readFile(path, options?) { |
|
|
|
|
try { |
|
|
|
|
path = this.normalize(path) |
|
|
|
|
path = this.limitPluginScope(path) |
|
|
|
|
await this._handleExists(path, `Cannot read file ${path}`) |
|
|
|
|
await this._handleIsFile(path, `Cannot read file ${path}`) |
|
|
|
|
return this.getFileContent(path, isBuffer) |
|
|
|
|
return this.getFileContent(path, options) |
|
|
|
|
} catch (e) { |
|
|
|
|
throw new Error(e) |
|
|
|
|
} |
|
|
|
@ -579,7 +579,7 @@ class FileManager extends Plugin { |
|
|
|
|
return path ? path[1] : '/' |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
getFileContent(path, isBuffer?) { |
|
|
|
|
getFileContent(path, options?) { |
|
|
|
|
const provider = this.fileProviderOf(path) |
|
|
|
|
|
|
|
|
|
if (!provider) throw createError({ code: 'ENOENT', message: `${path} not available` }) |
|
|
|
@ -589,11 +589,11 @@ class FileManager extends Plugin { |
|
|
|
|
provider.get(path, (err, content) => { |
|
|
|
|
if (err) reject(err) |
|
|
|
|
resolve(content) |
|
|
|
|
}, isBuffer) |
|
|
|
|
}, options) |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
async setFileContent(path, content, isBuffer?) { |
|
|
|
|
async setFileContent(path, content, options?) { |
|
|
|
|
if (this.currentRequest) { |
|
|
|
|
const canCall = await this.askUserPermission(`writeFile`, `modifying ${path} ...`) |
|
|
|
|
const required = this.appManager.isRequired(this.currentRequest.from) |
|
|
|
@ -602,10 +602,10 @@ class FileManager extends Plugin { |
|
|
|
|
this.call('notification', 'toast', fileChangedToastMsg(this.currentRequest.from, path)) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return await this._setFileInternal(path, content, isBuffer) |
|
|
|
|
return await this._setFileInternal(path, content, options) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
_setFileInternal(path, content, isBuffer?) { |
|
|
|
|
_setFileInternal(path, content, options?) { |
|
|
|
|
const provider = this.fileProviderOf(path) |
|
|
|
|
if (!provider) throw createError({ code: 'ENOENT', message: `${path} not available` }) |
|
|
|
|
// TODO : Add permission
|
|
|
|
@ -616,7 +616,7 @@ class FileManager extends Plugin { |
|
|
|
|
this.syncEditor(path) |
|
|
|
|
this.emit('fileSaved', path) |
|
|
|
|
resolve(true) |
|
|
|
|
}, isBuffer) |
|
|
|
|
}, options) |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|