This repository was archived by the owner on Apr 12, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +19
-17
lines changed
scripts/code.angularjs.org-firebase/functions Expand file tree Collapse file tree 1 file changed +19
-17
lines changed Original file line number Diff line number Diff line change @@ -175,31 +175,33 @@ function deleteOldSnapshotZip(event) {
175175 const bucketId = object . bucket ;
176176 const filePath = object . name ;
177177 const contentType = object . contentType ;
178+ const resourceState = object . resourceState ;
178179
179180 const bucket = gcs . bucket ( bucketId ) ;
180181
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
184185 ) {
186+ return ;
187+ }
185188
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 ] ;
196195
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+ } ) ;
200199
200+ oldZipFiles . forEach ( function ( file ) {
201+ file . delete ( ) ;
201202 } ) ;
202- }
203+
204+ } ) ;
203205}
204206
205207exports . sendStoredFile = functions . https . onRequest ( sendStoredFile ) ;
You can’t perform that action at this time.
0 commit comments