fix js handler func not existed bug

This commit is contained in:
tickstep 2022-04-20 22:05:50 +08:00
parent 182c28fdb3
commit 0887b9f160

View File

@ -59,9 +59,20 @@ func (js *JsPlugin) LoadScript(script string) error {
return nil return nil
} }
func (js *JsPlugin) isHandlerFuncExisted(fnName string) bool {
ret := js.vm.Get(fnName)
if ret != nil {
return true
}
return false
}
// UploadFilePrepareCallback 上传文件前的回调函数 // UploadFilePrepareCallback 上传文件前的回调函数
func (js *JsPlugin) UploadFilePrepareCallback(context *Context, params *UploadFilePrepareParams) (*UploadFilePrepareResult, error) { func (js *JsPlugin) UploadFilePrepareCallback(context *Context, params *UploadFilePrepareParams) (*UploadFilePrepareResult, error) {
var fn func(*Context, *UploadFilePrepareParams) (*UploadFilePrepareResult, error) var fn func(*Context, *UploadFilePrepareParams) (*UploadFilePrepareResult, error)
if !js.isHandlerFuncExisted("uploadFilePrepareCallback") {
return nil, nil
}
err := js.vm.ExportTo(js.vm.Get("uploadFilePrepareCallback"), &fn) err := js.vm.ExportTo(js.vm.Get("uploadFilePrepareCallback"), &fn)
if err != nil { if err != nil {
logger.Verboseln("Js函数映射到 Go 函数失败!") logger.Verboseln("Js函数映射到 Go 函数失败!")