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 +34
-0
lines changed
scripts/code.angularjs.org-firebase/functions Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -72,4 +72,38 @@ function sendStoredFile(request, response) {
72
72
}
73
73
}
74
74
75
+ function deleteOldSnapshotZip ( event ) {
76
+ const object = event . data ;
77
+
78
+ const bucketId = object . bucket ;
79
+ const filePath = object . name ;
80
+ const contentType = object . contentType ;
81
+
82
+ const bucket = gcs . bucket ( bucketId ) ;
83
+
84
+ if ( event . eventType === 'providers/cloud.storage/eventTypes/object.change' &&
85
+ contentType === 'application/zip' &&
86
+ filePath . startsWith ( 'snapshot/' )
87
+ ) {
88
+
89
+ bucket . getFiles ( {
90
+ prefix : 'snapshot/' ,
91
+ delimiter : '/' ,
92
+ autoPaginate : false
93
+ } ) . then ( function ( data ) {
94
+ const files = data [ 0 ] ;
95
+
96
+ const oldZipFiles = files . filter ( file => {
97
+ return file . metadata . name !== filePath && file . metadata . contentType === 'application/zip' ;
98
+ } ) ;
99
+
100
+ oldZipFiles . forEach ( function ( file ) {
101
+ file . delete ( ) ;
102
+ } ) ;
103
+
104
+ } ) ;
105
+ }
106
+ }
107
+
75
108
exports . sendStoredFile = functions . https . onRequest ( sendStoredFile ) ;
109
+ exports . deleteOldSnapshotZip = functions . storage . object ( ) . onChange ( deleteOldSnapshotZip ) ;
You can’t perform that action at this time.
0 commit comments