From 5352152b66fc3b7d909162e89abfad1eed8b60aa Mon Sep 17 00:00:00 2001 From: Star Date: Fri, 13 Dec 2024 19:37:46 +0800 Subject: [PATCH] fix args error for DownloadFile fix bug for watch --- go.mod | 14 +++++++------- response.go | 2 +- service.go | 44 ++++++++++++++++++++++++++++++++------------ service.ts | 1 + 4 files changed, 41 insertions(+), 20 deletions(-) diff --git a/go.mod b/go.mod index db56ccc..23d6ea0 100644 --- a/go.mod +++ b/go.mod @@ -3,10 +3,10 @@ module apigo.cc/gojs/service go 1.18 require ( - apigo.cc/gojs v0.0.7 + apigo.cc/gojs v0.0.8 apigo.cc/gojs/console v0.0.2 apigo.cc/gojs/http v0.0.3 - apigo.cc/gojs/util v0.0.7 + apigo.cc/gojs/util v0.0.8 github.com/gorilla/websocket v1.5.3 github.com/ssgo/config v1.7.9 github.com/ssgo/discover v1.7.9 @@ -21,7 +21,7 @@ require ( require ( github.com/ZZMarquis/gm v1.3.2 // indirect github.com/dlclark/regexp2 v1.11.4 // indirect - github.com/emmansun/gmsm v0.29.4 // indirect + github.com/emmansun/gmsm v0.29.6 // indirect github.com/fsnotify/fsnotify v1.8.0 // indirect github.com/go-ole/go-ole v1.3.0 // indirect github.com/go-sourcemap/sourcemap v2.1.4+incompatible // indirect @@ -36,9 +36,9 @@ require ( github.com/tklauser/go-sysconf v0.3.14 // indirect github.com/tklauser/numcpus v0.9.0 // indirect github.com/yusufpapurcu/wmi v1.2.4 // indirect - golang.org/x/crypto v0.29.0 // indirect - golang.org/x/net v0.31.0 // indirect - golang.org/x/sys v0.27.0 // indirect - golang.org/x/text v0.20.0 // indirect + golang.org/x/crypto v0.31.0 // indirect + golang.org/x/net v0.32.0 // indirect + golang.org/x/sys v0.28.0 // indirect + golang.org/x/text v0.21.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/response.go b/response.go index b8b51b6..6f85ef2 100644 --- a/response.go +++ b/response.go @@ -111,7 +111,7 @@ func (r *Response) SendFile(argsIn goja.FunctionCall, vm *goja.Runtime) goja.Val func (r *Response) DownloadFile(argsIn goja.FunctionCall, vm *goja.Runtime) goja.Value { args := gojs.MakeArgs(&argsIn, vm).Check(3) - r.resp.DownloadFile(args.Str(0), args.Str(1), args.Bytes(1)) + r.resp.DownloadFile(args.Str(0), args.Str(1), args.Bytes(2)) return nil } diff --git a/service.go b/service.go index e8861a0..fd6d799 100644 --- a/service.go +++ b/service.go @@ -214,20 +214,13 @@ func init() { // 处理Watch if vm.GoData["inWatch"] == true { onWatchConn := map[string]*websocket.Conn{} - onWatchLock := sync.RWMutex{} + onWatchLock := sync.Mutex{} vm.GoData["onWatch"] = func(filename string) { - conns := map[string]*websocket.Conn{} - onWatchLock.RLock() + onWatchLock.Lock() + defer onWatchLock.Unlock() for id, conn := range onWatchConn { - conns[id] = conn - } - onWatchLock.RUnlock() - for id, conn := range conns { if err := conn.WriteMessage(websocket.TextMessage, []byte(filename)); err != nil { - onWatchLock.Lock() delete(onWatchConn, id) - onWatchLock.Unlock() - } else { } } } @@ -246,11 +239,38 @@ func init() { outStr := u.String(out) // 注入自动刷新的代码 outStr = strings.ReplaceAll(outStr, "", ` `) diff --git a/service.ts b/service.ts index f6b6b74..7605541 100644 --- a/service.ts +++ b/service.ts @@ -271,6 +271,7 @@ interface Response { sendFile: (contentType: string, filename: string) => void downloadFile: (contentType: string, filename: string, data: any) => void location: (url: string) => void + end: (data: any) => void } interface Logger {