Spaces:
Sleeping
Sleeping
github-actions[bot] commited on
Commit ·
eae2fa6
1
Parent(s): e1c26fb
Automated deployment from GitHub Actions: 688f8f9ca5ff045fa33e55282928e37ba11c0939
Browse files- src/services/ingest_svc.py +13 -24
src/services/ingest_svc.py
CHANGED
|
@@ -68,24 +68,18 @@ class StorageService:
|
|
| 68 |
|
| 69 |
elif self.backend == "supabase":
|
| 70 |
supabase = get_supabase()
|
| 71 |
-
|
| 72 |
-
#
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
# Ensure bucket exists
|
| 77 |
-
buckets = supabase.storage.list_buckets()
|
| 78 |
-
if not any(b.name == self.bucket for b in buckets):
|
| 79 |
-
supabase.storage.create_bucket(self.bucket, {"public": False})
|
| 80 |
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
return res
|
| 87 |
|
| 88 |
-
await asyncio.to_thread(_upload)
|
| 89 |
log.info("Uploaded to Supabase Storage", path=object_path)
|
| 90 |
return object_path
|
| 91 |
|
|
@@ -104,12 +98,7 @@ class StorageService:
|
|
| 104 |
|
| 105 |
if self.backend == "supabase":
|
| 106 |
supabase = get_supabase()
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
def _download() -> bytes:
|
| 110 |
-
return supabase.storage.from_(self.bucket).download(object_path)
|
| 111 |
-
|
| 112 |
-
data = await asyncio.to_thread(_download)
|
| 113 |
return bytes(data)
|
| 114 |
|
| 115 |
raise ValueError(f"Unknown storage backend: {self.backend}")
|
|
@@ -118,7 +107,7 @@ class StorageService:
|
|
| 118 |
"""Compute SHA-256 hash of the file."""
|
| 119 |
return hashlib.sha256(file_bytes).hexdigest()
|
| 120 |
|
| 121 |
-
def get_presigned_url(self, object_path: str, expires_in: int = 3600) -> str:
|
| 122 |
"""Generate a presigned URL for preview/download."""
|
| 123 |
if self.backend == "minio":
|
| 124 |
return self.s3_client.generate_presigned_url(
|
|
@@ -129,7 +118,7 @@ class StorageService:
|
|
| 129 |
elif self.backend == "supabase":
|
| 130 |
# For Supabase, we can use create_signed_url
|
| 131 |
supabase = get_supabase()
|
| 132 |
-
res = supabase.storage.from_(self.bucket).create_signed_url(object_path, expires_in)
|
| 133 |
return res.get("signedURL", "")
|
| 134 |
return ""
|
| 135 |
|
|
|
|
| 68 |
|
| 69 |
elif self.backend == "supabase":
|
| 70 |
supabase = get_supabase()
|
| 71 |
+
|
| 72 |
+
# Ensure bucket exists
|
| 73 |
+
buckets = await supabase.storage.list_buckets()
|
| 74 |
+
if not any(b.name == self.bucket for b in buckets):
|
| 75 |
+
await supabase.storage.create_bucket(self.bucket, {"public": False})
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
|
| 77 |
+
await supabase.storage.from_(self.bucket).upload(
|
| 78 |
+
object_path,
|
| 79 |
+
file_bytes,
|
| 80 |
+
{"content-type": content_type}
|
| 81 |
+
)
|
|
|
|
| 82 |
|
|
|
|
| 83 |
log.info("Uploaded to Supabase Storage", path=object_path)
|
| 84 |
return object_path
|
| 85 |
|
|
|
|
| 98 |
|
| 99 |
if self.backend == "supabase":
|
| 100 |
supabase = get_supabase()
|
| 101 |
+
data = await supabase.storage.from_(self.bucket).download(object_path)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
return bytes(data)
|
| 103 |
|
| 104 |
raise ValueError(f"Unknown storage backend: {self.backend}")
|
|
|
|
| 107 |
"""Compute SHA-256 hash of the file."""
|
| 108 |
return hashlib.sha256(file_bytes).hexdigest()
|
| 109 |
|
| 110 |
+
async def get_presigned_url(self, object_path: str, expires_in: int = 3600) -> str:
|
| 111 |
"""Generate a presigned URL for preview/download."""
|
| 112 |
if self.backend == "minio":
|
| 113 |
return self.s3_client.generate_presigned_url(
|
|
|
|
| 118 |
elif self.backend == "supabase":
|
| 119 |
# For Supabase, we can use create_signed_url
|
| 120 |
supabase = get_supabase()
|
| 121 |
+
res = await supabase.storage.from_(self.bucket).create_signed_url(object_path, expires_in)
|
| 122 |
return res.get("signedURL", "")
|
| 123 |
return ""
|
| 124 |
|