@@ -10,19 +10,17 @@ const BROWSER_CACHE_DURATION = 60 * 10;
1010const CDN_CACHE_DURATION = 60 * 60 * 12 ;
1111
1212function sendStoredFile ( request , response ) {
13- let filePathSegments = request . path . split ( '/' ) . filter ( ( segment ) => {
13+ const requestPath = request . path || '/' ;
14+ let filePathSegments = requestPath . split ( '/' ) . filter ( ( segment ) => {
1415 // Remove empty leading or trailing path parts
1516 return segment !== '' ;
1617 } ) ;
1718
18-
1919 const version = filePathSegments [ 0 ] ;
2020 const isDocsPath = filePathSegments [ 1 ] === 'docs' ;
2121 const lastSegment = filePathSegments [ filePathSegments . length - 1 ] ;
2222 const bucket = gcs . bucket ( gcsBucketId ) ;
2323
24- console . log ( request . path , lastSegment ) ;
25-
2624 let downloadSource ;
2725 let fileName ;
2826
@@ -162,7 +160,11 @@ function sendStoredFile(request, response) {
162160 const nextQuery = data [ 1 ] ;
163161 const apiResponse = data [ 2 ] ;
164162
165- 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 ) ) {
166168 return Promise . reject ( {
167169 code : 404
168170 } ) ;
@@ -197,12 +199,15 @@ function deleteOldSnapshotZip(object, context) {
197199 const bucketId = object . bucket ;
198200 const filePath = object . name ;
199201 const contentType = object . contentType ;
200- const resourceState = object . resourceState ;
201202
202203 const bucket = gcs . bucket ( bucketId ) ;
203204
204205 const snapshotFolderMatch = filePath . match ( snapshotRegex ) ;
205206
207+ if ( ! snapshotFolderMatch || contentType !== 'application/zip' ) {
208+ return ;
209+ }
210+
206211 bucket . getFiles ( {
207212 prefix : snapshotFolderMatch [ 0 ] ,
208213 delimiter : '/' ,
0 commit comments