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 +36
-0
lines changed
scripts/code.angularjs.org-firebase/functions Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -169,4 +169,40 @@ function sendStoredFile(request, response) {
169
169
}
170
170
}
171
171
172
+ function deleteOldSnapshotZip ( event ) {
173
+ const object = event . data ;
174
+
175
+ const bucketId = object . bucket ;
176
+ const filePath = object . name ;
177
+ const contentType = object . contentType ;
178
+ const resourceState = object . resourceState ;
179
+
180
+ const bucket = gcs . bucket ( bucketId ) ;
181
+
182
+ if ( contentType !== 'application/zip' ||
183
+ ! filePath . startsWith ( 'snapshot/' ) ||
184
+ resourceState === 'not_exists' // Deletion event
185
+ ) {
186
+ return ;
187
+ }
188
+
189
+ bucket . getFiles ( {
190
+ prefix : 'snapshot/' ,
191
+ delimiter : '/' ,
192
+ autoPaginate : false
193
+ } ) . then ( function ( data ) {
194
+ const files = data [ 0 ] ;
195
+
196
+ const oldZipFiles = files . filter ( file => {
197
+ return file . metadata . name !== filePath && file . metadata . contentType === 'application/zip' ;
198
+ } ) ;
199
+
200
+ oldZipFiles . forEach ( function ( file ) {
201
+ file . delete ( ) ;
202
+ } ) ;
203
+
204
+ } ) ;
205
+ }
206
+
172
207
exports . sendStoredFile = functions . https . onRequest ( sendStoredFile ) ;
208
+ exports . deleteOldSnapshotZip = functions . storage . object ( ) . onChange ( deleteOldSnapshotZip ) ;
You can’t perform that action at this time.
0 commit comments