Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- export const deletePhoto = functions.firestore
- .document("posts/{postId}")
- .onUpdate((change, context) => {
- // Get an object representing the document
- const updatedPost = change.after.data() as any;
- // ...or the previous value before this update
- const oldPost = change.before.data() as any;
- const oldImages: string[] = oldPost.images;
- const newImages: string[] = updatedPost.images;
- const deletedImages = oldImages.filter(oldImage => {
- return !newImages.some(newImage => newImage === oldImage);
- });
- const bucket = firebase.storage().bucket();
- const imagesRemovePromises = deletedImages.map((imagePath: string) => {
- return bucket.file(imagePath).delete();
- });
- return Promise.all(imagesRemovePromises);
- });
Add Comment
Please, Sign In to add comment