Spaces:
Running

File size: 2,563 Bytes
01bc36c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
"""
Quick script to check if Supabase bucket is configured correctly.
Run: python -m scripts.check_supabase_bucket
"""

import sys
from app.core.supabase import supabase_client

def main():
    print("=" * 60)
    print("Supabase Bucket Configuration Check")
    print("=" * 60)
    
    if not supabase_client:
        print("❌ Supabase client not initialized!")
        print("   Check SUPABASE_URL and SUPABASE_KEY in .env")
        return False
    
    print("βœ… Supabase client initialized")
    
    # List buckets
    try:
        buckets = supabase_client.storage.list_buckets()
        bucket_names = [b.name for b in buckets]
        print(f"\nπŸ“¦ Available buckets: {bucket_names}")
        
        if "chat-attachments" not in bucket_names:
            print("\n❌ 'chat-attachments' bucket NOT found!")
            print("   Create it in Supabase Dashboard:")
            print("   1. Storage β†’ New bucket")
            print("   2. Name: chat-attachments")
            print("   3. Public: ON")
            return False
        
        print("βœ… 'chat-attachments' bucket exists")
        
    except Exception as e:
        print(f"❌ Error listing buckets: {e}")
        return False
    
    # Test upload
    try:
        test_path = "test/check.txt"
        test_content = b"Test upload from check script"
        
        print(f"\n⬆️  Testing upload to {test_path}...")
        result = supabase_client.storage.from_("chat-attachments").upload(
            path=test_path,
            file=test_content,
            file_options={"content-type": "text/plain", "upsert": "true"}
        )
        print(f"βœ… Upload successful!")
        
        # Get public URL
        public_url = supabase_client.storage.from_("chat-attachments").get_public_url(test_path)
        print(f"βœ… Public URL: {public_url}")
        
        # Cleanup
        print(f"\n🧹 Cleaning up test file...")
        supabase_client.storage.from_("chat-attachments").remove([test_path])
        print("βœ… Cleanup complete")
        
    except Exception as e:
        print(f"❌ Upload failed: {e}")
        print("\n   Possible issues:")
        print("   1. Bucket is not public")
        print("   2. Missing RLS policy for INSERT")
        print("   3. SUPABASE_KEY doesn't have sufficient permissions")
        return False
    
    print("\n" + "=" * 60)
    print("βœ… All checks passed! Bucket is configured correctly.")
    print("=" * 60)
    return True


if __name__ == "__main__":
    success = main()
    sys.exit(0 if success else 1)