@@ -14,14 +14,28 @@ export async function downloadOrShare(fileId: string, filename?: string): Promis
1414 const fileUrl = `/api/files/${ fileId } ` ;
1515
1616 // Desktop or no Share API support → traditional download
17- const canShare = isMobileDevice ( ) && navigator . canShare ?.( { files : [ new File ( [ ] , 'test' ) ] } ) ;
17+ const isMobile = isMobileDevice ( ) ;
18+ const hasCanShare = typeof navigator . canShare === 'function' ;
19+ const canShare = isMobile && hasCanShare && navigator . canShare ( { files : [ new File ( [ ] , 'test' ) ] } ) ;
20+
21+ console . log ( '[downloadOrShare]' , {
22+ fileId,
23+ filename,
24+ isMobile,
25+ hasCanShare,
26+ canShare,
27+ userAgent : navigator . userAgent
28+ } ) ;
29+
1830 if ( ! canShare ) {
31+ console . log ( '[downloadOrShare] Using window.open fallback' ) ;
1932 window . open ( fileUrl , '_blank' ) ;
2033 return ;
2134 }
2235
2336 // Mobile with Share API → fetch blob and share
2437 try {
38+ console . log ( '[downloadOrShare] Fetching blob from' , fileUrl ) ;
2539 const response = await fetch ( fileUrl ) ;
2640 if ( ! response . ok ) {
2741 throw new Error ( `HTTP ${ response . status } : ${ response . statusText } ` ) ;
@@ -30,18 +44,30 @@ export async function downloadOrShare(fileId: string, filename?: string): Promis
3044 const blob = await response . blob ( ) ;
3145 const file = new File ( [ blob ] , filename || 'download' , { type : blob . type } ) ;
3246
47+ console . log ( '[downloadOrShare] Calling navigator.share with file:' , {
48+ name : file . name ,
49+ type : file . type ,
50+ size : file . size
51+ } ) ;
52+
3353 await navigator . share ( { files : [ file ] } ) ;
54+ console . log ( '[downloadOrShare] Share succeeded' ) ;
3455 // Success: user shared or saved (no toast needed, native UI provides feedback)
3556 } catch ( error : any ) {
57+ console . error ( '[downloadOrShare] Share failed:' , error ) ;
58+
3659 // User cancelled the share sheet → AbortError (don't show error)
37- if ( error . name === 'AbortError' ) return ;
60+ if ( error . name === 'AbortError' ) {
61+ console . log ( '[downloadOrShare] User cancelled share sheet' ) ;
62+ return ;
63+ }
3864
3965 // Actual error → show toast with details
40- console . error ( 'Share failed:' , error ) ;
4166 const message = error . message || 'Unknown error' ;
4267 addToast ( 'error' , `Failed to share file: ${ message } ` ) ;
4368
4469 // Fallback: try traditional download
70+ console . log ( '[downloadOrShare] Falling back to window.open' ) ;
4571 window . open ( fileUrl , '_blank' ) ;
4672 }
4773}
0 commit comments