Save and retrieve playlists and epg guides from vercel blob storage

This commit is contained in:
2025-05-06 13:27:14 -05:00
parent a55695865e
commit beb1bdd8c0
8 changed files with 230 additions and 31 deletions

View File

@@ -1,5 +1,6 @@
from upstash_redis import Redis as UpstashRedis
from redis import Redis as LocalRedis, RedisError
import vercel_blob
from src.config import REDIS_URL, REDIS_TOKEN, USE_LOCAL_REDIS, LOCAL_REDIS_URL
from fastapi import HTTPException
import logging
@@ -33,4 +34,21 @@ except RedisError as re:
raise HTTPException(status_code=500, detail="Database connection error")
except Exception as e:
logger.error(f"Unexpected error while connecting to Redis: {str(e)}")
raise HTTPException(status_code=500, detail="Internal server error")
raise HTTPException(status_code=500, detail="Internal server error")
def get_blob_by_path(folder: str, filename: str) -> dict:
# Get list of all blobs
resp = vercel_blob.list()
# Search for matching blob path
target_path = f"{folder}/{filename}"
matching_blob = next(
(blob for blob in resp.get('blobs', [])
if blob.get('pathname') == target_path),
None
)
if not matching_blob:
raise HTTPException(status_code=404, detail="File not found")
return matching_blob