feat: add pure Python COS upload and improve login detection

- feat(cos): add cos_upload.py for direct file upload without browser
  - implements COS V1 signature algorithm with temporary credentials
  - upload_image() pipeline: get_upload_info → sign → PUT to COS
- feat(api): auto-load cookies from file when cookies arg is omitted
  - both Hunyuan3DAPI and Hunyuan3DAPIComplete now fall back to
    ~/.config/hunyuan3dweb/cookies.txt automatically
- fix(login): strengthen login-state detection using both URL and DOM
  - checks "login" not in page.url AND no login button on page
- docs: update README / README_CN with COS upload examples

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Claude
2026-05-27 00:47:11 +08:00
parent 734d53dafb
commit bf4e1e5755
6 changed files with 206 additions and 12 deletions

View File

@@ -87,7 +87,7 @@ if result["status"] == "success":
### 2. 图生3D本地文件
本地图片文件通过浏览器自动化工具上传。纯 API 客户端无法直接上传图片,因为腾讯 COS 临时凭证需要浏览器端解密
本地图片文件通过浏览器自动化工具上传,也可使用纯 Python 的 COS 上传模块先拿到 `resourceUrl` 再走 API
```bash
hunyuan3dweb-generate /path/to/image.png wait
@@ -102,6 +102,18 @@ result = generate_3d("/path/to/image.png", wait_for_complete=True)
print(f"模型地址: {result.get('modelUrl')}")
```
或通过纯 Python 上传:
```python
from hunyuan3dweb.cos_upload import upload_image
from hunyuan3dweb import Hunyuan3DAPIComplete
resource_url = upload_image("/path/to/image.png")
api = Hunyuan3DAPIComplete()
result = api.generate_from_image(resource_url, title="我的模型")
```
### 3. 图生3DAPI已有 resourceUrl
如果你已经有 `resourceUrl`(例如之前通过浏览器上传过),可直接调用 API
@@ -283,6 +295,7 @@ hunyuan3dweb-sniffer
| `hunyuan3dweb/api.py` | 基础 API 客户端图生3D、文生3D |
| `hunyuan3dweb/api_complete.py` | 完整 API 客户端(所有生成模式) |
| `hunyuan3dweb/sign.py` | 腾讯混元3D 签名算法 |
| `hunyuan3dweb/cos_upload.py` | 纯 Python COS 上传工具 |
| `hunyuan3dweb/config.py` | 用户配置路径管理 |
| `hunyuan3dweb/cli.py` | CLI 入口 |
| `hunyuan3dweb/browser/login.py` | 浏览器登录工具 |