diff --git a/functions/src/api/routes/event/exportSchedulePdf.ts b/functions/src/api/routes/event/exportSchedulePdf.ts index 01eab701..7855a074 100644 --- a/functions/src/api/routes/event/exportSchedulePdf.ts +++ b/functions/src/api/routes/event/exportSchedulePdf.ts @@ -6,7 +6,7 @@ import { getFirebaseProjectId } from '../../../utils/getFirebaseProjectId' import { getServiceAPIKey } from '../../../serviceApi/serviceApiKeyPreHandler' import { getIndividualDays } from '../../../../../src/utils/dates/diffDays' import { uploadBufferToStorage } from '../file/utils/uploadBufferToStorage' -import { addPdfFileToEvent, getFilesNames, getUploadFilePath } from '../deploy/updateWebsiteActions/getFilesNames' +import { addPdfFileToEvent } from '../deploy/updateWebsiteActions/getFilesNames' import { getFileName } from '../../other/getFileName' const ExportPdfReply = Type.Object({ @@ -130,17 +130,8 @@ export const exportSchedulePdfRoute = (fastify: FastifyInstance, options: any, d return reply.status(400).send(publicFileUrlOrError) } - if (!event.files?.pdf) { - const updatedEvent = await EventDao.getEvent(fastify.firebase, eventId) - const eventFiles = await getFilesNames(fastify.firebase, updatedEvent) - const uploadFilePath = getUploadFilePath(eventFiles) - return reply.status(200).send({ - pdf: uploadFilePath.pdf, - }) - } - reply.status(200).send({ - pdf: getUploadFilePath(event.files).pdf, + pdf: publicFileUrlOrError, }) } catch (err) { const error = err as Error diff --git a/src/utils/images/uploadImage.ts b/src/utils/images/uploadImage.ts index 278653fd..248bc1a7 100644 --- a/src/utils/images/uploadImage.ts +++ b/src/utils/images/uploadImage.ts @@ -4,9 +4,19 @@ import { v4 as uuidv4 } from 'uuid' export const uploadImage = async (imageFolder: string, image: Blob): Promise => { const fileName = uuidv4() + const storageBucket = storage.app.options.storageBucket! - const outputRef = ref(storage, `${imageFolder}${fileName}`) + // imageFolder may be a full public URL; extract just the storage path + const baseUrl = `https://storage.googleapis.com/${storageBucket}/` + const altUrl = `https://${storageBucket}.storage.googleapis.com/` + const folderPath = imageFolder.startsWith(baseUrl) + ? imageFolder.slice(baseUrl.length) + : imageFolder.startsWith(altUrl) + ? imageFolder.slice(altUrl.length) + : imageFolder + + const outputRef = ref(storage, `${folderPath}${fileName}`) await uploadBytes(outputRef, image, {}) - return `${imageFolder}${fileName}` + return `https://${storageBucket}.storage.googleapis.com/${outputRef.fullPath}` }