I am currently using the firebase image resizer extension. When a file is uploaded to a specified path, the image resizer deletes the original and provides 3 resized images. In order to grab the image url I have created a firebase storage trigger to grab the url and update a user's document with said url. I am able to do so by obtaining a signed url, but I am storing the signed url on the user document for an extended period of time; thus, I would prefer to grab the image url as seen on the firebase storage bucket. Any and all suggestions would be greatly appreciated.
my code is as follows:
const { functions, db, admin } = require('../util/firebase')
exports.trgUserImg = functions.storage.object().onFinalize(async (object) => {
const name = object.name
try {
const bucket = admin.storage().bucket()
const file = bucket.file(name)
const options = {
action: 'read',
expires: '03-17-2025'
}
const imageUrl = await file
.getSignedUrl(options)
.then((results) => {
const url = results[0]
return url
})
.catch((error) => {
console.error(new Error(`imageUrl`, error.message))
})
} catch (error) {
console.error(new Error(`trgUserImg: ${error.message}`))
}
return null
})