mirror of
https://github.com/jwetzell/showbridge-go.git
synced 2026-04-26 21:05:30 +00:00
try processing return value of script.js as an array and a map
This commit is contained in:
@@ -2,7 +2,6 @@ package processor
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/jwetzell/showbridge-go/internal/common"
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
@@ -63,10 +62,25 @@ func (sj *ScriptJS) Process(ctx context.Context, wrappedPayload common.WrappedPa
|
|||||||
outputObject, ok := output.(*quickjs.Object)
|
outputObject, ok := output.(*quickjs.Object)
|
||||||
|
|
||||||
if ok {
|
if ok {
|
||||||
var outputMap map[string]interface{}
|
var outputSlice []interface{}
|
||||||
err := json.Unmarshal([]byte(outputObject.String()), &outputMap)
|
|
||||||
wrappedPayload.Payload = outputMap
|
err = outputObject.Into(&outputSlice)
|
||||||
return wrappedPayload, err
|
|
||||||
|
if err != nil {
|
||||||
|
var outputMap map[string]interface{}
|
||||||
|
err = outputObject.Into(&outputMap)
|
||||||
|
if err != nil {
|
||||||
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
|
} else {
|
||||||
|
wrappedPayload.Payload = outputMap
|
||||||
|
return wrappedPayload, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
wrappedPayload.Payload = outputSlice
|
||||||
|
return wrappedPayload, nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
wrappedPayload.Payload = output
|
wrappedPayload.Payload = output
|
||||||
|
|||||||
Reference in New Issue
Block a user