Compare commits

...

3 Commits

Author SHA1 Message Date
59f023a7d9 fix: do not use goja.Value outside of loop
All checks were successful
arcad/edge/pipeline/head This commit looks good
ref #22
2023-12-05 21:27:43 +01:00
753a6c9708 fix: temporarily write blob directly as response body without http.ServeContent
All checks were successful
arcad/edge/pipeline/head This commit looks good
2023-12-05 14:18:22 +01:00
b120e590b6 fix: do not use goja.Value outside of run loop 2023-12-05 14:14:08 +01:00
3 changed files with 21 additions and 15 deletions

View File

@ -46,11 +46,11 @@ func NewPromiseProxyFrom(rt *goja.Runtime) *PromiseProxy {
return NewPromiseProxy(promise, resolve, reject) return NewPromiseProxy(promise, resolve, reject)
} }
func IsPromise(v goja.Value) (*goja.Promise, bool) { func isPromise(v any) (*goja.Promise, bool) {
if v == nil { if v == nil {
return nil, false return nil, false
} }
promise, ok := v.Export().(*goja.Promise) promise, ok := v.(*goja.Promise)
return promise, ok return promise, ok
} }

View File

@ -23,7 +23,7 @@ type Server struct {
modules []ServerModule modules []ServerModule
} }
func (s *Server) ExecFuncByName(ctx context.Context, funcName string, args ...interface{}) (any, error) { func (s *Server) ExecFuncByName(ctx context.Context, funcName string, args ...any) (any, error) {
ctx = logger.With(ctx, logger.F("function", funcName), logger.F("args", args)) ctx = logger.With(ctx, logger.F("function", funcName), logger.F("args", args))
ret, err := s.Exec(ctx, funcName, args...) ret, err := s.Exec(ctx, funcName, args...)
@ -34,9 +34,9 @@ func (s *Server) ExecFuncByName(ctx context.Context, funcName string, args ...in
return ret, nil return ret, nil
} }
func (s *Server) Exec(ctx context.Context, callableOrFuncname any, args ...interface{}) (any, error) { func (s *Server) Exec(ctx context.Context, callableOrFuncname any, args ...any) (any, error) {
type result struct { type result struct {
value goja.Value value any
err error err error
} }
@ -110,7 +110,7 @@ func (s *Server) Exec(ctx context.Context, callableOrFuncname any, args ...inter
} }
done <- result{ done <- result{
value: value, value: value.Export(),
} }
logger.Debug(ctx, "executed callable", logger.F("callable", callableOrFuncname), logger.F("duration", time.Since(start).String())) logger.Debug(ctx, "executed callable", logger.F("callable", callableOrFuncname), logger.F("duration", time.Since(start).String()))
@ -129,20 +129,18 @@ func (s *Server) Exec(ctx context.Context, callableOrFuncname any, args ...inter
return nil, errors.WithStack(result.err) return nil, errors.WithStack(result.err)
} }
value := result.value if promise, ok := isPromise(result.value); ok {
return s.waitForPromise(promise), nil
if promise, ok := IsPromise(value); ok {
value = s.waitForPromise(promise)
} }
return value.Export(), nil return result.value, nil
} }
} }
func (s *Server) waitForPromise(promise *goja.Promise) goja.Value { func (s *Server) waitForPromise(promise *goja.Promise) any {
var ( var (
wg sync.WaitGroup wg sync.WaitGroup
value goja.Value value any
) )
wg.Add(1) wg.Add(1)
@ -162,7 +160,7 @@ func (s *Server) waitForPromise(promise *goja.Promise) goja.Value {
return return
} }
value = promise.Result() value = promise.Result().Export()
breakLoop = true breakLoop = true
}) })

View File

@ -2,6 +2,7 @@ package blob
import ( import (
"encoding/json" "encoding/json"
"io"
"io/fs" "io/fs"
"mime/multipart" "mime/multipart"
"net/http" "net/http"
@ -164,7 +165,14 @@ func handleAppDownload(w http.ResponseWriter, r *http.Request) {
} }
}() }()
http.ServeContent(w, r, string(replyMessage.BlobInfo.ID()), replyMessage.BlobInfo.ModTime(), replyMessage.Blob) // TODO Fix usage of ServeContent
// http.ServeContent(w, r, string(replyMessage.BlobInfo.ID()), replyMessage.BlobInfo.ModTime(), replyMessage.Blob)
w.Header().Add("Content-Type", replyMessage.BlobInfo.ContentType())
if _, err := io.Copy(w, replyMessage.Blob); err != nil {
logger.Error(ctx, "could not write blob", logger.CapturedE(errors.WithStack(err)))
}
} }
type uploadedFile struct { type uploadedFile struct {