This repository was archived by the owner on Apr 12, 2024. It is now read-only.
File tree 1 file changed +19
-17
lines changed
scripts/code.angularjs.org-firebase/functions
1 file changed +19
-17
lines changed Original file line number Diff line number Diff line change @@ -175,31 +175,33 @@ function deleteOldSnapshotZip(event) {
175
175
const bucketId = object . bucket ;
176
176
const filePath = object . name ;
177
177
const contentType = object . contentType ;
178
+ const resourceState = object . resourceState ;
178
179
179
180
const bucket = gcs . bucket ( bucketId ) ;
180
181
181
- if ( event . eventType === 'providers/cloud.storage/eventTypes/object.change' &&
182
- contentType === 'application/zip' &&
183
- filePath . startsWith ( 'snapshot/' )
182
+ if ( contentType !== 'application/zip' ||
183
+ ! filePath . startsWith ( 'snapshot/' ) ||
184
+ resourceState === 'not_exists' // Deletion event
184
185
) {
186
+ return ;
187
+ }
185
188
186
- bucket . getFiles ( {
187
- prefix : 'snapshot/' ,
188
- delimiter : '/' ,
189
- autoPaginate : false
190
- } ) . then ( function ( data ) {
191
- const files = data [ 0 ] ;
192
-
193
- const oldZipFiles = files . filter ( file => {
194
- return file . metadata . name !== filePath && file . metadata . contentType === 'application/zip' ;
195
- } ) ;
189
+ bucket . getFiles ( {
190
+ prefix : 'snapshot/' ,
191
+ delimiter : '/' ,
192
+ autoPaginate : false
193
+ } ) . then ( function ( data ) {
194
+ const files = data [ 0 ] ;
196
195
197
- oldZipFiles . forEach ( function ( file ) {
198
- file . delete ( ) ;
199
- } ) ;
196
+ const oldZipFiles = files . filter ( file => {
197
+ return file . metadata . name !== filePath && file . metadata . contentType === 'application/zip' ;
198
+ } ) ;
200
199
200
+ oldZipFiles . forEach ( function ( file ) {
201
+ file . delete ( ) ;
201
202
} ) ;
202
- }
203
+
204
+ } ) ;
203
205
}
204
206
205
207
exports . sendStoredFile = functions . https . onRequest ( sendStoredFile ) ;
You can’t perform that action at this time.
0 commit comments