Skip to content

Commit 740a5a1

Browse files
committed
fix: 兼容 R2
1 parent 9a07ee5 commit 740a5a1

3 files changed

Lines changed: 10 additions & 5 deletions

File tree

trendradar/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@
99

1010
from trendradar.context import AppContext
1111

12-
__version__ = "4.0.1"
12+
__version__ = "4.0.2"
1313
__all__ = ["AppContext", "__version__"]

trendradar/storage/remote.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,15 @@ def __init__(
9393

9494
# 初始化 S3 客户端
9595
# 使用 virtual-hosted style addressing(主流)
96-
# 使用 s3 签名版本(v2),避免 s3v4 签名可能导致的 chunked encoding 问题
96+
# 根据服务商选择签名版本:
97+
# - Cloudflare R2 只支持 SigV4
98+
# - 腾讯云 COS 等使用 SigV2 以避免 chunked encoding 问题
99+
is_cloudflare_r2 = "r2.cloudflarestorage.com" in endpoint_url.lower()
100+
signature_version = 's3v4' if is_cloudflare_r2 else 's3'
101+
97102
s3_config = BotoConfig(
98103
s3={"addressing_style": "virtual"},
99-
signature_version='s3', # 使用 S3v2 签名,兼容性更好
104+
signature_version=signature_version,
100105
)
101106

102107
client_kwargs = {
@@ -114,7 +119,7 @@ def __init__(
114119
self._downloaded_files: List[Path] = []
115120
self._db_connections: Dict[str, sqlite3.Connection] = {}
116121

117-
print(f"[远程存储] 初始化完成,存储桶: {bucket_name}")
122+
print(f"[远程存储] 初始化完成,存储桶: {bucket_name},签名版本: {signature_version}")
118123

119124
@property
120125
def backend_name(self) -> str:

version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
4.0.1
1+
4.0.2

0 commit comments

Comments
 (0)