mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-01-26 22:30:19 +08:00
fix: oss2
This commit is contained in:
parent
a88a90d9a7
commit
304560d9f5
@ -28,13 +28,13 @@ logging.basicConfig(level=logging.INFO, format='%(levelname)s: %(message)s')
|
|||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
# OSS Configuration - TODO: Configure these values
|
# OSS Configuration - Try bucket-specific endpoint
|
||||||
OSS_CONFIG = {
|
OSS_CONFIG = {
|
||||||
'endpoint': '', # OSS endpoint, e.g., 'https://oss-cn-hangzhou.aliyuncs.com'
|
'endpoint': 'https://oss-cn-shanghai.aliyuncs.com', # Bucket-specific endpoint
|
||||||
'access_key_id': '', # Access Key ID
|
'access_key_id': '',
|
||||||
'access_key_secret': '', # Access Key Secret
|
'access_key_secret': '',
|
||||||
'bucket_name': '', # Bucket name
|
'bucket_name': 'tusi-assets',
|
||||||
'base_path': 'extensions/', # Base path in OSS bucket
|
'base_path': 'comfyui/howell5/static_extensions/',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -50,18 +50,41 @@ def get_oss_client():
|
|||||||
# Try to import oss2 - if not available, fall back to local mode
|
# Try to import oss2 - if not available, fall back to local mode
|
||||||
try:
|
try:
|
||||||
import oss2
|
import oss2
|
||||||
|
from oss2.credentials import StaticCredentialsProvider
|
||||||
except ImportError:
|
except ImportError:
|
||||||
logger.warning("oss2 package not found. Install with: pip install oss2")
|
logger.warning("oss2 package not found. Install with: pip install oss2")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
# Initialize OSS client
|
# Initialize OSS client with V4 auth and region
|
||||||
auth = oss2.Auth(OSS_CONFIG['access_key_id'], OSS_CONFIG['access_key_secret'])
|
# Use StaticCredentialsProvider for direct key/secret
|
||||||
bucket = oss2.Bucket(auth, OSS_CONFIG['endpoint'], OSS_CONFIG['bucket_name'])
|
credentials_provider = StaticCredentialsProvider(
|
||||||
|
OSS_CONFIG['access_key_id'],
|
||||||
|
OSS_CONFIG['access_key_secret']
|
||||||
|
)
|
||||||
|
auth = oss2.ProviderAuthV4(credentials_provider)
|
||||||
|
|
||||||
# Test connection
|
# Extract region from endpoint or use default
|
||||||
bucket.get_bucket_info()
|
region = "cn-shanghai" # extracted from oss-cn-shanghai.aliyuncs.com
|
||||||
logger.info(f"OSS connection established to bucket: {OSS_CONFIG['bucket_name']}")
|
|
||||||
return bucket
|
bucket = oss2.Bucket(
|
||||||
|
auth,
|
||||||
|
OSS_CONFIG['endpoint'],
|
||||||
|
OSS_CONFIG['bucket_name'],
|
||||||
|
region=region
|
||||||
|
)
|
||||||
|
|
||||||
|
# Test connection with a simple list operation
|
||||||
|
logger.info(f"Testing OSS connection to {OSS_CONFIG['endpoint']}/{OSS_CONFIG['bucket_name']}")
|
||||||
|
|
||||||
|
try:
|
||||||
|
result = bucket.list_objects(max_keys=1)
|
||||||
|
logger.info(f"OSS connection established to bucket: {OSS_CONFIG['bucket_name']}")
|
||||||
|
return bucket
|
||||||
|
except Exception as list_error:
|
||||||
|
logger.error(f"OSS list test failed: {list_error}")
|
||||||
|
logger.info("Trying without connection test...")
|
||||||
|
# Return bucket anyway, let the upload operations handle errors
|
||||||
|
return bucket
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warning(f"Failed to initialize OSS client: {e}. Falling back to local mode.")
|
logger.warning(f"Failed to initialize OSS client: {e}. Falling back to local mode.")
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user