@@ -10,7 +10,8 @@ const BROWSER_CACHE_DURATION = 60 * 10;
10
10
const CDN_CACHE_DURATION = 60 * 60 * 12 ;
11
11
12
12
function sendStoredFile ( request , response ) {
13
- let filePathSegments = request . path . split ( '/' ) . filter ( ( segment ) => {
13
+ const requestPath = request . path || '/' ;
14
+ let filePathSegments = requestPath . split ( '/' ) . filter ( ( segment ) => {
14
15
// Remove empty leading or trailing path parts
15
16
return segment !== '' ;
16
17
} ) ;
@@ -159,7 +160,11 @@ function sendStoredFile(request, response) {
159
160
const nextQuery = data [ 1 ] ;
160
161
const apiResponse = data [ 2 ] ;
161
162
162
- if ( ! files . length && ( ! apiResponse || ! apiResponse . prefixes ) ) {
163
+ if (
164
+ // we got no files or directories from previous query pages
165
+ ! fileList . length && ! directoryList . length &&
166
+ // this query page has no file or directories
167
+ ! files . length && ( ! apiResponse || ! apiResponse . prefixes ) ) {
163
168
return Promise . reject ( {
164
169
code : 404
165
170
} ) ;
@@ -190,22 +195,16 @@ const snapshotRegex = /^snapshot(-stable)?\//;
190
195
* When a new zip file is uploaded into snapshot or snapshot-stable,
191
196
* delete the previous zip file.
192
197
*/
193
- function deleteOldSnapshotZip ( event ) {
194
- const object = event . data ;
195
-
198
+ function deleteOldSnapshotZip ( object , context ) {
196
199
const bucketId = object . bucket ;
197
200
const filePath = object . name ;
198
201
const contentType = object . contentType ;
199
- const resourceState = object . resourceState ;
200
202
201
203
const bucket = gcs . bucket ( bucketId ) ;
202
204
203
205
const snapshotFolderMatch = filePath . match ( snapshotRegex ) ;
204
206
205
- if ( ! snapshotFolderMatch ||
206
- contentType !== 'application/zip' ||
207
- resourceState === 'not_exists' // Deletion event
208
- ) {
207
+ if ( ! snapshotFolderMatch || contentType !== 'application/zip' ) {
209
208
return ;
210
209
}
211
210
@@ -230,4 +229,4 @@ function deleteOldSnapshotZip(event) {
230
229
}
231
230
232
231
exports . sendStoredFile = functions . https . onRequest ( sendStoredFile ) ;
233
- exports . deleteOldSnapshotZip = functions . storage . object ( ) . onChange ( deleteOldSnapshotZip ) ;
232
+ exports . deleteOldSnapshotZip = functions . storage . object ( ) . onFinalize ( deleteOldSnapshotZip ) ;
0 commit comments