@@ -10,19 +10,17 @@ 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
} ) ;
17
18
18
-
19
19
const version = filePathSegments [ 0 ] ;
20
20
const isDocsPath = filePathSegments [ 1 ] === 'docs' ;
21
21
const lastSegment = filePathSegments [ filePathSegments . length - 1 ] ;
22
22
const bucket = gcs . bucket ( gcsBucketId ) ;
23
23
24
- console . log ( request . path , lastSegment ) ;
25
-
26
24
let downloadSource ;
27
25
let fileName ;
28
26
@@ -162,7 +160,11 @@ function sendStoredFile(request, response) {
162
160
const nextQuery = data [ 1 ] ;
163
161
const apiResponse = data [ 2 ] ;
164
162
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 ) ) {
166
168
return Promise . reject ( {
167
169
code : 404
168
170
} ) ;
@@ -197,12 +199,15 @@ function deleteOldSnapshotZip(object, context) {
197
199
const bucketId = object . bucket ;
198
200
const filePath = object . name ;
199
201
const contentType = object . contentType ;
200
- const resourceState = object . resourceState ;
201
202
202
203
const bucket = gcs . bucket ( bucketId ) ;
203
204
204
205
const snapshotFolderMatch = filePath . match ( snapshotRegex ) ;
205
206
207
+ if ( ! snapshotFolderMatch || contentType !== 'application/zip' ) {
208
+ return ;
209
+ }
210
+
206
211
bucket . getFiles ( {
207
212
prefix : snapshotFolderMatch [ 0 ] ,
208
213
delimiter : '/' ,
0 commit comments