Frank van Puffelen has an example for deleting database after time. https://stackoverflow.com/a/32012520/12253594 https://github.com/firebase/functions-samples/tree/master/delete-old-child-nodes
Which works wonders. But I'm wondering if it is possible for Storage as well?
The structure: Experiences -> Experience_ID -> fullHD -> Image
And I want to delete including Experience_ID.
I'm thinking, something like:
exports.deleteOldItems = functions.storange.ref('/Experiences/{notification_id}')
.onWrite((change, context) => {
var ref = change.after.ref.parent; // reference to the items
var now = Date.now();
var cutoff = now - 2 * 60 * 60 * 1000;
var oldItemsQuery = ref.orderByChild('timestamp').endAt(cutoff);
return oldItemsQuery.once('value', function(snapshot) {
// create a map with all children that need to be removed
var updates = {};
snapshot.forEach(function(child) {
updates[child.key] = null
});
// execute all updates in one go and return the result to end the function
return ref.update(updates);
});
});
But I obviously don't have timestamps like I do in the database section. So what do I do?
Best regards,