mirror of
https://github.com/RhenCloud/Cloud-Index.git
synced 2025-12-06 15:26:10 +08:00
feat: 完整的 R2 文件管理系统初始化
- 实现 11 个 API 端点:上传、删除、重命名、复制、移动、创建文件夹等 - 构建存储抽象层,支持多后端(R2、S3、GitHub) - 添加完整的前端界面:列表/网格视图、文件操作、批量管理 - 添加深色/浅色主题支持 - 迁移至 Jinja2 模板继承架构 - 添加完整的 API 文档和项目文档 - 优化 Vercel 部署配置
This commit is contained in:
54
storages/factory.py
Normal file
54
storages/factory.py
Normal file
@@ -0,0 +1,54 @@
|
||||
import os
|
||||
from typing import Optional
|
||||
|
||||
import dotenv
|
||||
|
||||
from .base import BaseStorage
|
||||
|
||||
# from .cnbcool import CnbCoolStorage
|
||||
from .r2 import R2Storage
|
||||
|
||||
dotenv.load_dotenv()
|
||||
|
||||
|
||||
class StorageFactory:
|
||||
"""存储工厂类,根据配置创建对应的存储实例"""
|
||||
|
||||
_instance: Optional[BaseStorage] = None
|
||||
|
||||
@classmethod
|
||||
def get_storage(cls) -> BaseStorage:
|
||||
"""
|
||||
获取存储实例(单例模式)
|
||||
|
||||
Returns:
|
||||
BaseStorage: 存储实例
|
||||
|
||||
Raises:
|
||||
RuntimeError: 当存储类型未配置或不支持时
|
||||
"""
|
||||
if cls._instance is not None:
|
||||
return cls._instance
|
||||
|
||||
storage_type = os.getenv(
|
||||
"STORAGE_TYPE",
|
||||
).lower()
|
||||
|
||||
if storage_type == "r2":
|
||||
cls._instance = R2Storage()
|
||||
# elif storage_type == "github":
|
||||
# cls._instance = GithubStorage()
|
||||
# elif storage_type == "cnbcool":
|
||||
# cls._instance = CnbCoolStorage()
|
||||
else:
|
||||
raise RuntimeError(
|
||||
f"Unsupported storage type: {storage_type}. "
|
||||
f"Supported types: r2, cnbcool"
|
||||
)
|
||||
|
||||
return cls._instance
|
||||
|
||||
@classmethod
|
||||
def reset(cls):
|
||||
"""重置单例实例(主要用于测试)"""
|
||||
cls._instance = None
|
||||
Reference in New Issue
Block a user