[go: nahoru, domu]

Skip to content

Commit

Permalink
Merge pull request #1547 from 0chain/fix/wasm-urlencode
Browse files Browse the repository at this point in the history
Encode url params
  • Loading branch information
dabasov committed Jul 2, 2024
2 parents 63badd2 + 8ace517 commit 7100a81
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
20 changes: 13 additions & 7 deletions wasmsdk/jsbridge/template_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ import (
"fmt"
"net/url"
"os"
"path"
"strings"
"syscall/js"
"text/template"

"github.com/0chain/gosdk/core/version"
)

//go:embed zcnworker.js.tpl
Expand All @@ -20,28 +23,31 @@ func buildWorkerJS(args, env []string, path string) (string, error) {
return buildJS(args, env, path, WorkerJSTpl)
}

func buildJS(args, env []string, path string, tpl []byte) (string, error) {
func buildJS(args, env []string, wasmPath string, tpl []byte) (string, error) {
var workerJS bytes.Buffer

if len(args) == 0 {
args = []string{path}
args = []string{wasmPath}
}

if len(env) == 0 {
env = os.Environ()
}

if uRL, err := url.ParseRequestURI(path); err != nil || !uRL.IsAbs() {
if uRL, err := url.ParseRequestURI(wasmPath); err != nil || !uRL.IsAbs() {
origin := js.Global().Get("location").Get("origin").String()
baseURL, err := url.ParseRequestURI(origin)
u, err := url.Parse(origin)
if err != nil {
return "", err
}
path = baseURL.JoinPath(path).String()
u.Path = path.Join(u.Path, wasmPath)
params := url.Values{}
params.Add("v", version.VERSIONSTR)
u.RawQuery = params.Encode()
wasmPath = u.String()
}

data := templateData{
Path: path,
Path: wasmPath,
Args: args,
Env: env,
}
Expand Down
3 changes: 1 addition & 2 deletions wasmsdk/jsbridge/webworker.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"errors"
"sync"

"github.com/0chain/gosdk/core/version"
"github.com/google/uuid"
"github.com/hack-pad/go-webworkers/worker"
"github.com/hack-pad/safejs"
Expand Down Expand Up @@ -61,7 +60,7 @@ func NewWasmWebWorker(blobberID, blobberURL, clientID, publicKey, privateKey, mn
w := &WasmWebWorker{
Name: blobberURL,
Env: []string{"BLOBBER_URL=" + blobberURL, "CLIENT_ID=" + clientID, "PRIVATE_KEY=" + privateKey, "MODE=worker", "PUBLIC_KEY=" + publicKey, "MNEMONIC=" + mnemonic},
Path: "zcn.wasm?v=" + version.VERSIONSTR,
Path: "zcn.wasm",
subscribers: make(map[string]chan worker.MessageEvent),
}

Expand Down

0 comments on commit 7100a81

Please sign in to comment.