|
@@ -1,8 +1,11 @@
|
|
|
package agi
|
|
|
|
|
|
import (
|
|
|
+ "crypto/md5"
|
|
|
+ "encoding/hex"
|
|
|
"encoding/json"
|
|
|
"errors"
|
|
|
+ "io"
|
|
|
"io/fs"
|
|
|
"log"
|
|
|
"os"
|
|
@@ -38,8 +41,7 @@ func (g *Gateway) injectFileLibFunctions(vm *otto.Otto, u *user.User) {
|
|
|
vpath, err := call.Argument(0).ToString()
|
|
|
if err != nil {
|
|
|
g.raiseError(err)
|
|
|
- reply, _ := vm.ToValue(false)
|
|
|
- return reply
|
|
|
+ return otto.FalseValue()
|
|
|
}
|
|
|
|
|
|
//Check for permission
|
|
@@ -50,24 +52,21 @@ func (g *Gateway) injectFileLibFunctions(vm *otto.Otto, u *user.User) {
|
|
|
content, err := call.Argument(1).ToString()
|
|
|
if err != nil {
|
|
|
g.raiseError(err)
|
|
|
- reply, _ := vm.ToValue(false)
|
|
|
- return reply
|
|
|
+ return otto.FalseValue()
|
|
|
}
|
|
|
|
|
|
//Check if there is quota for the given length
|
|
|
if !u.StorageQuota.HaveSpace(int64(len(content))) {
|
|
|
//User have no remaining storage quota
|
|
|
g.raiseError(errors.New("Storage Quota Fulled"))
|
|
|
- reply, _ := vm.ToValue(false)
|
|
|
- return reply
|
|
|
+ return otto.FalseValue()
|
|
|
}
|
|
|
|
|
|
//Translate the virtual path to realpath
|
|
|
fsh, rpath, err := virtualPathToRealPath(vpath, u)
|
|
|
if err != nil {
|
|
|
g.raiseError(err)
|
|
|
- reply, _ := vm.ToValue(false)
|
|
|
- return reply
|
|
|
+ return otto.FalseValue()
|
|
|
}
|
|
|
|
|
|
//Check if file already exists.
|
|
@@ -84,8 +83,7 @@ func (g *Gateway) injectFileLibFunctions(vm *otto.Otto, u *user.User) {
|
|
|
err = fsh.FileSystemAbstraction.WriteFile(rpath, []byte(content), 0755)
|
|
|
if err != nil {
|
|
|
g.raiseError(err)
|
|
|
- reply, _ := vm.ToValue(false)
|
|
|
- return reply
|
|
|
+ return otto.FalseValue()
|
|
|
}
|
|
|
|
|
|
//Add the filesize to user quota
|
|
@@ -99,8 +97,7 @@ func (g *Gateway) injectFileLibFunctions(vm *otto.Otto, u *user.User) {
|
|
|
vpath, err := call.Argument(0).ToString()
|
|
|
if err != nil {
|
|
|
g.raiseError(err)
|
|
|
- reply, _ := vm.ToValue(false)
|
|
|
- return reply
|
|
|
+ return otto.FalseValue()
|
|
|
}
|
|
|
|
|
|
//Check for permission
|
|
@@ -112,8 +109,7 @@ func (g *Gateway) injectFileLibFunctions(vm *otto.Otto, u *user.User) {
|
|
|
fsh, rpath, err := virtualPathToRealPath(vpath, u)
|
|
|
if err != nil {
|
|
|
g.raiseError(err)
|
|
|
- reply, _ := vm.ToValue(false)
|
|
|
- return reply
|
|
|
+ return otto.FalseValue()
|
|
|
}
|
|
|
|
|
|
//Check if file already exists.
|
|
@@ -126,8 +122,7 @@ func (g *Gateway) injectFileLibFunctions(vm *otto.Otto, u *user.User) {
|
|
|
}
|
|
|
} else {
|
|
|
g.raiseError(errors.New("File not exists"))
|
|
|
- reply, _ := vm.ToValue(false)
|
|
|
- return reply
|
|
|
+ return otto.FalseValue()
|
|
|
}
|
|
|
|
|
|
//Remove the file
|
|
@@ -142,8 +137,7 @@ func (g *Gateway) injectFileLibFunctions(vm *otto.Otto, u *user.User) {
|
|
|
vpath, err := call.Argument(0).ToString()
|
|
|
if err != nil {
|
|
|
g.raiseError(err)
|
|
|
- reply, _ := vm.ToValue(false)
|
|
|
- return reply
|
|
|
+ return otto.FalseValue()
|
|
|
}
|
|
|
|
|
|
//Check for permission
|
|
@@ -155,16 +149,14 @@ func (g *Gateway) injectFileLibFunctions(vm *otto.Otto, u *user.User) {
|
|
|
fsh, rpath, err := virtualPathToRealPath(vpath, u)
|
|
|
if err != nil {
|
|
|
g.raiseError(err)
|
|
|
- reply, _ := vm.ToValue(false)
|
|
|
- return reply
|
|
|
+ return otto.FalseValue()
|
|
|
}
|
|
|
|
|
|
//Create and write to file using ioUtil
|
|
|
content, err := fsh.FileSystemAbstraction.ReadFile(rpath)
|
|
|
if err != nil {
|
|
|
g.raiseError(err)
|
|
|
- reply, _ := vm.ToValue(false)
|
|
|
- return reply
|
|
|
+ return otto.FalseValue()
|
|
|
}
|
|
|
reply, _ := vm.ToValue(string(content))
|
|
|
return reply
|
|
@@ -177,16 +169,14 @@ func (g *Gateway) injectFileLibFunctions(vm *otto.Otto, u *user.User) {
|
|
|
vpath, err := call.Argument(0).ToString()
|
|
|
if err != nil {
|
|
|
g.raiseError(err)
|
|
|
- reply, _ := vm.ToValue(false)
|
|
|
- return reply
|
|
|
+ return otto.FalseValue()
|
|
|
}
|
|
|
|
|
|
//Translate the virtual path to realpath
|
|
|
fsh, rpath, err := virtualPathToRealPath(vpath, u)
|
|
|
if err != nil {
|
|
|
g.raiseError(err)
|
|
|
- reply, _ := vm.ToValue(false)
|
|
|
- return reply
|
|
|
+ return otto.FalseValue()
|
|
|
}
|
|
|
fshAbs := fsh.FileSystemAbstraction
|
|
|
|
|
@@ -194,8 +184,7 @@ func (g *Gateway) injectFileLibFunctions(vm *otto.Otto, u *user.User) {
|
|
|
fileList, err := fshAbs.Glob(rpath)
|
|
|
if err != nil {
|
|
|
g.raiseError(err)
|
|
|
- reply, _ := vm.ToValue(false)
|
|
|
- return reply
|
|
|
+ return otto.FalseValue()
|
|
|
}
|
|
|
|
|
|
//Translate all paths to virtual paths
|
|
@@ -221,8 +210,7 @@ func (g *Gateway) injectFileLibFunctions(vm *otto.Otto, u *user.User) {
|
|
|
vpath, err := call.Argument(0).ToString()
|
|
|
if err != nil {
|
|
|
g.raiseError(err)
|
|
|
- reply, _ := vm.ToValue(false)
|
|
|
- return reply
|
|
|
+ return otto.FalseValue()
|
|
|
}
|
|
|
mode, err := call.Argument(1).ToString()
|
|
|
if err != nil {
|
|
@@ -232,8 +220,7 @@ func (g *Gateway) injectFileLibFunctions(vm *otto.Otto, u *user.User) {
|
|
|
fsh, rpath, err := virtualPathToRealPath(vpath, u)
|
|
|
if err != nil {
|
|
|
g.raiseError(err)
|
|
|
- reply, _ := vm.ToValue(false)
|
|
|
- return reply
|
|
|
+ return otto.FalseValue()
|
|
|
}
|
|
|
results := []string{}
|
|
|
fsh.FileSystemAbstraction.Walk(rpath, func(path string, info os.FileInfo, err error) error {
|
|
@@ -273,8 +260,7 @@ func (g *Gateway) injectFileLibFunctions(vm *otto.Otto, u *user.User) {
|
|
|
regex, err := call.Argument(0).ToString()
|
|
|
if err != nil {
|
|
|
g.raiseError(err)
|
|
|
- reply, _ := vm.ToValue(false)
|
|
|
- return reply
|
|
|
+ return otto.FalseValue()
|
|
|
}
|
|
|
|
|
|
userSortMode, err := call.Argument(1).ToString()
|
|
@@ -309,8 +295,8 @@ func (g *Gateway) injectFileLibFunctions(vm *otto.Otto, u *user.User) {
|
|
|
//Rewrite and validate the sort mode
|
|
|
if userSortMode == "user" {
|
|
|
//Use user sorting mode.
|
|
|
- if g.Option.UserHandler.GetDatabase().KeyExists("fs-sortpref", u.Username+"/"+filepath.ToSlash(vrootPath)) {
|
|
|
- g.Option.UserHandler.GetDatabase().Read("fs-sortpref", u.Username+"/"+filepath.ToSlash(vrootPath), &userSortMode)
|
|
|
+ if g.Option.UserHandler.GetDatabase().KeyExists("fs-sortpref", u.Username+"/"+filepath.ToSlash(filepath.Clean(vrootPath))) {
|
|
|
+ g.Option.UserHandler.GetDatabase().Read("fs-sortpref", u.Username+"/"+filepath.ToSlash(filepath.Clean(vrootPath)), &userSortMode)
|
|
|
} else {
|
|
|
userSortMode = "default"
|
|
|
}
|
|
@@ -325,15 +311,13 @@ func (g *Gateway) injectFileLibFunctions(vm *otto.Otto, u *user.User) {
|
|
|
fsh, rrootPath, err := virtualPathToRealPath(vrootPath, u)
|
|
|
if err != nil {
|
|
|
g.raiseError(err)
|
|
|
- reply, _ := vm.ToValue(false)
|
|
|
- return reply
|
|
|
+ return otto.FalseValue()
|
|
|
}
|
|
|
|
|
|
suitableFiles, err := fsh.FileSystemAbstraction.Glob(filepath.Join(rrootPath, regexFilename))
|
|
|
if err != nil {
|
|
|
g.raiseError(err)
|
|
|
- reply, _ := vm.ToValue(false)
|
|
|
- return reply
|
|
|
+ return otto.FalseValue()
|
|
|
}
|
|
|
|
|
|
fileList := []string{}
|
|
@@ -370,8 +354,7 @@ func (g *Gateway) injectFileLibFunctions(vm *otto.Otto, u *user.User) {
|
|
|
regex, err := call.Argument(0).ToString()
|
|
|
if err != nil {
|
|
|
g.raiseError(err)
|
|
|
- reply, _ := vm.ToValue(false)
|
|
|
- return reply
|
|
|
+ return otto.FalseValue()
|
|
|
}
|
|
|
|
|
|
userSortMode, err := call.Argument(1).ToString()
|
|
@@ -390,8 +373,8 @@ func (g *Gateway) injectFileLibFunctions(vm *otto.Otto, u *user.User) {
|
|
|
//Rewrite and validate the sort mode
|
|
|
if userSortMode == "user" {
|
|
|
//Use user sorting mode.
|
|
|
- if g.Option.UserHandler.GetDatabase().KeyExists("fs-sortpref", u.Username+"/"+filepath.ToSlash(vrootPath)) {
|
|
|
- g.Option.UserHandler.GetDatabase().Read("fs-sortpref", u.Username+"/"+filepath.ToSlash(vrootPath), &userSortMode)
|
|
|
+ if g.Option.UserHandler.GetDatabase().KeyExists("fs-sortpref", u.Username+"/"+filepath.ToSlash(filepath.Clean(vrootPath))) {
|
|
|
+ g.Option.UserHandler.GetDatabase().Read("fs-sortpref", u.Username+"/"+filepath.ToSlash(filepath.Clean(vrootPath)), &userSortMode)
|
|
|
} else {
|
|
|
userSortMode = "default"
|
|
|
}
|
|
@@ -406,16 +389,14 @@ func (g *Gateway) injectFileLibFunctions(vm *otto.Otto, u *user.User) {
|
|
|
fsh, err := u.GetFileSystemHandlerFromVirtualPath(vrootPath)
|
|
|
if err != nil {
|
|
|
g.raiseError(err)
|
|
|
- reply, _ := vm.ToValue(false)
|
|
|
- return reply
|
|
|
+ return otto.FalseValue()
|
|
|
}
|
|
|
fshAbs := fsh.FileSystemAbstraction
|
|
|
rrootPath, _ := fshAbs.VirtualPathToRealPath(vrootPath, u.Username)
|
|
|
suitableFiles, err := fshAbs.Glob(filepath.Join(rrootPath, regexFilename))
|
|
|
if err != nil {
|
|
|
g.raiseError(err)
|
|
|
- reply, _ := vm.ToValue(false)
|
|
|
- return reply
|
|
|
+ return otto.FalseValue()
|
|
|
}
|
|
|
|
|
|
fileList := []string{}
|
|
@@ -450,8 +431,7 @@ func (g *Gateway) injectFileLibFunctions(vm *otto.Otto, u *user.User) {
|
|
|
vpath, err := call.Argument(0).ToString()
|
|
|
if err != nil {
|
|
|
g.raiseError(err)
|
|
|
- reply, _ := vm.ToValue(false)
|
|
|
- return reply
|
|
|
+ return otto.FalseValue()
|
|
|
}
|
|
|
|
|
|
//Check for permission
|
|
@@ -459,25 +439,42 @@ func (g *Gateway) injectFileLibFunctions(vm *otto.Otto, u *user.User) {
|
|
|
panic(vm.MakeCustomError("PermissionDenied", "Path access denied"))
|
|
|
}
|
|
|
|
|
|
+ userSortMode, err := call.Argument(1).ToString()
|
|
|
+ if err != nil || userSortMode == "" || userSortMode == "undefined" {
|
|
|
+ userSortMode = "default"
|
|
|
+ }
|
|
|
+
|
|
|
+ //Rewrite and validate the sort mode
|
|
|
+ if userSortMode == "user" {
|
|
|
+ //Use user sorting mode.
|
|
|
+ if g.Option.UserHandler.GetDatabase().KeyExists("fs-sortpref", u.Username+"/"+filepath.ToSlash(filepath.Clean(vpath))) {
|
|
|
+ g.Option.UserHandler.GetDatabase().Read("fs-sortpref", u.Username+"/"+filepath.ToSlash(filepath.Clean(vpath)), &userSortMode)
|
|
|
+ } else {
|
|
|
+ userSortMode = "default"
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if !fssort.SortModeIsSupported(userSortMode) {
|
|
|
+ log.Println("[AGI] Sort mode: " + userSortMode + " not supported. Using default")
|
|
|
+ userSortMode = "default"
|
|
|
+ }
|
|
|
+
|
|
|
fsh, err := u.GetFileSystemHandlerFromVirtualPath(vpath)
|
|
|
if err != nil {
|
|
|
g.raiseError(err)
|
|
|
- reply, _ := vm.ToValue(false)
|
|
|
- return reply
|
|
|
+ return otto.FalseValue()
|
|
|
}
|
|
|
fshAbs := fsh.FileSystemAbstraction
|
|
|
rpath, err := fshAbs.VirtualPathToRealPath(vpath, u.Username)
|
|
|
if err != nil {
|
|
|
g.raiseError(err)
|
|
|
- reply, _ := vm.ToValue(false)
|
|
|
- return reply
|
|
|
+ return otto.FalseValue()
|
|
|
}
|
|
|
|
|
|
dirEntry, err := fshAbs.ReadDir(rpath)
|
|
|
if err != nil {
|
|
|
g.raiseError(err)
|
|
|
- reply, _ := vm.ToValue(false)
|
|
|
- return reply
|
|
|
+ return otto.FalseValue()
|
|
|
}
|
|
|
|
|
|
type fileInfo struct {
|
|
@@ -489,6 +486,32 @@ func (g *Gateway) injectFileLibFunctions(vm *otto.Otto, u *user.User) {
|
|
|
IsDir bool
|
|
|
}
|
|
|
|
|
|
+ //Sort the dirEntry by file info, a bit slow :(
|
|
|
+ entries := map[string]fs.DirEntry{}
|
|
|
+ fnames := []string{}
|
|
|
+ fis := []fs.FileInfo{}
|
|
|
+ if userSortMode != "default" {
|
|
|
+ //Prepare the data structure for sorting
|
|
|
+ for _, de := range dirEntry {
|
|
|
+ fnames = append(fnames, de.Name())
|
|
|
+ fstat, _ := de.Info()
|
|
|
+ fis = append(fis, fstat)
|
|
|
+ thisFsDirEntry := de
|
|
|
+ entries[de.Name()] = thisFsDirEntry
|
|
|
+ }
|
|
|
+
|
|
|
+ //Sort it
|
|
|
+ sortedNameList := fssort.SortFileList(fnames, fis, userSortMode)
|
|
|
+
|
|
|
+ //Update dirEntry sequence
|
|
|
+ newDirEntry := []fs.DirEntry{}
|
|
|
+ for _, key := range sortedNameList {
|
|
|
+ newDirEntry = append(newDirEntry, entries[key])
|
|
|
+ }
|
|
|
+
|
|
|
+ dirEntry = newDirEntry
|
|
|
+ }
|
|
|
+
|
|
|
results := []fileInfo{}
|
|
|
for _, de := range dirEntry {
|
|
|
isHidden, _ := hidden.IsHidden(de.Name(), false)
|
|
@@ -519,8 +542,7 @@ func (g *Gateway) injectFileLibFunctions(vm *otto.Otto, u *user.User) {
|
|
|
vpath, err := call.Argument(0).ToString()
|
|
|
if err != nil {
|
|
|
g.raiseError(err)
|
|
|
- reply, _ := vm.ToValue(false)
|
|
|
- return reply
|
|
|
+ return otto.FalseValue()
|
|
|
}
|
|
|
|
|
|
//Check for permission
|
|
@@ -531,23 +553,20 @@ func (g *Gateway) injectFileLibFunctions(vm *otto.Otto, u *user.User) {
|
|
|
fsh, err := u.GetFileSystemHandlerFromVirtualPath(vpath)
|
|
|
if err != nil {
|
|
|
g.raiseError(err)
|
|
|
- reply, _ := vm.ToValue(false)
|
|
|
- return reply
|
|
|
+ return otto.FalseValue()
|
|
|
}
|
|
|
fshAbs := fsh.FileSystemAbstraction
|
|
|
rpath, err := fshAbs.VirtualPathToRealPath(vpath, u.Username)
|
|
|
if err != nil {
|
|
|
g.raiseError(err)
|
|
|
- reply, _ := vm.ToValue(false)
|
|
|
- return reply
|
|
|
+ return otto.FalseValue()
|
|
|
}
|
|
|
|
|
|
//Get filesize of file
|
|
|
rawsize := fshAbs.GetFileSize(rpath)
|
|
|
if err != nil {
|
|
|
g.raiseError(err)
|
|
|
- reply, _ := vm.ToValue(false)
|
|
|
- return reply
|
|
|
+ return otto.FalseValue()
|
|
|
}
|
|
|
|
|
|
reply, _ := vm.ToValue(rawsize)
|
|
@@ -559,8 +578,7 @@ func (g *Gateway) injectFileLibFunctions(vm *otto.Otto, u *user.User) {
|
|
|
vpath, err := call.Argument(0).ToString()
|
|
|
if err != nil {
|
|
|
g.raiseError(err)
|
|
|
- reply, _ := vm.ToValue(false)
|
|
|
- return reply
|
|
|
+ return otto.FalseValue()
|
|
|
}
|
|
|
|
|
|
//Check for permission
|
|
@@ -571,23 +589,19 @@ func (g *Gateway) injectFileLibFunctions(vm *otto.Otto, u *user.User) {
|
|
|
fsh, err := u.GetFileSystemHandlerFromVirtualPath(vpath)
|
|
|
if err != nil {
|
|
|
g.raiseError(err)
|
|
|
- reply, _ := vm.ToValue(false)
|
|
|
- return reply
|
|
|
+ return otto.FalseValue()
|
|
|
}
|
|
|
fshAbs := fsh.FileSystemAbstraction
|
|
|
rpath, err := fshAbs.VirtualPathToRealPath(vpath, u.Username)
|
|
|
if err != nil {
|
|
|
g.raiseError(err)
|
|
|
- reply, _ := vm.ToValue(false)
|
|
|
- return reply
|
|
|
+ return otto.FalseValue()
|
|
|
}
|
|
|
|
|
|
if fshAbs.FileExists(rpath) {
|
|
|
- reply, _ := vm.ToValue(true)
|
|
|
- return reply
|
|
|
+ return otto.TrueValue()
|
|
|
} else {
|
|
|
- reply, _ := vm.ToValue(false)
|
|
|
- return reply
|
|
|
+ return otto.FalseValue()
|
|
|
}
|
|
|
})
|
|
|
|
|
@@ -596,8 +610,7 @@ func (g *Gateway) injectFileLibFunctions(vm *otto.Otto, u *user.User) {
|
|
|
vpath, err := call.Argument(0).ToString()
|
|
|
if err != nil {
|
|
|
g.raiseError(err)
|
|
|
- reply, _ := vm.ToValue(false)
|
|
|
- return reply
|
|
|
+ return otto.FalseValue()
|
|
|
}
|
|
|
|
|
|
//Check for permission
|
|
@@ -609,8 +622,7 @@ func (g *Gateway) injectFileLibFunctions(vm *otto.Otto, u *user.User) {
|
|
|
fsh, rpath, err := virtualPathToRealPath(vpath, u)
|
|
|
if err != nil {
|
|
|
g.raiseError(err)
|
|
|
- reply, _ := vm.ToValue(false)
|
|
|
- return reply
|
|
|
+ return otto.FalseValue()
|
|
|
}
|
|
|
|
|
|
if _, err := fsh.FileSystemAbstraction.Stat(rpath); os.IsNotExist(err) {
|
|
@@ -619,11 +631,9 @@ func (g *Gateway) injectFileLibFunctions(vm *otto.Otto, u *user.User) {
|
|
|
}
|
|
|
|
|
|
if fsh.FileSystemAbstraction.IsDir(rpath) {
|
|
|
- reply, _ := vm.ToValue(true)
|
|
|
- return reply
|
|
|
+ return otto.TrueValue()
|
|
|
} else {
|
|
|
- reply, _ := vm.ToValue(false)
|
|
|
- return reply
|
|
|
+ return otto.FalseValue()
|
|
|
}
|
|
|
})
|
|
|
|
|
@@ -658,8 +668,45 @@ func (g *Gateway) injectFileLibFunctions(vm *otto.Otto, u *user.User) {
|
|
|
|
|
|
//Get MD5 of the given filepath, not implemented
|
|
|
vm.Set("_filelib_md5", func(call otto.FunctionCall) otto.Value {
|
|
|
- log.Println("Call to MD5 Functions!")
|
|
|
- return otto.FalseValue()
|
|
|
+ vpath, err := call.Argument(0).ToString()
|
|
|
+ if err != nil {
|
|
|
+ g.raiseError(err)
|
|
|
+ return otto.FalseValue()
|
|
|
+ }
|
|
|
+
|
|
|
+ //Check for permission
|
|
|
+ if !u.CanRead(vpath) {
|
|
|
+ panic(vm.MakeCustomError("PermissionDenied", "Path access denied"))
|
|
|
+ }
|
|
|
+
|
|
|
+ fsh, err := u.GetFileSystemHandlerFromVirtualPath(vpath)
|
|
|
+ if err != nil {
|
|
|
+ g.raiseError(err)
|
|
|
+ return otto.FalseValue()
|
|
|
+ }
|
|
|
+ fshAbs := fsh.FileSystemAbstraction
|
|
|
+ rpath, err := fshAbs.VirtualPathToRealPath(vpath, u.Username)
|
|
|
+ if err != nil {
|
|
|
+ g.raiseError(err)
|
|
|
+ return otto.FalseValue()
|
|
|
+ }
|
|
|
+
|
|
|
+ f, err := fshAbs.ReadStream(rpath)
|
|
|
+ if err != nil {
|
|
|
+ g.raiseError(err)
|
|
|
+ return otto.FalseValue()
|
|
|
+ }
|
|
|
+
|
|
|
+ defer f.Close()
|
|
|
+ h := md5.New()
|
|
|
+ if _, err := io.Copy(h, f); err != nil {
|
|
|
+ g.raiseError(err)
|
|
|
+ return otto.FalseValue()
|
|
|
+ }
|
|
|
+
|
|
|
+ md5Sum := hex.EncodeToString(h.Sum(nil))
|
|
|
+ result, _ := vm.ToValue(md5Sum)
|
|
|
+ return result
|
|
|
})
|
|
|
|
|
|
//Get the root name of the given virtual path root
|
|
@@ -688,8 +735,7 @@ func (g *Gateway) injectFileLibFunctions(vm *otto.Otto, u *user.User) {
|
|
|
vpath, err := call.Argument(0).ToString()
|
|
|
if err != nil {
|
|
|
g.raiseError(err)
|
|
|
- reply, _ := vm.ToValue(false)
|
|
|
- return reply
|
|
|
+ return otto.FalseValue()
|
|
|
}
|
|
|
|
|
|
//Check for permission
|
|
@@ -743,8 +789,8 @@ func (g *Gateway) injectFileLibFunctions(vm *otto.Otto, u *user.User) {
|
|
|
filelib.mtime = _filelib_mtime;
|
|
|
filelib.rootName = _filelib_rname;
|
|
|
|
|
|
- filelib.readdir = function(path){
|
|
|
- var s = _filelib_readdir(path);
|
|
|
+ filelib.readdir = function(path, sortmode){
|
|
|
+ var s = _filelib_readdir(path, sortmode);
|
|
|
return JSON.parse(s);
|
|
|
};
|
|
|
`)
|