KyrosDev's picture
新增版本管理系統和雙Supabase專案整合
5486429
"""
KSTools License Manager - 授權系統資料庫連接
專門處理授權系統 (Project 1) 的資料庫操作
"""
import os
from supabase import create_client, Client
from typing import Optional
class LicenseDatabase:
"""授權系統 Supabase 資料庫客戶端"""
def __init__(self):
# 明確使用授權系統的環境變數
self.url: str = os.environ.get("SUPABASE_LICENSE_URL", "")
self.key: str = os.environ.get("SUPABASE_LICENSE_SERVICE_KEY", "")
self.client: Optional[Client] = None
print(f"🔗 Initializing License System Supabase connection...")
print(f" URL: {self.url[:50]}{'...' if len(self.url) > 50 else ''}")
print(f" Key: {'*' * 20 if self.key else 'NOT SET'}")
if self.url and self.key and not self.url.startswith('your-') and not self.key.startswith('your-'):
try:
self.client = create_client(self.url, self.key)
print("✅ License System Supabase connection initialized successfully")
except Exception as e:
print(f"❌ License System Supabase connection failed: {e}")
self.client = None
else:
print("⚠️ License System Supabase 環境變數未設定或使用預設值")
print(" 請在 Hugging Face Spaces Settings 或 .env 檔案中設定正確的 SUPABASE_LICENSE_URL 和 SUPABASE_LICENSE_SERVICE_KEY")
def get_client(self) -> Optional[Client]:
"""取得授權系統 Supabase 客戶端"""
if not self.client:
print("❌ License System Supabase client 未初始化")
return self.client
def is_connected(self) -> bool:
"""檢查授權系統是否連接成功"""
connected = self.client is not None
print(f"🔍 License System Supabase connection status: {'Connected' if connected else 'Not connected'}")
return connected
# 全域授權系統資料庫實例
license_db = LicenseDatabase()
# 保留舊名稱以維持相容性
db = license_db