@@ -94,8 +94,7 @@ self.addEventListener('activate', event => {
94
94
} ) ;
95
95
96
96
// Handle share target requests: This listener specifically processes POST requests
97
- // to the /share-target endpoint, which is triggered when other apps share content with wami.
98
- // It stores the shared data and files in a temporary cache for the main app to access.
97
+ // to the /share-target endpoint
99
98
self . addEventListener ( 'fetch' , event => {
100
99
// Only process POST requests to the share-target endpoint
101
100
if ( event . request . method === 'POST' && event . request . url . includes ( '/share-target' ) ) {
@@ -122,23 +121,26 @@ self.addEventListener('fetch', event => {
122
121
// Store the files in a temporary cache for the client to access
123
122
const shareCache = await caches . open ( 'share-target-cache' ) ;
124
123
125
- // Create an object with the share data
124
+ // Extract file names and store them in the shareData
125
+ const fileNames = files . map ( file => file . name ) ;
126
+
127
+ // Create share data object with file names array
126
128
const shareData = {
127
129
title : data . title ,
128
130
text : data . text ,
129
131
url : data . url ,
130
132
timestamp : Date . now ( ) ,
131
- fileCount : files . length
133
+ fileCount : files . length ,
134
+ fileNames : fileNames // Store file names in the share data
132
135
} ;
133
136
134
- // Store the share data and files
137
+ // Store the share data
135
138
await shareCache . put ( 'shareData' , new Response ( JSON . stringify ( shareData ) ) ) ;
136
139
137
140
// Store each file with a unique key
138
141
for ( let i = 0 ; i < files . length ; i ++ ) {
139
142
const file = files [ i ] ;
140
- const response = new Response ( file ) ;
141
- await shareCache . put ( `file-${ i } ` , response ) ;
143
+ await shareCache . put ( `file-${ i } ` , new Response ( file ) ) ;
142
144
}
143
145
}
144
146
} catch ( error ) {
0 commit comments