Minimal MVP resource management system - file upload, directory listing, HTTP API
Project description
Resource Manager
极简资源管理系统 (MVP) - 提供文件上传、目录创建和文件树查看功能。
功能
- 初始化仓库: 创建
index.json索引文件 - 上传资源: 支持上传文件和文件夹到仓库
- 查看文件树: 以树状结构显示仓库内容
- 创建目录: 创建新的文件夹
安装
cd resource-mgr
pip install -e .
快速开始
CLI 命令
# 初始化仓库
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
程序化使用
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
# 启动 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)
叶子节点模式
叶子节点模式限制文件只能在最底层目录(不包含子目录的目录)中创建:
# 初始化为叶子节点模式
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 # ❌
测试
# 安装开发依赖
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file resource_mgr-1.0.0-py3-none-any.whl.
File metadata
- Download URL: resource_mgr-1.0.0-py3-none-any.whl
- Upload date:
- Size: 16.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
15481ce02e3fad9ff722ec5e27efe153463ca16fe5f9f20ca1b6486e72e4709a
|
|
| MD5 |
48c8c13a32d0b8edceec6cf2859a07d4
|
|
| BLAKE2b-256 |
a507d12bcd34f124eddf64d7fd35a7dd95aca261fb3b02a73531dcbf4480fe73
|