mirror of
https://github.com/RhenCloud/Cloud-Index.git
synced 2025-12-06 15:26:10 +08:00
feat: 重构配置管理,集中管理环境变量并优化存储后端实现
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user