File size: 1,605 Bytes
32bc095
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
"""
Setup script: Creates the 'annotated-videos' public bucket in Supabase Storage.

Run this once from the back-end directory:
    python scripts/setup_annotated_bucket.py
"""
import os
import sys
from dotenv import load_dotenv

# Allow running from any directory
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
load_dotenv(os.path.join(os.path.dirname(os.path.dirname(__file__)), ".env"))

from supabase import create_client

SUPABASE_URL = os.environ["SUPABASE_URL"]
SERVICE_KEY = os.environ.get("SUPABASE_SERVICE_KEY") or os.environ["SUPABASE_KEY"]
BUCKET_NAME = "annotated-videos"


def main():
    client = create_client(SUPABASE_URL, SERVICE_KEY)

    # List existing buckets
    try:
        buckets = client.storage.list_buckets()
        names = [b.name for b in buckets]
        if BUCKET_NAME in names:
            print(f"✅  Bucket '{BUCKET_NAME}' already exists.")
            return
    except Exception as e:
        print(f"⚠️  Could not list buckets: {e}")

    # Create the bucket as public so the frontend can stream videos directly
    # without needing signed URLs.
    try:
        try:
            from storage3.types import CreateOrUpdateBucketOptions
            opts = CreateOrUpdateBucketOptions(public=True)
        except ImportError:
            opts = {"public": True}

        client.storage.create_bucket(BUCKET_NAME, options=opts)
        print(f"✅  Created public bucket '{BUCKET_NAME}'.")
    except Exception as e:
        print(f"❌  Failed to create bucket: {e}")
        sys.exit(1)


if __name__ == "__main__":
    main()