diff --git a/src/firestore/app/appkit.ts b/src/firestore/app/appkit.ts index c1a781ec..d90b20f7 100644 --- a/src/firestore/app/appkit.ts +++ b/src/firestore/app/appkit.ts @@ -1,7 +1,7 @@ /* eslint-disable @typescript-eslint/no-non-null-assertion */ import { onAuthStateChanged } from 'firebase/auth'; import { updateDoc, arrayRemove, arrayUnion } from 'firebase/firestore'; - +import { ref, getDownloadURL } from 'firebase/storage'; import { IComputedScores, IRawScores, RoarRun } from './run'; import { ITaskVariantInfo, RoarTaskVariant } from './task'; import { IUserInfo, IUserUpdateInput, RoarAppUser } from './user'; @@ -303,4 +303,13 @@ export class RoarAppkit { throw new Error('This run has not started. Use the startRun method first.'); } } + + async getStorageDownloadUrl(filePath: string) { + if (!this._initialized) { + await this._init(); + } + + const storageRef = ref(this.firebaseProject!.storage, filePath); + return getDownloadURL(storageRef); + } } diff --git a/src/firestore/interfaces.ts b/src/firestore/interfaces.ts index 93644f53..0c16f264 100644 --- a/src/firestore/interfaces.ts +++ b/src/firestore/interfaces.ts @@ -2,6 +2,7 @@ import { FirebaseApp } from 'firebase/app'; import { Auth, User } from 'firebase/auth'; import { DocumentData, Firestore, Timestamp } from 'firebase/firestore'; import { Functions } from 'firebase/functions'; +import { FirebaseStorage } from 'firebase/storage'; import { FirebasePerformance } from 'firebase/performance'; import { FirebaseConfigData } from './util'; @@ -15,6 +16,7 @@ export interface IFirekit { db: Firestore; auth: Auth; functions: Functions; + storage: FirebaseStorage; perf?: FirebasePerformance; user?: User; claimsLastUpdated?: Date; diff --git a/src/firestore/util.ts b/src/firestore/util.ts index 51b9350f..5693e0bd 100644 --- a/src/firestore/util.ts +++ b/src/firestore/util.ts @@ -10,6 +10,7 @@ import { } from 'firebase/auth'; import { connectFirestoreEmulator, Firestore, getFirestore } from 'firebase/firestore'; import { Functions, connectFunctionsEmulator, getFunctions } from 'firebase/functions'; +import { getStorage, FirebaseStorage } from 'firebase/storage'; import { getPerformance } from 'firebase/performance'; import _chunk from 'lodash/chunk'; import _difference from 'lodash/difference'; @@ -118,7 +119,7 @@ export interface MarkRawConfig { functions?: boolean; } -type FirebaseProduct = Auth | Firestore | Functions; +type FirebaseProduct = Auth | Firestore | Functions | FirebaseStorage; export const initializeFirebaseProject = async ( config: FirebaseConfigData, @@ -140,6 +141,7 @@ export const initializeFirebaseProject = async ( const auth = optionallyMarkRaw('auth', getAuth(app)); const db = optionallyMarkRaw('db', getFirestore(app)); const functions = optionallyMarkRaw('functions', getFunctions(app)); + const storage = optionallyMarkRaw('storage', getStorage(app)); connectFirestoreEmulator(db, '127.0.0.1', ports.db); connectFunctionsEmulator(functions, '127.0.0.1', ports.functions); @@ -155,6 +157,7 @@ export const initializeFirebaseProject = async ( auth, db, functions, + storage, }; } else { const app = safeInitializeApp(config as RealConfigData, name); @@ -163,6 +166,7 @@ export const initializeFirebaseProject = async ( auth: optionallyMarkRaw('auth', getAuth(app)), db: optionallyMarkRaw('db', getFirestore(app)), functions: optionallyMarkRaw('functions', getFunctions(app)), + storage: optionallyMarkRaw('storage', getStorage(app)), perf: getPerformance(app), };