Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 919087f

Browse files
authored
chore(code.angular): correctly remove old zip files from snapshot
Previously, the event would be triggered on the deletion of the previous zip files, which would delete the current zip file as well Closes #16168
1 parent 5b31b37 commit 919087f

File tree

1 file changed

+19
-17
lines changed
  • scripts/code.angularjs.org-firebase/functions

1 file changed

+19
-17
lines changed

scripts/code.angularjs.org-firebase/functions/index.js

+19-17
Original file line numberDiff line numberDiff 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

205207
exports.sendStoredFile = functions.https.onRequest(sendStoredFile);

0 commit comments

Comments
 (0)