Compare commits

...

3 Commits
v0.0.1 ... main

Author SHA1 Message Date
82c3d89788 update gojs 2025-11-30 23:08:01 +08:00
b8c5b4f10d fix package name again 2025-06-27 15:21:37 +08:00
886369a740 fix package name 2025-06-27 15:17:54 +08:00
3 changed files with 33 additions and 18 deletions

9
LICENSE Normal file
View File

@ -0,0 +1,9 @@
MIT License
Copyright (c) 2024 apigo
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

28
go.mod
View File

@ -1,27 +1,27 @@
module apigo.cc/apigo/know module apigo.cc/gojs/runtime
go 1.24 go 1.24.0
require ( require (
apigo.cc/gojs v0.0.13 apigo.cc/gojs v0.0.28
apigo.cc/gojs/console v0.0.2 apigo.cc/gojs/console v0.0.3
apigo.cc/gojs/file v0.0.3 apigo.cc/gojs/file v0.0.6
github.com/ssgo/u v1.7.18 github.com/ssgo/u v1.7.23
) )
require ( require (
github.com/dlclark/regexp2 v1.11.4 // indirect github.com/dlclark/regexp2 v1.11.5 // indirect
github.com/fsnotify/fsnotify v1.8.0 // indirect github.com/fsnotify/fsnotify v1.9.0 // indirect
github.com/go-sourcemap/sourcemap v2.1.4+incompatible // indirect github.com/go-sourcemap/sourcemap v2.1.4+incompatible // indirect
github.com/google/pprof v0.0.0-20250317173921-a4b03ec1a45e // indirect github.com/google/pprof v0.0.0-20250903194437-c28834ac2320 // indirect
github.com/kr/pretty v0.3.1 // indirect github.com/kr/pretty v0.3.1 // indirect
github.com/rogpeppe/go-internal v1.13.1 // indirect github.com/rogpeppe/go-internal v1.13.1 // indirect
github.com/ssgo/config v1.7.9 // indirect github.com/ssgo/config v1.7.10 // indirect
github.com/ssgo/log v1.7.7 // indirect github.com/ssgo/log v1.7.9 // indirect
github.com/ssgo/standard v1.7.7 // indirect github.com/ssgo/standard v1.7.7 // indirect
github.com/ssgo/tool v0.4.28 // indirect github.com/ssgo/tool v0.4.29 // indirect
golang.org/x/sys v0.33.0 // indirect golang.org/x/sys v0.38.0 // indirect
golang.org/x/text v0.23.0 // indirect golang.org/x/text v0.31.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect
) )

View File

@ -42,7 +42,7 @@ func (obj *PluginObject) Arch() string {
return runtime.GOARCH return runtime.GOARCH
} }
func (obj *PluginObject) Sleep(timeValue any) error { func (obj *PluginObject) Sleep(timeValue any, vm *goja.Runtime) error {
var timeV time.Duration var timeV time.Duration
if ms := u.Int64(timeValue); ms > 0 { if ms := u.Int64(timeValue); ms > 0 {
timeV = time.Duration(ms) * time.Millisecond timeV = time.Duration(ms) * time.Millisecond
@ -51,8 +51,11 @@ func (obj *PluginObject) Sleep(timeValue any) error {
timeV = v timeV = v
} }
} }
if timeV > time.Hour { if timeV > time.Minute {
return errors.New("sleep time too long, max 1h") return errors.New("sleep time too long, max 60s")
}
if timeV > time.Second*5 && u.String(vm.GetData("userPath")) != "" {
return errors.New("sleep time too long, max 5s in sandbox")
} }
if timeV > 0 { if timeV > 0 {
time.Sleep(timeV) time.Sleep(timeV)
@ -60,7 +63,10 @@ func (obj *PluginObject) Sleep(timeValue any) error {
return nil return nil
} }
func (obj *PluginObject) Shell(cmd string, args ...string) ([]string, error) { func (obj *PluginObject) Shell(vm *goja.Runtime, cmd string, args ...string) ([]string, error) {
if u.String(vm.GetData("userPath")) != "" {
return nil, gojs.Err("shell is not allowed in sandbox")
}
if len(args) == 0 && strings.ContainsRune(cmd, ' ') { if len(args) == 0 && strings.ContainsRune(cmd, ' ') {
args = u.SplitArgs(cmd) args = u.SplitArgs(cmd)
cmd = args[0] cmd = args[0]