File tree Expand file tree Collapse file tree
extensions/github-browser/src Expand file tree Collapse file tree Original file line number Diff line number Diff line change 88const textDecoder = new TextDecoder ( ) ;
99const textEncoder = new TextEncoder ( ) ;
1010
11- declare const WEBWORKER : boolean ;
11+ declare let WEBWORKER : boolean ;
1212
1313export async function sha1 ( s : string | Uint8Array ) : Promise < string > {
14- if ( WEBWORKER ) {
15- const hash = await globalThis . crypto . subtle . digest ( { name : 'sha-1' } , typeof s === 'string' ? textEncoder . encode ( s ) : s ) ;
16- // Use encodeURIComponent to avoid issues with btoa and Latin-1 characters
17- return globalThis . btoa ( encodeURIComponent ( textDecoder . decode ( hash ) ) ) ;
18- }
19- else {
20- return ( await import ( 'crypto' ) ) . createHash ( 'sha1' ) . update ( s ) . digest ( 'base64' ) ;
14+ while ( true ) {
15+ try {
16+ if ( WEBWORKER ) {
17+ const hash = await globalThis . crypto . subtle . digest ( { name : 'sha-1' } , typeof s === 'string' ? textEncoder . encode ( s ) : s ) ;
18+ // Use encodeURIComponent to avoid issues with btoa and Latin-1 characters
19+ return globalThis . btoa ( encodeURIComponent ( textDecoder . decode ( hash ) ) ) ;
20+ } else {
21+ return ( await import ( 'crypto' ) ) . createHash ( 'sha1' ) . update ( s ) . digest ( 'base64' ) ;
22+ }
23+ } catch ( ex ) {
24+ if ( ex instanceof ReferenceError ) {
25+ ( global as any ) . WEBWORKER = false ;
26+ }
27+ }
2128 }
2229}
You can’t perform that action at this time.
0 commit comments