@@ -676,10 +676,17 @@ class WebuiBridge {
676
676
const scriptSanitize = script . replace ( / (?: \r \n | \r | \n ) / g, '\n' ) ;
677
677
if ( this . #log) console . log ( `WebUI -> CMD -> JS [${ scriptSanitize } ]` ) ;
678
678
// Get callback result
679
- let FunReturn = 'undefined' ;
679
+ let FunReturn : string | Uint8Array = 'undefined' ;
680
680
let FunError = false ;
681
+ let isBinaryReturn = false ;
681
682
try {
682
- FunReturn = await AsyncFunction ( scriptSanitize ) ( ) ;
683
+ const result = await AsyncFunction ( scriptSanitize ) ( ) ;
684
+ if ( result instanceof Uint8Array ) {
685
+ FunReturn = result ;
686
+ isBinaryReturn = true ;
687
+ } else {
688
+ FunReturn = String ( result ) ;
689
+ }
683
690
} catch ( e ) {
684
691
FunError = true ;
685
692
FunReturn = e . message ;
@@ -691,8 +698,20 @@ class WebuiBridge {
691
698
FunReturn = 'undefined' ;
692
699
}
693
700
// Logging
694
- if ( this . #log && ! FunError ) console . log ( `WebUI -> CMD -> JS -> Return Success [${ FunReturn } ]` ) ;
695
- if ( this . #log && FunError ) console . log ( `WebUI -> CMD -> JS -> Return Error [${ FunReturn } ]` ) ;
701
+ if ( this . #log && ! FunError ) {
702
+ if ( isBinaryReturn ) {
703
+ const binaryData = FunReturn as Uint8Array ;
704
+ const hexPreview = Array . from ( binaryData . slice ( 0 , 64 ) ) . map ( b => `0x${ b . toString ( 16 ) . padStart ( 2 , '0' ) } ` ) . join ( ', ' ) ;
705
+ console . log ( `WebUI -> CMD -> JS -> Return Success (${ binaryData . length } Bytes) [${ hexPreview } ${ binaryData . length > 64 ? '...' : '' } ]` ) ;
706
+ } else {
707
+ const stringData = String ( FunReturn ) ;
708
+ console . log ( `WebUI -> CMD -> JS -> Return Success (${ new TextEncoder ( ) . encode ( stringData ) . length } Bytes) [${ stringData . substring ( 0 , 64 ) } ${ stringData . length > 64 ? '...' : '' } ]` ) ;
709
+ }
710
+ }
711
+ else if ( this . #log && FunError ) {
712
+ const errorString = String ( FunReturn ) ;
713
+ console . log ( `WebUI -> CMD -> JS -> Return Error [${ errorString . substring ( 0 , 64 ) } ${ errorString . length > 64 ? '...' : '' } ]` ) ;
714
+ }
696
715
// Protocol
697
716
// 0: [SIGNATURE]
698
717
// 1: [TOKEN]
@@ -724,7 +743,11 @@ class WebuiBridge {
724
743
packetPush ( new Uint8Array ( [ 0 , 0 ] ) ) ; // ID (2 Bytes)
725
744
packetPush ( new Uint8Array ( [ this . #CMD_JS] ) ) ;
726
745
packetPush ( new Uint8Array ( FunError ? [ 1 ] : [ 0 ] ) ) ;
727
- packetPushStr ( FunReturn ) ;
746
+ if ( isBinaryReturn ) {
747
+ packetPush ( FunReturn as Uint8Array ) ;
748
+ } else {
749
+ packetPushStr ( FunReturn as string ) ;
750
+ }
728
751
packetPush ( new Uint8Array ( [ 0 ] ) ) ;
729
752
this . #addToken( packet , this . #token, this . #PROTOCOL_TOKEN) ;
730
753
this . #addID( packet , callId , this . #PROTOCOL_ID) ;
0 commit comments