Skip to content
Open
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
31 changes: 19 additions & 12 deletions backend/utils/other/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from google.oauth2 import service_account
from google.cloud.storage import transfer_manager
from google.cloud.exceptions import NotFound as BlobNotFound
from google.cloud.exceptions import NotFound
from google.cloud.exceptions import NotFound, Forbidden

from database.redis_db import cache_signed_url, get_cached_signed_url
from utils import encryption
Expand Down Expand Up @@ -47,20 +47,27 @@ def upload_profile_audio(file_path: str, uid: str):


def get_user_has_speech_profile(uid: str, max_age_days: int = None) -> bool:
bucket = storage_client.bucket(speech_profiles_bucket)
blob = bucket.blob(f'{uid}/speech_profile.wav')
if not blob.exists():
if not speech_profiles_bucket:
return False

# Check age if max_age_days is specified
if max_age_days is not None:
blob.reload()
if blob.time_created:
age = datetime.datetime.now(datetime.timezone.utc) - blob.time_created
if age.days > max_age_days:
return False
try:
bucket = storage_client.bucket(speech_profiles_bucket)
blob = bucket.blob(f'{uid}/speech_profile.wav')

if not blob.exists():
return False

return True
# Check age if max_age_days is specified
if max_age_days is not None:
blob.reload()
if blob.time_created:
age = datetime.datetime.now(datetime.timezone.utc) - blob.time_created
if age.days > max_age_days:
return False

return True
except Forbidden:
return False


def get_profile_audio_if_exists(uid: str, download: bool = True) -> str:
Expand Down