Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
FIREBASE_STORAGE_BUCKET="" # Firebase storage bucket of your Ruxailab project
FIREBASE_STORAGE_BUCKET="" # Firebase storage bucket of your Ruxailab project

FIREBASE_EMULATOR_HOST=localhost
STORAGE_EMULATOR_PORT=
FIRESTORE_EMULATOR_PORT=
FIREBASE_PROJECT_ID=
USE_EMULATORS=false #true if running firebase emulators
27 changes: 23 additions & 4 deletions services/data/firebase_imp.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import os
import firebase_admin
import logging
import coloredlogs

from firebase_admin import firestore, storage
from firebase_admin import firestore, storage, credentials
from services.data.firebase_service import FirebaseService


Expand All @@ -24,11 +25,29 @@ def __init__(self, storage_bucket: str):
self.storage_client = storage.bucket()

def _initialize_app(self):
if os.getenv('USE_EMULATORS', '').lower() == 'true':

emulator_host = os.getenv('FIREBASE_EMULATOR_HOST', 'localhost')
storage_port = os.getenv('STORAGE_EMULATOR_PORT', '9199')
firestore_port = os.getenv('FIRESTORE_EMULATOR_PORT', '8080')

os.environ['STORAGE_EMULATOR_HOST'] = f"http://{emulator_host}:{storage_port}"
os.environ['FIRESTORE_EMULATOR_HOST'] = f"{emulator_host}:{firestore_port}"

options = {
"storageBucket": self.storage_bucket,
"projectId": os.getenv('FIREBASE_PROJECT_ID')
}

else:

options = {
"storageBucket": self.storage_bucket
}

if not firebase_admin._apps:
firebase_admin.initialize_app(
options={
"storageBucket": self.storage_bucket
}
options=options
)

def download_video_from_storage(self, video_name: str):
Expand Down