Compare commits
1 Commits
2023.12.5-
...
2023.12.3-
Author | SHA1 | Date | |
---|---|---|---|
c5efd771a3 |
@ -46,11 +46,11 @@ func NewPromiseProxyFrom(rt *goja.Runtime) *PromiseProxy {
|
|||||||
return NewPromiseProxy(promise, resolve, reject)
|
return NewPromiseProxy(promise, resolve, reject)
|
||||||
}
|
}
|
||||||
|
|
||||||
func isPromise(v any) (*goja.Promise, bool) {
|
func IsPromise(v goja.Value) (*goja.Promise, bool) {
|
||||||
if v == nil {
|
if v == nil {
|
||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
|
|
||||||
promise, ok := v.(*goja.Promise)
|
promise, ok := v.Export().(*goja.Promise)
|
||||||
return promise, ok
|
return promise, ok
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ type Server struct {
|
|||||||
modules []ServerModule
|
modules []ServerModule
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) ExecFuncByName(ctx context.Context, funcName string, args ...any) (any, error) {
|
func (s *Server) ExecFuncByName(ctx context.Context, funcName string, args ...interface{}) (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 ...an
|
|||||||
return ret, nil
|
return ret, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) Exec(ctx context.Context, callableOrFuncname any, args ...any) (any, error) {
|
func (s *Server) Exec(ctx context.Context, callableOrFuncname any, args ...interface{}) (any, error) {
|
||||||
type result struct {
|
type result struct {
|
||||||
value any
|
value goja.Value
|
||||||
err error
|
err error
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,7 +110,7 @@ func (s *Server) Exec(ctx context.Context, callableOrFuncname any, args ...any)
|
|||||||
}
|
}
|
||||||
|
|
||||||
done <- result{
|
done <- result{
|
||||||
value: value.Export(),
|
value: value,
|
||||||
}
|
}
|
||||||
|
|
||||||
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,18 +129,20 @@ func (s *Server) Exec(ctx context.Context, callableOrFuncname any, args ...any)
|
|||||||
return nil, errors.WithStack(result.err)
|
return nil, errors.WithStack(result.err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if promise, ok := isPromise(result.value); ok {
|
value := result.value
|
||||||
return s.waitForPromise(promise), nil
|
|
||||||
|
if promise, ok := IsPromise(value); ok {
|
||||||
|
value = s.waitForPromise(promise)
|
||||||
}
|
}
|
||||||
|
|
||||||
return result.value, nil
|
return value.Export(), nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) waitForPromise(promise *goja.Promise) any {
|
func (s *Server) waitForPromise(promise *goja.Promise) goja.Value {
|
||||||
var (
|
var (
|
||||||
wg sync.WaitGroup
|
wg sync.WaitGroup
|
||||||
value any
|
value goja.Value
|
||||||
)
|
)
|
||||||
|
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
@ -160,7 +162,7 @@ func (s *Server) waitForPromise(promise *goja.Promise) any {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
value = promise.Result().Export()
|
value = promise.Result()
|
||||||
|
|
||||||
breakLoop = true
|
breakLoop = true
|
||||||
})
|
})
|
||||||
|
@ -2,7 +2,6 @@ package blob
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io"
|
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"mime/multipart"
|
"mime/multipart"
|
||||||
"net/http"
|
"net/http"
|
||||||
@ -165,14 +164,7 @@ func handleAppDownload(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// TODO Fix usage of ServeContent
|
http.ServeContent(w, r, string(replyMessage.BlobInfo.ID()), replyMessage.BlobInfo.ModTime(), replyMessage.Blob)
|
||||||
// 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 {
|
||||||
|
@ -8,6 +8,7 @@ import (
|
|||||||
"forge.cadoles.com/arcad/edge/pkg/storage"
|
"forge.cadoles.com/arcad/edge/pkg/storage"
|
||||||
"forge.cadoles.com/arcad/edge/pkg/storage/driver"
|
"forge.cadoles.com/arcad/edge/pkg/storage/driver"
|
||||||
"forge.cadoles.com/arcad/edge/pkg/storage/share"
|
"forge.cadoles.com/arcad/edge/pkg/storage/share"
|
||||||
|
"github.com/davecgh/go-spew/spew"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -39,6 +40,8 @@ func documentStoreFactory(url *url.URL) (storage.DocumentStore, error) {
|
|||||||
func blobStoreFactory(url *url.URL) (storage.BlobStore, error) {
|
func blobStoreFactory(url *url.URL) (storage.BlobStore, error) {
|
||||||
dir := filepath.Dir(url.Host + url.Path)
|
dir := filepath.Dir(url.Host + url.Path)
|
||||||
|
|
||||||
|
spew.Dump(url.Host + url.Path)
|
||||||
|
|
||||||
if dir != "." {
|
if dir != "." {
|
||||||
if err := os.MkdirAll(dir, os.FileMode(0750)); err != nil {
|
if err := os.MkdirAll(dir, os.FileMode(0750)); err != nil {
|
||||||
return nil, errors.WithStack(err)
|
return nil, errors.WithStack(err)
|
||||||
|
Reference in New Issue
Block a user