sync: 更新 MinIO §8 — dual S3Client 模式(禁止字符串替换域名)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -249,12 +249,34 @@ NPM 代理主机默认配置会阻断 WebSocket,导致:
|
||||
| `S3_ENDPOINT` | S3Client 内部连接 | `http://localhost:9000` |
|
||||
| `S3_PUBLIC_URL` | 对外暴露的 URL(presigned、封面) | `https://{MINIO_HOST}` |
|
||||
|
||||
### Dual S3Client 模式(⛔ 强制)
|
||||
|
||||
AWS SDK `getSignedUrl()` 生成的 presigned URL 签名包含 `X-Amz-SignedHeaders=host`,
|
||||
即签名绑定了 S3Client 的 endpoint host。**不能用字符串替换域名**(签名会失效返回 403)。
|
||||
|
||||
必须创建两个 S3Client 实例:
|
||||
|
||||
```typescript
|
||||
// 内部 S3Client(worker 下载、上传等)
|
||||
const s3 = new S3Client({ endpoint: "http://localhost:9000", ... });
|
||||
|
||||
// 外网 S3Client(生成外网 presigned URL)
|
||||
const s3Public = new S3Client({ endpoint: "https://minio-xxx.dev.d8d.fun", ... });
|
||||
|
||||
// 内部 presigned URL(worker 用)
|
||||
getDownloadUrl(key) → getSignedUrl(s3, ...) // host=localhost:9000
|
||||
|
||||
// 外网 presigned URL(浏览器/stream 路由用)
|
||||
getPublicDownloadUrl(key) → getSignedUrl(s3Public, ...) // host=minio-xxx.dev.d8d.fun
|
||||
```
|
||||
|
||||
### 代码规则
|
||||
|
||||
- **`getDownloadUrl()`**:返回内部 presigned URL(worker 下载用)
|
||||
- **`getPublicDownloadUrl()`**:返回外网 presigned URL(stream 路由用,替换域名)
|
||||
- **`getDownloadUrl()`**:用内部 `s3`,返回 localhost presigned URL(worker 下载用)
|
||||
- **`getPublicDownloadUrl()`**:用 `s3Public`,返回外网 presigned URL(stream 路由用)
|
||||
- **`uploadFile()` 返回值**:使用 `S3_PUBLIC_URL`(公开访问 URL)
|
||||
- **worker 中的封面 URL**:使用 `S3_PUBLIC_URL`
|
||||
- **禁止字符串替换域名**:`url.replace(localhost, publicUrl)` 会导致 403
|
||||
|
||||
### ⚠️ HTTPS 注意
|
||||
|
||||
|
||||
Reference in New Issue
Block a user