Skip to content

Commit 15432b0

Browse files
authored
chore(web): make onIncomingFile async (#63)
1 parent 7f337db commit 15432b0

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

cmd/wasm/main.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,17 @@ func cpH(onIncomingFile js.Value, downloadFile js.Value) http.HandlerFunc {
505505
}),
506506
}
507507

508-
allow := onIncomingFile.Invoke(peer, fiName, r.ContentLength).Bool()
508+
var allow bool
509+
onIncomingFile.Invoke(peer, fiName, r.ContentLength).
510+
Call("then", js.FuncOf(func(this js.Value, args []js.Value) any {
511+
allow = args[0].Bool()
512+
return nil
513+
})).
514+
Call("catch", js.FuncOf(func(this js.Value, args []js.Value) any {
515+
fmt.Println("onIncomingFile failed:", args[0].String())
516+
allow = false
517+
return nil
518+
}))
509519
if !allow {
510520
w.WriteHeader(http.StatusForbidden)
511521
w.Write([]byte("File transfer was denied"))

site/types/wush_js.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ declare global {
6060
peer: Peer,
6161
filename: string,
6262
sizeBytes: number,
63-
) => boolean;
63+
) => Promise<boolean>;
6464
downloadFile: (
6565
peer: Peer,
6666
filename: string,

0 commit comments

Comments
 (0)