Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
baas-ide
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
guxukai
baas-ide
Commits
3968ec0b
Commit
3968ec0b
authored
Mar 30, 2021
by
ioedeveloper
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Restrict file creation to workspace
parent
b9f3b137
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
43 additions
and
32 deletions
+43
-32
fileManager.js
apps/remix-ide/src/app/files/fileManager.js
+1
-9
workspaceFileProvider.js
apps/remix-ide/src/app/files/workspaceFileProvider.js
+14
-2
file-explorer.tsx
libs/remix-ui/file-explorer/src/lib/file-explorer.tsx
+28
-21
No files found.
apps/remix-ide/src/app/files/fileManager.js
View file @
3968ec0b
...
@@ -9,7 +9,6 @@ const globalRegistry = require('../../global/registry')
...
@@ -9,7 +9,6 @@ const globalRegistry = require('../../global/registry')
const
toaster
=
require
(
'../ui/tooltip'
)
const
toaster
=
require
(
'../ui/tooltip'
)
const
modalDialogCustom
=
require
(
'../ui/modal-dialog-custom'
)
const
modalDialogCustom
=
require
(
'../ui/modal-dialog-custom'
)
const
helper
=
require
(
'../../lib/helper.js'
)
const
helper
=
require
(
'../../lib/helper.js'
)
const
path
=
require
(
'path'
)
/*
/*
attach to files event (removed renamed)
attach to files event (removed renamed)
...
@@ -59,14 +58,7 @@ class FileManager extends Plugin {
...
@@ -59,14 +58,7 @@ class FileManager extends Plugin {
}
}
limitPluginScope
(
path
)
{
limitPluginScope
(
path
)
{
const
workspace
=
this
.
fileManager
.
currentWorkspace
()
return
path
.
replace
(
/^
\/
browser
\/
/
,
''
).
replace
(
/^browser
\/
/
,
''
)
// forbids plugin to access the root filesystem
if
(
workspace
)
{
}
else
{
}
}
}
/**
/**
...
...
apps/remix-ide/src/app/files/workspaceFileProvider.js
View file @
3968ec0b
'use strict'
'use strict'
const
FileProvider
=
require
(
'./fileProvider'
)
const
FileProvider
=
require
(
'./fileProvider'
)
const
path
=
require
(
'path'
)
class
WorkspaceFileProvider
extends
FileProvider
{
class
WorkspaceFileProvider
extends
FileProvider
{
constructor
()
{
constructor
()
{
...
@@ -32,8 +33,19 @@ class WorkspaceFileProvider extends FileProvider {
...
@@ -32,8 +33,19 @@ class WorkspaceFileProvider extends FileProvider {
if
(
path
.
startsWith
(
this
.
workspacesPath
+
'/'
+
this
.
workspace
))
return
path
if
(
path
.
startsWith
(
this
.
workspacesPath
+
'/'
+
this
.
workspace
))
return
path
if
(
path
.
startsWith
(
this
.
workspace
))
return
this
.
workspacesPath
+
'/'
+
this
.
workspace
if
(
path
.
startsWith
(
this
.
workspace
))
return
this
.
workspacesPath
+
'/'
+
this
.
workspace
path
=
super
.
removePrefix
(
path
)
path
=
super
.
removePrefix
(
path
)
const
ret
=
this
.
workspacesPath
+
'/'
+
this
.
workspace
+
'/'
+
(
path
===
'/'
?
''
:
path
)
let
ret
=
this
.
workspacesPath
+
'/'
+
this
.
workspace
+
'/'
+
(
path
===
'/'
?
''
:
path
)
return
ret
.
replace
(
/^
\/
|
\/
$/g
,
''
)
ret
=
ret
.
replace
(
/^
\/
|
\/
$/g
,
''
)
if
(
!
this
.
isSubDirectory
(
this
.
workspacesPath
+
'/'
+
this
.
workspace
,
ret
))
throw
new
Error
(
'Cannot read/write to path outside workspace'
)
return
ret
}
isSubDirectory
(
parent
,
child
)
{
if
(
!
parent
)
return
false
if
(
parent
===
child
)
return
true
const
relative
=
path
.
relative
(
parent
,
child
)
return
!!
relative
&&
relative
.
split
(
path
.
sep
)[
0
]
!==
'..'
}
}
resolveDirectory
(
path
,
callback
)
{
resolveDirectory
(
path
,
callback
)
{
...
...
libs/remix-ui/file-explorer/src/lib/file-explorer.tsx
View file @
3968ec0b
...
@@ -314,26 +314,32 @@ export const FileExplorer = (props: FileExplorerProps) => {
...
@@ -314,26 +314,32 @@ export const FileExplorer = (props: FileExplorerProps) => {
const
createNewFile
=
(
newFilePath
:
string
)
=>
{
const
createNewFile
=
(
newFilePath
:
string
)
=>
{
const
fileManager
=
state
.
fileManager
const
fileManager
=
state
.
fileManager
if
(
helper
.
checkSpecialChars
(
newFilePath
)
||
helper
.
checkSlash
(
newFilePath
))
return
toast
(
'special characters are not allowed'
)
try
{
helper
.
createNonClashingName
(
newFilePath
,
filesProvider
,
async
(
error
,
newName
)
=>
{
helper
.
createNonClashingName
(
newFilePath
,
filesProvider
,
async
(
error
,
newName
)
=>
{
if
(
error
)
{
if
(
error
)
{
modal
(
'Create File Failed'
,
error
,
{
modal
(
'Create File Failed'
,
error
,
{
label
:
'Close'
,
label
:
'Close'
,
fn
:
async
()
=>
{}
fn
:
async
()
=>
{}
},
null
)
},
null
)
}
else
{
const
createFile
=
await
fileManager
.
writeFile
(
newName
,
''
)
if
(
!
createFile
)
{
return
toast
(
'Failed to create file '
+
newName
)
}
else
{
}
else
{
await
fileManager
.
open
(
newName
)
const
createFile
=
await
fileManager
.
writeFile
(
newName
,
''
)
setState
(
prevState
=>
{
return
{
...
prevState
,
focusElement
:
[{
key
:
newName
,
type
:
'file'
}]
}
if
(
!
createFile
)
{
})
return
toast
(
'Failed to create file '
+
newName
)
}
else
{
await
fileManager
.
open
(
newName
)
setState
(
prevState
=>
{
return
{
...
prevState
,
focusElement
:
[{
key
:
newName
,
type
:
'file'
}]
}
})
}
}
}
}
})
})
}
catch
(
error
)
{
return
modal
(
'File Creation Failed'
,
error
.
message
,
{
label
:
'Close'
,
fn
:
async
()
=>
{}
},
null
)
}
}
}
const
createNewFolder
=
async
(
newFolderPath
:
string
)
=>
{
const
createNewFolder
=
async
(
newFolderPath
:
string
)
=>
{
...
@@ -354,8 +360,10 @@ export const FileExplorer = (props: FileExplorerProps) => {
...
@@ -354,8 +360,10 @@ export const FileExplorer = (props: FileExplorerProps) => {
return
{
...
prevState
,
focusElement
:
[{
key
:
newFolderPath
,
type
:
'folder'
}]
}
return
{
...
prevState
,
focusElement
:
[{
key
:
newFolderPath
,
type
:
'folder'
}]
}
})
})
}
catch
(
e
)
{
}
catch
(
e
)
{
console
.
log
(
'error: '
,
e
)
return
modal
(
'File Creation Failed'
,
e
.
message
,
{
toast
(
'Failed to create folder: '
+
newFolderPath
)
label
:
'Close'
,
fn
:
async
()
=>
{}
},
null
)
}
}
}
}
...
@@ -393,7 +401,6 @@ export const FileExplorer = (props: FileExplorerProps) => {
...
@@ -393,7 +401,6 @@ export const FileExplorer = (props: FileExplorerProps) => {
fn
:
()
=>
{}
fn
:
()
=>
{}
},
null
)
},
null
)
}
else
{
}
else
{
if
(
helper
.
checkSpecialChars
(
newPath
)
||
helper
.
checkSlash
(
newPath
))
throw
new
Error
(
'special characters are not allowed'
)
await
fileManager
.
rename
(
oldPath
,
newPath
)
await
fileManager
.
rename
(
oldPath
,
newPath
)
}
}
}
catch
(
error
)
{
}
catch
(
error
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment