feat: 重构配置管理,集中管理环境变量并优化存储后端实现

This commit is contained in:
2025-11-14 23:26:21 +08:00
parent 07a8fafff2
commit 33fe06c59e
10 changed files with 347 additions and 193 deletions

View File

@@ -1,14 +1,11 @@
import os
from typing import Optional
import dotenv
from config import Config
from .base import BaseStorage
from .github import GitHubStorage
from .r2 import R2Storage
dotenv.load_dotenv()
class StorageFactory:
"""存储工厂类,根据配置创建对应的存储实例"""
@@ -29,24 +26,19 @@ class StorageFactory:
if cls._instance is not None:
return cls._instance
storage_type = os.getenv("STORAGE_TYPE")
storage_type = Config.STORAGE_TYPE
if not storage_type:
raise RuntimeError(
"STORAGE_TYPE environment variable is not set. "
"Supported types: r2, github"
)
storage_type = storage_type.lower()
raise RuntimeError("STORAGE_TYPE environment variable is not set. Supported types: r2, github")
if storage_type == "r2":
cls._instance = R2Storage()
elif storage_type == "github":
cls._instance = GitHubStorage()
else:
raise RuntimeError(
f"Unsupported storage type: {storage_type}. Supported types: r2, github"
)
raise RuntimeError(f"Unsupported storage type: {storage_type}. Supported types: r2, github")
return cls._instance
return cls._instance