|
|
@ -80,7 +80,7 @@ class FileProvider { |
|
|
|
async _exists (path) { |
|
|
|
async _exists (path) { |
|
|
|
path = this.getPathFromUrl(path) || path // ensure we actually use the normalized path from here
|
|
|
|
path = this.getPathFromUrl(path) || path // ensure we actually use the normalized path from here
|
|
|
|
var unprefixedpath = this.removePrefix(path) |
|
|
|
var unprefixedpath = this.removePrefix(path) |
|
|
|
return path === this.type ? true : await window.remixFileSystem.exists(this.addSlash(unprefixedpath)) |
|
|
|
return path === this.type ? true : await window.remixFileSystem.exists(unprefixedpath) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
init (cb) { |
|
|
|
init (cb) { |
|
|
@ -91,8 +91,7 @@ class FileProvider { |
|
|
|
path = this.getPathFromUrl(path) || path // ensure we actually use the normalized path from here
|
|
|
|
path = this.getPathFromUrl(path) || path // ensure we actually use the normalized path from here
|
|
|
|
var unprefixedpath = this.removePrefix(path) |
|
|
|
var unprefixedpath = this.removePrefix(path) |
|
|
|
try { |
|
|
|
try { |
|
|
|
console.log('getting', this.addSlash(unprefixedpath)) |
|
|
|
const content = await window.remixFileSystem.readFile(unprefixedpath, 'utf8') |
|
|
|
const content = await window.remixFileSystem.readFile(this.addSlash(unprefixedpath), 'utf8') |
|
|
|
|
|
|
|
if (cb) cb(null, content) |
|
|
|
if (cb) cb(null, content) |
|
|
|
return content |
|
|
|
return content |
|
|
|
} catch (err) { |
|
|
|
} catch (err) { |
|
|
@ -103,15 +102,15 @@ class FileProvider { |
|
|
|
|
|
|
|
|
|
|
|
async set (path, content, cb) { |
|
|
|
async set (path, content, cb) { |
|
|
|
var unprefixedpath = this.removePrefix(path) |
|
|
|
var unprefixedpath = this.removePrefix(path) |
|
|
|
const exists = await window.remixFileSystem.exists(this.addSlash(unprefixedpath)) |
|
|
|
const exists = await window.remixFileSystem.exists(unprefixedpath) |
|
|
|
if (exists && await window.remixFileSystem.readFile(this.addSlash(unprefixedpath), 'utf8') === content) { |
|
|
|
if (exists && await window.remixFileSystem.readFile(unprefixedpath, 'utf8') === content) { |
|
|
|
if (cb) cb() |
|
|
|
if (cb) cb() |
|
|
|
return null |
|
|
|
return null |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
await this.createDir(path.substr(0, path.lastIndexOf('/'))) |
|
|
|
await this.createDir(path.substr(0, path.lastIndexOf('/'))) |
|
|
|
try { |
|
|
|
try { |
|
|
|
await window.remixFileSystem.writeFile(this.addSlash(unprefixedpath), content, 'utf8') |
|
|
|
await window.remixFileSystem.writeFile(unprefixedpath, content, 'utf8') |
|
|
|
} catch (e) { |
|
|
|
} catch (e) { |
|
|
|
if (cb) cb(e) |
|
|
|
if (cb) cb(e) |
|
|
|
return false |
|
|
|
return false |
|
|
@ -156,13 +155,13 @@ class FileProvider { |
|
|
|
|
|
|
|
|
|
|
|
async isDirectory (path) { |
|
|
|
async isDirectory (path) { |
|
|
|
const unprefixedpath = this.removePrefix(path) |
|
|
|
const unprefixedpath = this.removePrefix(path) |
|
|
|
return path === this.type ? true : (await window.remixFileSystem.statExtended(this.addSlash(unprefixedpath))).isDirectory() |
|
|
|
return path === this.type ? true : (await window.remixFileSystem.stat(unprefixedpath)).isDirectory() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async isFile (path) { |
|
|
|
async isFile (path) { |
|
|
|
path = this.getPathFromUrl(path) || path // ensure we actually use the normalized path from here
|
|
|
|
path = this.getPathFromUrl(path) || path // ensure we actually use the normalized path from here
|
|
|
|
path = this.removePrefix(path) |
|
|
|
path = this.removePrefix(path) |
|
|
|
return (await window.remixFileSystem.statExtended(this.addSlash(path))).isFile() |
|
|
|
return (await window.remixFileSystem.stat(path)).isFile() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -171,26 +170,26 @@ class FileProvider { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
async remove (path) { |
|
|
|
async remove (path) { |
|
|
|
path = this.removePrefix(path) |
|
|
|
path = this.removePrefix(path) |
|
|
|
if (await window.remixFileSystem.exists(this.addSlash(path))) { |
|
|
|
if (await window.remixFileSystem.exists(path)) { |
|
|
|
const stat = await window.remixFileSystem.statExtended(this.addSlash(path)) |
|
|
|
const stat = await window.remixFileSystem.stat(path) |
|
|
|
try { |
|
|
|
try { |
|
|
|
if (!stat.isDirectory()) { |
|
|
|
if (!stat.isDirectory()) { |
|
|
|
return (this.removeFile(path)) |
|
|
|
return (this.removeFile(path)) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
const items = await window.remixFileSystem.readdir(this.addSlash(path)) |
|
|
|
const items = await window.remixFileSystem.readdir(path) |
|
|
|
if (items.length !== 0) { |
|
|
|
if (items.length !== 0) { |
|
|
|
for (const item of items) { |
|
|
|
for (const item of items) { |
|
|
|
const curPath = `${path}${path.endsWith('/') ? '' : '/'}${item}` |
|
|
|
const curPath = `${path}${path.endsWith('/') ? '' : '/'}${item}` |
|
|
|
if ((await window.remixFileSystem.statExtended(this.addSlash(curPath))).isDirectory()) { // delete folder
|
|
|
|
if ((await window.remixFileSystem.stat(curPath)).isDirectory()) { // delete folder
|
|
|
|
await this.remove(curPath) |
|
|
|
await this.remove(curPath) |
|
|
|
} else { // delete file
|
|
|
|
} else { // delete file
|
|
|
|
await this.removeFile(curPath) |
|
|
|
await this.removeFile(curPath) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
await window.remixFileSystem.rmdir(this.addSlash(path)) |
|
|
|
await window.remixFileSystem.rmdir(path) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
// folder is empty
|
|
|
|
// folder is empty
|
|
|
|
await window.remixFileSystem.rmdir(this.addSlash(path)) |
|
|
|
await window.remixFileSystem.rmdir(path) |
|
|
|
} |
|
|
|
} |
|
|
|
this.event.emit('fileRemoved', this._normalizePath(path)) |
|
|
|
this.event.emit('fileRemoved', this._normalizePath(path)) |
|
|
|
} |
|
|
|
} |
|
|
@ -213,18 +212,18 @@ class FileProvider { |
|
|
|
|
|
|
|
|
|
|
|
const json = {} |
|
|
|
const json = {} |
|
|
|
path = this.removePrefix(path) |
|
|
|
path = this.removePrefix(path) |
|
|
|
if (await window.remixFileSystem.exists(this.addSlash(path))) { |
|
|
|
if (await window.remixFileSystem.exists(path)) { |
|
|
|
try { |
|
|
|
try { |
|
|
|
const items = await window.remixFileSystem.readdir(this.addSlash(path)) |
|
|
|
const items = await window.remixFileSystem.readdir(path) |
|
|
|
visitFolder({ path }) |
|
|
|
visitFolder({ path }) |
|
|
|
if (items.length !== 0) { |
|
|
|
if (items.length !== 0) { |
|
|
|
for (const item of items) { |
|
|
|
for (const item of items) { |
|
|
|
const file = {} |
|
|
|
const file = {} |
|
|
|
const curPath = `${path}${path.endsWith('/') ? '' : '/'}${item}` |
|
|
|
const curPath = `${path}${path.endsWith('/') ? '' : '/'}${item}` |
|
|
|
if ((await window.remixFileSystem.statExtended(this.addSlash(curPath))).isDirectory()) { |
|
|
|
if ((await window.remixFileSystem.stat(curPath)).isDirectory()) { |
|
|
|
file.children = await this._copyFolderToJsonInternal(curPath, visitFile, visitFolder) |
|
|
|
file.children = await this._copyFolderToJsonInternal(curPath, visitFile, visitFolder) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
file.content = await window.remixFileSystem.readFile(this.addSlash(curPath), 'utf8') |
|
|
|
file.content = await window.remixFileSystem.readFile(curPath, 'utf8') |
|
|
|
visitFile({ path: curPath, content: file.content }) |
|
|
|
visitFile({ path: curPath, content: file.content }) |
|
|
|
} |
|
|
|
} |
|
|
|
json[curPath] = file |
|
|
|
json[curPath] = file |
|
|
@ -252,8 +251,8 @@ class FileProvider { |
|
|
|
|
|
|
|
|
|
|
|
async removeFile (path) { |
|
|
|
async removeFile (path) { |
|
|
|
path = this.removePrefix(path) |
|
|
|
path = this.removePrefix(path) |
|
|
|
if (await window.remixFileSystem.exists(this.addSlash(path)) && !(await window.remixFileSystem.statExtended(this.addSlash(path))).isDirectory()) { |
|
|
|
if (await window.remixFileSystem.exists(path) && !(await window.remixFileSystem.stat(path)).isDirectory()) { |
|
|
|
await window.remixFileSystem.unlink(this.addSlash(path)) |
|
|
|
await window.remixFileSystem.unlink(path) |
|
|
|
this.event.emit('fileRemoved', this._normalizePath(path)) |
|
|
|
this.event.emit('fileRemoved', this._normalizePath(path)) |
|
|
|
return true |
|
|
|
return true |
|
|
|
} else return false |
|
|
|
} else return false |
|
|
@ -263,7 +262,7 @@ class FileProvider { |
|
|
|
var unprefixedoldPath = this.removePrefix(oldPath) |
|
|
|
var unprefixedoldPath = this.removePrefix(oldPath) |
|
|
|
var unprefixednewPath = this.removePrefix(newPath) |
|
|
|
var unprefixednewPath = this.removePrefix(newPath) |
|
|
|
if (await this._exists(unprefixedoldPath)) { |
|
|
|
if (await this._exists(unprefixedoldPath)) { |
|
|
|
await window.remixFileSystem.rename(this.addSlash(unprefixedoldPath), this.addSlash(unprefixednewPath)) |
|
|
|
await window.remixFileSystem.rename(unprefixedoldPath, unprefixednewPath) |
|
|
|
this.event.emit('fileRenamed', |
|
|
|
this.event.emit('fileRenamed', |
|
|
|
this._normalizePath(unprefixedoldPath), |
|
|
|
this._normalizePath(unprefixedoldPath), |
|
|
|
this._normalizePath(unprefixednewPath), |
|
|
|
this._normalizePath(unprefixednewPath), |
|
|
@ -278,7 +277,7 @@ class FileProvider { |
|
|
|
path = this.removePrefix(path) |
|
|
|
path = this.removePrefix(path) |
|
|
|
if (path.indexOf('/') !== 0) path = '/' + path |
|
|
|
if (path.indexOf('/') !== 0) path = '/' + path |
|
|
|
try { |
|
|
|
try { |
|
|
|
const files = await window.remixFileSystem.readdir(this.addSlash(path)) |
|
|
|
const files = await window.remixFileSystem.readdir(path) |
|
|
|
const ret = {} |
|
|
|
const ret = {} |
|
|
|
|
|
|
|
|
|
|
|
if (files) { |
|
|
|
if (files) { |
|
|
@ -286,7 +285,7 @@ class FileProvider { |
|
|
|
path = path.replace(/^\/|\/$/g, '') // remove first and last slash
|
|
|
|
path = path.replace(/^\/|\/$/g, '') // remove first and last slash
|
|
|
|
element = element.replace(/^\/|\/$/g, '') // remove first and last slash
|
|
|
|
element = element.replace(/^\/|\/$/g, '') // remove first and last slash
|
|
|
|
const absPath = (path === '/' ? '' : path) + '/' + element |
|
|
|
const absPath = (path === '/' ? '' : path) + '/' + element |
|
|
|
ret[absPath.indexOf('/') === 0 ? absPath.substr(1, absPath.length) : absPath] = { isDirectory: (await window.remixFileSystem.statExtended(this.addSlash(absPath))).isDirectory() } |
|
|
|
ret[absPath.indexOf('/') === 0 ? absPath.substr(1, absPath.length) : absPath] = { isDirectory: (await window.remixFileSystem.stat(absPath)).isDirectory() } |
|
|
|
// ^ ret does not accept path starting with '/'
|
|
|
|
// ^ ret does not accept path starting with '/'
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -298,11 +297,6 @@ class FileProvider { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
addSlash (file) { |
|
|
|
|
|
|
|
if (!file.startsWith('/'))file = '/' + file |
|
|
|
|
|
|
|
return file |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
removePrefix (path) { |
|
|
|
removePrefix (path) { |
|
|
|
path = path.indexOf(this.type) === 0 ? path.replace(this.type, '') : path |
|
|
|
path = path.indexOf(this.type) === 0 ? path.replace(this.type, '') : path |
|
|
|
if (path === '') return '/' |
|
|
|
if (path === '') return '/' |
|
|
|