|
|
@ -61,6 +61,10 @@ class FileManager extends Plugin { |
|
|
|
return path.replace(/^\/browser\//, '').replace(/^browser\//, '') // forbids plugin to access the root filesystem
|
|
|
|
return path.replace(/^\/browser\//, '').replace(/^browser\//, '') // forbids plugin to access the root filesystem
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
normalize (path) { |
|
|
|
|
|
|
|
return path.replace(/^\/+/, '') |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Emit error if path doesn't exist |
|
|
|
* Emit error if path doesn't exist |
|
|
|
* @param {string} path path of the file/directory |
|
|
|
* @param {string} path path of the file/directory |
|
|
@ -119,6 +123,7 @@ class FileManager extends Plugin { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
exists (path) { |
|
|
|
exists (path) { |
|
|
|
try { |
|
|
|
try { |
|
|
|
|
|
|
|
path = this.normalize(path) |
|
|
|
path = this.limitPluginScope(path) |
|
|
|
path = this.limitPluginScope(path) |
|
|
|
const provider = this.fileProviderOf(path) |
|
|
|
const provider = this.fileProviderOf(path) |
|
|
|
const result = provider.exists(path) |
|
|
|
const result = provider.exists(path) |
|
|
@ -168,6 +173,7 @@ class FileManager extends Plugin { |
|
|
|
* @returns {void} |
|
|
|
* @returns {void} |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
async open (path) { |
|
|
|
async open (path) { |
|
|
|
|
|
|
|
path = this.normalize(path) |
|
|
|
path = this.limitPluginScope(path) |
|
|
|
path = this.limitPluginScope(path) |
|
|
|
path = this.getPathFromUrl(path).file |
|
|
|
path = this.getPathFromUrl(path).file |
|
|
|
await this._handleExists(path, `Cannot open file ${path}`) |
|
|
|
await this._handleExists(path, `Cannot open file ${path}`) |
|
|
@ -183,6 +189,7 @@ class FileManager extends Plugin { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
async writeFile (path, data) { |
|
|
|
async writeFile (path, data) { |
|
|
|
try { |
|
|
|
try { |
|
|
|
|
|
|
|
path = this.normalize(path) |
|
|
|
path = this.limitPluginScope(path) |
|
|
|
path = this.limitPluginScope(path) |
|
|
|
if (await this.exists(path)) { |
|
|
|
if (await this.exists(path)) { |
|
|
|
await this._handleIsFile(path, `Cannot write file ${path}`) |
|
|
|
await this._handleIsFile(path, `Cannot write file ${path}`) |
|
|
@ -204,6 +211,7 @@ class FileManager extends Plugin { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
async readFile (path) { |
|
|
|
async readFile (path) { |
|
|
|
try { |
|
|
|
try { |
|
|
|
|
|
|
|
path = this.normalize(path) |
|
|
|
path = this.limitPluginScope(path) |
|
|
|
path = this.limitPluginScope(path) |
|
|
|
await this._handleExists(path, `Cannot read file ${path}`) |
|
|
|
await this._handleExists(path, `Cannot read file ${path}`) |
|
|
|
await this._handleIsFile(path, `Cannot read file ${path}`) |
|
|
|
await this._handleIsFile(path, `Cannot read file ${path}`) |
|
|
@ -221,6 +229,8 @@ class FileManager extends Plugin { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
async copyFile (src, dest, customName) { |
|
|
|
async copyFile (src, dest, customName) { |
|
|
|
try { |
|
|
|
try { |
|
|
|
|
|
|
|
src = this.normalize(src) |
|
|
|
|
|
|
|
dest = this.normalize(dest) |
|
|
|
src = this.limitPluginScope(src) |
|
|
|
src = this.limitPluginScope(src) |
|
|
|
dest = this.limitPluginScope(dest) |
|
|
|
dest = this.limitPluginScope(dest) |
|
|
|
await this._handleExists(src, `Cannot copy from ${src}. Path does not exist.`) |
|
|
|
await this._handleExists(src, `Cannot copy from ${src}. Path does not exist.`) |
|
|
@ -245,6 +255,8 @@ class FileManager extends Plugin { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
async copyDir (src, dest) { |
|
|
|
async copyDir (src, dest) { |
|
|
|
try { |
|
|
|
try { |
|
|
|
|
|
|
|
src = this.normalize(src) |
|
|
|
|
|
|
|
dest = this.normalize(dest) |
|
|
|
src = this.limitPluginScope(src) |
|
|
|
src = this.limitPluginScope(src) |
|
|
|
dest = this.limitPluginScope(dest) |
|
|
|
dest = this.limitPluginScope(dest) |
|
|
|
await this._handleExists(src, `Cannot copy from ${src}. Path does not exist.`) |
|
|
|
await this._handleExists(src, `Cannot copy from ${src}. Path does not exist.`) |
|
|
@ -281,6 +293,8 @@ class FileManager extends Plugin { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
async rename (oldPath, newPath) { |
|
|
|
async rename (oldPath, newPath) { |
|
|
|
try { |
|
|
|
try { |
|
|
|
|
|
|
|
oldPath = this.normalize(oldPath) |
|
|
|
|
|
|
|
newPath = this.normalize(newPath) |
|
|
|
oldPath = this.limitPluginScope(oldPath) |
|
|
|
oldPath = this.limitPluginScope(oldPath) |
|
|
|
newPath = this.limitPluginScope(newPath) |
|
|
|
newPath = this.limitPluginScope(newPath) |
|
|
|
await this._handleExists(oldPath, `Cannot rename ${oldPath}`) |
|
|
|
await this._handleExists(oldPath, `Cannot rename ${oldPath}`) |
|
|
@ -313,6 +327,7 @@ class FileManager extends Plugin { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
async mkdir (path) { |
|
|
|
async mkdir (path) { |
|
|
|
try { |
|
|
|
try { |
|
|
|
|
|
|
|
path = this.normalize(path) |
|
|
|
path = this.limitPluginScope(path) |
|
|
|
path = this.limitPluginScope(path) |
|
|
|
if (await this.exists(path)) { |
|
|
|
if (await this.exists(path)) { |
|
|
|
throw createError({ code: 'EEXIST', message: `Cannot create directory ${path}` }) |
|
|
|
throw createError({ code: 'EEXIST', message: `Cannot create directory ${path}` }) |
|
|
@ -332,6 +347,7 @@ class FileManager extends Plugin { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
async readdir (path) { |
|
|
|
async readdir (path) { |
|
|
|
try { |
|
|
|
try { |
|
|
|
|
|
|
|
path = this.normalize(path) |
|
|
|
path = this.limitPluginScope(path) |
|
|
|
path = this.limitPluginScope(path) |
|
|
|
await this._handleExists(path) |
|
|
|
await this._handleExists(path) |
|
|
|
await this._handleIsDir(path) |
|
|
|
await this._handleIsDir(path) |
|
|
@ -356,6 +372,7 @@ class FileManager extends Plugin { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
async remove (path) { |
|
|
|
async remove (path) { |
|
|
|
try { |
|
|
|
try { |
|
|
|
|
|
|
|
path = this.normalize(path) |
|
|
|
path = this.limitPluginScope(path) |
|
|
|
path = this.limitPluginScope(path) |
|
|
|
await this._handleExists(path, `Cannot remove file or directory ${path}`) |
|
|
|
await this._handleExists(path, `Cannot remove file or directory ${path}`) |
|
|
|
const provider = this.fileProviderOf(path) |
|
|
|
const provider = this.fileProviderOf(path) |
|
|
|