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
c9203f54
Commit
c9203f54
authored
Jun 09, 2020
by
ioedeveloper
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Modified exposed apis
parent
fc080222
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
20 deletions
+31
-20
remixd.ts
bin/remixd.ts
+1
-1
remixdClient.ts
src/services/remixdClient.ts
+26
-19
index.ts
types/index.ts
+4
-0
No files found.
bin/remixd.ts
View file @
c9203f54
#!/usr/bin/env node
import
WebSocket
from
'../src/websocket'
import
*
as
servicesList
from
'../src/serviceList'
import
*
as
WS
from
'ws
'
import
{
WS
}
from
'../types/index
'
const
program
=
require
(
'commander'
)
...
...
src/services/remixdClient.ts
View file @
c9203f54
import
*
as
WS
from
'ws'
import
{
PluginClient
}
from
'@remixproject/plugin'
import
{
SharedFolderArgs
,
TrackDownStreamUpdate
}
from
'../../types'
import
{
SharedFolderArgs
,
TrackDownStreamUpdate
,
WS
}
from
'../../types'
import
*
as
utils
from
'../utils'
const
isbinaryfile
=
require
(
'isbinaryfile'
)
const
fs
=
require
(
'fs-extra'
)
export
class
RemixdClient
extends
PluginClient
{
methods
:
[
'folderIsReadOnly'
,
'resolveDirectory'
]
methods
:
[
'folderIsReadOnly'
,
'resolveDirectory'
,
'get'
,
'exists'
,
'isFile'
]
trackDownStreamUpdate
:
TrackDownStreamUpdate
websocket
:
WS
currentSharedFolder
:
string
...
...
@@ -45,31 +44,36 @@ export class RemixdClient extends PluginClient {
return
this
.
readOnly
}
get
(
args
:
SharedFolderArgs
,
cb
:
Function
)
{
console
.
log
(
'called on server'
)
get
(
args
:
SharedFolderArgs
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
const
path
=
utils
.
absolutePath
(
args
.
path
,
this
.
currentSharedFolder
)
if
(
!
fs
.
existsSync
(
path
))
{
return
cb
(
'File not found '
+
path
)
reject
(
'File not found '
+
path
)
}
if
(
!
isRealPath
(
path
,
cb
))
return
if
(
!
isRealPath
(
path
))
return
isbinaryfile
(
path
,
(
error
:
Error
,
isBinary
:
boolean
)
=>
{
if
(
error
)
console
.
log
(
error
)
if
(
isBinary
)
{
cb
(
null
,
{
content
:
'<binary content not displayed>'
,
readonly
:
true
})
resolve
(
{
content
:
'<binary content not displayed>'
,
readonly
:
true
})
}
else
{
fs
.
readFile
(
path
,
'utf8'
,
(
error
:
Error
,
data
:
string
)
=>
{
if
(
error
)
console
.
log
(
error
)
cb
(
error
,
{
content
:
data
,
readonly
:
false
})
resolve
(
{
content
:
data
,
readonly
:
false
})
})
}
})
})
}
exists
(
args
:
SharedFolderArgs
,
cb
:
Function
)
{
exists
(
args
:
SharedFolderArgs
)
{
try
{
const
path
=
utils
.
absolutePath
(
args
.
path
,
this
.
currentSharedFolder
)
cb
(
null
,
fs
.
existsSync
(
path
))
return
fs
.
existsSync
(
path
)
}
catch
(
error
)
{
throw
new
Error
(
error
)
}
}
set
(
args
:
SharedFolderArgs
,
cb
:
Function
)
{
...
...
@@ -77,7 +81,7 @@ export class RemixdClient extends PluginClient {
const
isFolder
=
args
.
path
.
endsWith
(
'/'
)
const
path
=
utils
.
absolutePath
(
args
.
path
,
this
.
currentSharedFolder
)
if
(
fs
.
existsSync
(
path
)
&&
!
isRealPath
(
path
,
cb
))
return
if
(
fs
.
existsSync
(
path
)
&&
!
isRealPath
(
path
))
return
if
(
args
.
content
===
'undefined'
)
{
// no !!!!!
console
.
log
(
'trying to write "undefined" ! stopping.'
)
return
...
...
@@ -104,7 +108,7 @@ export class RemixdClient extends PluginClient {
}
const
newpath
=
utils
.
absolutePath
(
args
.
newPath
,
this
.
currentSharedFolder
)
if
(
!
isRealPath
(
oldpath
,
cb
))
return
if
(
!
isRealPath
(
oldpath
))
return
fs
.
move
(
oldpath
,
newpath
,
(
error
:
Error
,
data
:
string
)
=>
{
if
(
error
)
console
.
log
(
error
)
cb
(
error
,
data
)
...
...
@@ -118,7 +122,7 @@ export class RemixdClient extends PluginClient {
if
(
!
fs
.
existsSync
(
path
))
{
return
cb
(
'File not found '
+
path
)
}
if
(
!
isRealPath
(
path
,
cb
))
return
if
(
!
isRealPath
(
path
))
return
fs
.
remove
(
path
,
(
error
:
Error
)
=>
{
if
(
error
)
{
console
.
log
(
error
)
...
...
@@ -134,21 +138,25 @@ export class RemixdClient extends PluginClient {
cb
(
null
,
fs
.
statSync
(
path
).
isDirectory
())
}
isFile
(
args
:
SharedFolderArgs
,
cb
:
Function
)
{
isFile
(
args
:
SharedFolderArgs
)
{
try
{
const
path
=
utils
.
absolutePath
(
args
.
path
,
this
.
currentSharedFolder
)
cb
(
null
,
fs
.
statSync
(
path
).
isFile
())
return
fs
.
statSync
(
path
).
isFile
()
}
catch
(
error
)
{
throw
new
Error
(
error
)
}
}
}
function
isRealPath
(
path
:
string
,
cb
:
Function
)
{
function
isRealPath
(
path
:
string
)
{
const
realPath
=
fs
.
realpathSync
(
path
)
const
isRealPath
=
path
===
realPath
const
mes
=
'[WARN] Symbolic link modification not allowed : '
+
path
+
' | '
+
realPath
if
(
!
isRealPath
)
{
console
.
log
(
'
\
x1b[33m%s
\
x1b[0m'
,
mes
)
throw
new
Error
(
mes
)
}
if
(
cb
&&
!
isRealPath
)
cb
(
mes
)
return
isRealPath
}
\ No newline at end of file
types/index.ts
View file @
c9203f54
import
*
as
ServiceList
from
'../src/serviceList'
import
*
as
Websocket
from
'ws'
type
ServiceListKeys
=
keyof
typeof
ServiceList
;
...
...
@@ -27,3 +28,5 @@ export type ResolveDirectory = {
export
type
TrackDownStreamUpdate
=
KeyPairString
export
type
SharedFolderArgs
=
FolderArgs
&
KeyPairString
export
type
WS
=
typeof
Websocket
\ No newline at end of file
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