diff --git a/examples/firebase/functions/src/index.ts b/examples/firebase/functions/src/index.ts index a7cffb3..e5e0d81 100644 --- a/examples/firebase/functions/src/index.ts +++ b/examples/firebase/functions/src/index.ts @@ -1,24 +1,19 @@ import * as functions from "firebase-functions"; -import admin from "firebase-admin"; +import { initializeApp } from "firebase-admin/app"; +import { getStorage } from "firebase-admin/storage"; import passkit from "passkit-generator"; import type { Barcode, TransitType } from "passkit-generator"; import fs from "node:fs"; import path from "node:path"; import os from "node:os"; +// Please note this is experimental in NodeJS as +// it is marked as Stage 3 in TC39 +// Should probably not be used in production +import startData from "./startData.json" assert { "type": "json" }; + const PKPass = passkit.PKPass; -// Firebase init -admin - .initializeApp - // { - // credential: admin.credential.cert(require("CERTIFICATE_PATH")), - // storageBucket: "STORAGE_BUCKET_URL", - // } - (); - -const storageRef = admin.storage().bucket(); - interface RequestWithBody extends functions.Request { body: { passModel: string; @@ -56,6 +51,13 @@ declare global { } } +// Firebase init +initializeApp({ + storageBucket: startData.FIREBASE_BUCKET_ADDR, +}); + +const storageRef = getStorage().bucket(); + export const pass = functions.https.onRequest( async (request: RequestWithBody, response) => { try { @@ -283,28 +285,6 @@ export const pass = functions.https.onRequest( response.set("Content-Type", newPass.mimeType); response.status(200).send(bufferData); - - // Delete thumbnail file in Firebase Storage - storageRef - .file(`thumbnails/${request.body.thumbnailFile}`) - .delete() - .then(() => { - console.log("Thumbnail file deleted successfully"); - }) - .catch((error) => { - console.error(error); - }); - - // Delete logo file in Firebase Storage - storageRef - .file(`logos/${logoFile}`) - .delete() - .then(() => { - console.log("Logo file deleted successfully"); - }) - .catch((error) => { - console.error(error); - }); } catch (error) { console.log("Error Uploading pass " + error); diff --git a/examples/firebase/functions/src/startData.json b/examples/firebase/functions/src/startData.json new file mode 100644 index 0000000..6fe0c67 --- /dev/null +++ b/examples/firebase/functions/src/startData.json @@ -0,0 +1,3 @@ +{ + "FIREBASE_BUCKET_ADDR": "