mirror of
https://gitee.com/houhuan/TrendRadar.git
synced 2026-05-01 00:12:42 +08:00
fix: StorageManager 添加推送记录代理方法 + S3 切换至 virtual-hosted style 提升兼容性
This commit is contained in:
@@ -9,5 +9,5 @@ TrendRadar - 热点新闻聚合与分析工具
|
||||
|
||||
from trendradar.context import AppContext
|
||||
|
||||
__version__ = "4.0.0"
|
||||
__version__ = "4.0.1"
|
||||
__all__ = ["AppContext", "__version__"]
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user