fix: StorageManager 添加推送记录代理方法 + S3 切换至 virtual-hosted style 提升兼容性

This commit is contained in:
sansan
2025-12-17 19:26:34 +08:00
parent 73364a3af0
commit 6dd29eaee3
6 changed files with 66 additions and 133 deletions
+27
View File
@@ -264,6 +264,33 @@ class StorageManager:
"""是否支持 TXT 快照"""
return self.get_backend().supports_txt
# === 推送记录相关方法 ===
def has_pushed_today(self, date: Optional[str] = None) -> bool:
"""
检查指定日期是否已推送过
Args:
date: 日期字符串(YYYY-MM-DD),默认为今天
Returns:
是否已推送
"""
return self.get_backend().has_pushed_today(date)
def record_push(self, report_type: str, date: Optional[str] = None) -> bool:
"""
记录推送
Args:
report_type: 报告类型
date: 日期字符串(YYYY-MM-DD),默认为今天
Returns:
是否记录成功
"""
return self.get_backend().record_push(report_type, date)
def get_storage_manager(
backend_type: str = "auto",
+6
View File
@@ -21,11 +21,13 @@ from typing import Dict, List, Optional, Any
try:
import boto3
from botocore.config import Config as BotoConfig
from botocore.exceptions import ClientError
HAS_BOTO3 = True
except ImportError:
HAS_BOTO3 = False
boto3 = None
BotoConfig = None
ClientError = Exception
from trendradar.storage.base import StorageBackend, NewsItem, NewsData
@@ -90,10 +92,14 @@ class RemoteStorageBackend(StorageBackend):
self.temp_dir.mkdir(parents=True, exist_ok=True)
# 初始化 S3 客户端
# 使用 virtual-hosted style addressing(主流)
s3_config = BotoConfig(s3={"addressing_style": "virtual"})
client_kwargs = {
"endpoint_url": endpoint_url,
"aws_access_key_id": access_key_id,
"aws_secret_access_key": secret_access_key,
"config": s3_config,
}
if region:
client_kwargs["region_name"] = region