File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -15,17 +15,19 @@ registerRoute(
1515 return url . pathname === '/beta/HTMLPlayer/' && request . method === 'POST' ;
1616 } ,
1717 async ( { event } ) => {
18- const formData = await event . request . formData ( ) ;
19- const file = formData . get ( 'audio' ) ;
20-
21- if ( file ) {
22- const cache = await caches . open ( 'incoming-shares' ) ;
23- await cache . put ( '/shared-file' , new Response ( file ) ) ;
18+ try {
19+ const formData = await event . request . formData ( ) ;
20+ const file = formData . get ( 'audio' ) ;
21+ if ( file ) {
22+ const cache = await caches . open ( 'incoming-shares' ) ;
23+ await cache . put ( '/shared-file' , new Response ( file ) ) ;
24+ }
25+ const redirectUrl = new URL ( '/beta/HTMLPlayer/?share-received=true' , self . location . origin ) ;
26+ return Response . redirect ( redirectUrl . href , 303 ) ;
27+ } catch ( e ) {
28+ // always return a response even on error
29+ return new Response ( 'Failed to process share' , { status : 400 } ) ;
2430 }
25-
26- // Use self.location.origin to force a stable absolute URL
27- const redirectUrl = new URL ( '/beta/HTMLPlayer/?share-received=true' , self . location . origin ) ;
28- return Response . redirect ( redirectUrl . href , 303 ) ;
2931 } ,
3032 'POST'
3133) ;
You can’t perform that action at this time.
0 commit comments