Metadata-Version: 2.4
Name: resource-mgr
Version: 1.0.0
Summary: Minimal MVP resource management system - file upload, directory listing, HTTP API
Requires-Python: >=3.10
Requires-Dist: fastapi>=0.115.0
Requires-Dist: pydantic>=2.0.0
Requires-Dist: python-multipart>=0.0.9
Requires-Dist: typer>=0.12.0
Requires-Dist: uvicorn>=0.30.0
Provides-Extra: dev
Requires-Dist: pytest-subprocess>=0.1.0; extra == 'dev'
Requires-Dist: pytest>=7.0.0; extra == 'dev'
Requires-Dist: requests>=2.31.0; extra == 'dev'
Requires-Dist: ruff>=0.7.0; extra == 'dev'
Description-Content-Type: text/markdown

# Resource Manager

极简资源管理系统 (MVP) - 提供文件上传、目录创建和文件树查看功能。

## 功能

- **初始化仓库**: 创建 `index.json` 索引文件
- **上传资源**: 支持上传文件和文件夹到仓库
- **查看文件树**: 以树状结构显示仓库内容
- **创建目录**: 创建新的文件夹

## 安装

```bash
cd resource-mgr
pip install -e .
```

## 快速开始

### CLI 命令

```bash
# 初始化仓库
resourcemgr init --root ./my_repo

# 初始化为叶子节点模式（文件只能在最底层目录）
resourcemgr init --root ./my_repo --leaf-only

# 上传文件
resourcemgr upload /path/to/photo.jpg --root ./my_repo

# 上传到指定路径
resourcemgr upload /path/to/document.pdf --path "docs/report.pdf" --root ./my_repo

# 上传文件夹
resourcemgr upload /path/to/my_folder --path "projects" --root ./my_repo

# 带标签上传
resourcemgr upload /path/to/file.txt --tags "重要,文档" --root ./my_repo

# 查看文件树
resourcemgr list --root ./my_repo

# JSON 格式输出
resourcemgr list --root ./my_repo --json
```

### 程序化使用

```python
from resource_mgr import create_repository

# 创建仓库
repo = create_repository("./my_repo")

# 初始化（可选：设置叶子节点模式）
repo.ensure_index(allow_files_in_non_leaf=False)

# 上传文件
resource = repo.upload_resource(
    source_path="/path/to/file.jpg",
    target_path="images/photo.jpg",
    tags=["照片", "风景"],
)

# 创建目录
repo.create_directory("docs/2024")

# 获取文件树
tree = repo.list_tree()
print(tree)
```

### HTTP API

```bash
# 启动 API 服务
python -m resource_mgr.api --root ./my_repo --port 8000
```

访问 http://localhost:8000 查看测试页面。

**API 端点:**

| 方法 | 路径 | 说明 |
|------|------|------|
| `POST` | `/api/v1/init` | 初始化仓库 |
| `GET` | `/api/v1/resources/tree` | 获取文件树 |
| `POST` | `/api/v1/resources/upload` | 上传文件（文件系统路径）|
| `POST` | `/api/v1/resources/upload/browser` | 上传文件（浏览器表单）|
| `POST` | `/api/v1/directory` | 创建目录 |

### Web 界面

启动 API 服务后，访问 http://localhost:8000/static/index.html 使用 Web 界面：
- 浏览文件树（交互式展开/折叠）
- 上传文件
- 创建目录

## list 输出示例

```
my_repo/
├── docs
│   └── 2024
│       └── guide.pdf (1024000 bytes)
├── images
│   ├── photo1.jpg (512000 bytes)
│   └── photo2.jpg (480000 bytes)
└── readme.txt (100 bytes)
```

## 叶子节点模式

叶子节点模式限制文件只能在最底层目录（不包含子目录的目录）中创建：

```bash
# 初始化为叶子节点模式
resourcemgr init --root ./my_repo --leaf-only

# 允许：文件在叶子目录
resourcemgr upload photo.jpg --path "images/2024/photo.jpg" --root ./my_repo  # ✅

# 不允许：文件在非叶子目录（包含子目录）
resourcemgr upload photo.jpg --path "images/photo.jpg" --root ./my_repo  # ❌
```

## 测试

```bash
# 安装开发依赖
pip install -e ".[dev]"

# 运行测试
pytest tests/ -v
```

## 目录结构

```
resource-mgr/
├── src/resource_mgr/
│   ├── __init__.py      # 导出 create_repository
│   ├── models.py        # 数据模型
│   ├── storage.py       # 存储层
│   ├── repo.py          # 仓储层
│   ├── cli.py           # CLI 命令
│   └── api.py           # HTTP API
├── static/
│   └── index.html       # Web 测试界面
├── tests/
│   ├── test_repo.py     # 单元测试
│   └── test_e2e.py      # E2E 测试
├── docs/
│   └── 功能文档.md       # 详细功能文档
└── pyproject.toml       # 项目配置
```

## License

MIT
