docs: add cloud storage docs
This commit is contained in:
@@ -0,0 +1,259 @@
|
||||
---
|
||||
title: 云存储配置
|
||||
description: 如何配置多平台云存储
|
||||
---
|
||||
|
||||
<DocsLang en="/docs/developer/cloud-storage" zh="/docs/developer/cloud-storag-zh" />
|
||||
|
||||
## 概览
|
||||
|
||||
管理员可以在 `/admin/system` 管理 S3 配置,包括添加、删除和修改云存储的 S3 配置。
|
||||
|
||||
WR.DO 目前支持多种云存储提供商:
|
||||
|
||||
- Cloudflare R2
|
||||
- AWS S3
|
||||
- 腾讯云 COS
|
||||
- 阿里云 OSS
|
||||
- 自定义提供商 (兼容 S3 API)
|
||||
|
||||
> 一个提供商可以添加多个存储桶
|
||||
|
||||
## Cloudflare R2
|
||||
|
||||
### 1. 创建 R2 存储桶
|
||||
|
||||
1. 登录您的 [Cloudflare 仪表板](https://dash.cloudflare.com/)
|
||||
2. 从左侧边栏导航到 **R2 对象存储**
|
||||
3. 点击 **创建存储桶**
|
||||
4. 输入您的存储桶名称(例如:`wrdo`)
|
||||
5. 选择位置(建议选择自动)
|
||||
6. 点击 **创建存储桶**
|
||||
|
||||
### 2. 获取 API 凭证
|
||||
|
||||
1. 在您的 Cloudflare 仪表板中,前往 **我的个人资料** > **API 令牌**
|
||||
2. 点击 **创建令牌**
|
||||
3. 使用 **R2 令牌** 模板或创建自定义令牌,包含:
|
||||
- **权限**: `R2:Edit`
|
||||
- **账户资源**: 包含您的账户
|
||||
- **区域资源**: 包含所有区域(如果需要)
|
||||
4. 点击 **继续摘要**,然后 **创建令牌**
|
||||
5. 复制并保存令牌(这是您的 **访问密钥 ID** 和 **秘密访问密钥**)
|
||||
|
||||
### 3. 获取账户 ID
|
||||
|
||||
1. 在您的 Cloudflare 仪表板中,前往右侧边栏
|
||||
2. 复制您的 **账户 ID**
|
||||
|
||||
### 4. 获取公共 URL
|
||||
|
||||
1. 在您的 Cloudflare 仪表板中,前往 **R2 对象存储** > **存储桶详情** > **公共开发 URL**
|
||||
|
||||
如果您已配置自定义域名,请使用该域名。
|
||||
|
||||
### 5. 配置 CORS
|
||||
|
||||
1. 在您的 Cloudflare 仪表板中,前往 **R2 对象存储** > **存储桶设置** -> **CORS 策略**
|
||||
|
||||
填入以下内容:
|
||||
|
||||
```json
|
||||
[
|
||||
{
|
||||
"AllowedOrigins": [
|
||||
"http://localhost:3000",
|
||||
"https://wr.do" // 替换为您的域名
|
||||
],
|
||||
"AllowedMethods": [
|
||||
"GET",
|
||||
"PUT",
|
||||
"POST",
|
||||
"DELETE",
|
||||
"HEAD"
|
||||
],
|
||||
"AllowedHeaders": [
|
||||
"*"
|
||||
],
|
||||
"ExposeHeaders": [
|
||||
"ETag"
|
||||
],
|
||||
"MaxAgeSeconds": 3600
|
||||
}
|
||||
]
|
||||
```
|
||||
|
||||
### 6. 在 WR.DO 中配置
|
||||
|
||||
访问 `localhost:3000/admin/system`,填写配置表单:
|
||||
|
||||
- **提供渠道**: cloudflare (r2)
|
||||
- **渠道名称**: Cloudflare R2(或任何自定义名称)
|
||||
- **S3 端点**: `https://<账户ID>.r2.cloudflarestorage.com`(替换为您的账户端点)
|
||||
- **访问密钥 ID**: 第 2 步中的 API 令牌
|
||||
- **机密访问密钥**: 第 2 步中的 API 令牌
|
||||
- **启用**: 开启
|
||||
- **存储桶名称**: 您的存储桶名称
|
||||
- **公开域名或自定义域名**: 参考第 4 步
|
||||
- **存储桶区域**: auto
|
||||
- **前缀**: 可选
|
||||
- **公开**: 如果您想要公共访问,请启用
|
||||
|
||||
## 腾讯云 COS
|
||||
|
||||
### 1. 创建 COS 存储桶
|
||||
|
||||
1. 登录 [腾讯云控制台](https://console.cloud.tencent.com/cos)
|
||||
2. 点击 **存储桶列表** > **创建存储桶**
|
||||
3. 输入存储桶名称(例如:`wrdo-1303456836`)
|
||||
4. 选择地域(例如:`ap-chengdu`)
|
||||
5. 配置访问权限
|
||||
6. 点击 **创建**
|
||||
|
||||
### 2. 获取 API 密钥
|
||||
|
||||
1. 前往 [CAM 控制台](https://console.cloud.tencent.com/cam/capi)
|
||||
2. 点击 **新建密钥** 或使用现有密钥
|
||||
3. 保存您的 **SecretId** 和 **SecretKey**
|
||||
|
||||
### 3. CORS 设置
|
||||
|
||||
1. 前往 [COS 控制台](https://console.cloud.tencent.com/cos)
|
||||
2. 点击 **存储桶列表** > **选择存储桶** -> 安全管理 -> 跨域访问 CORS 设置
|
||||
3. 填入下列规则:
|
||||
|
||||

|
||||
|
||||
### 4. 在 WR.DO 中配置
|
||||
|
||||
填写配置表单:
|
||||
|
||||
- **提供渠道**: tencent (cos)
|
||||
- **渠道名称**: 腾讯云 COS(或任何自定义名称)
|
||||
- **S3 端点**: `https://cos.ap-chengdu.myqcloud.com`(替换为您的地域)
|
||||
- **访问密钥 ID**: 您的 SecretId
|
||||
- **机密访问密钥**: 您的 SecretKey
|
||||
- **启用**: 开启
|
||||
- **存储桶名称**: 您的存储桶名称(例如:`wrdo-1303456836`)
|
||||
- **公开域名或自定义域名**: `https://wrdo-1303456836.cos.ap-chengdu.myqcloud.com`(您的存储桶公共 URL)
|
||||
- **存储桶区域**: 您的 COS 地域(例如:`ap-chengdu`)
|
||||
- **前缀**: 可选日期前缀
|
||||
- **公开**: 如果您想要公共访问,请启用
|
||||
|
||||
## 阿里云 OSS
|
||||
|
||||
### 1. 创建 OSS 存储桶
|
||||
|
||||
1. 登录 [阿里云控制台](https://oss.console.aliyun.com/)
|
||||
2. 点击 **创建 Bucket**
|
||||
3. 输入存储桶名称
|
||||
4. 选择地域(例如:`oss-cn-hangzhou`)
|
||||
5. 配置 ACL 和其他设置
|
||||
6. 点击 **确定**
|
||||
|
||||
### 2. 获取 AccessKey
|
||||
|
||||
1. 前往 [RAM 控制台](https://ram.console.aliyun.com/manage/ak)
|
||||
2. 点击 **创建 AccessKey** 或使用现有密钥
|
||||
3. 保存您的 **AccessKeyId** 和 **AccessKeySecret**
|
||||
|
||||
### 3. 在 WR.DO 中配置
|
||||
|
||||
填写配置表单:
|
||||
|
||||
- **提供渠道**: ali (oss)
|
||||
- **渠道名称**: 阿里云 OSS(或任何自定义名称)
|
||||
- **S3 端点**: `https://oss-cn-hangzhou.aliyuncs.com`(替换为您的地域)
|
||||
- **访问密钥 ID**: 您的 AccessKeyId
|
||||
- **机密访问密钥**: 您的 AccessKeySecret
|
||||
- **启用**: 开启
|
||||
- **存储桶名称**: 您的存储桶名称
|
||||
- **公开域名或自定义域名**: `https://your-bucket.oss-cn-hangzhou.aliyuncs.com`(您的存储桶公共 URL)
|
||||
- **存储桶区域**: 您的 OSS 地域(例如:`oss-cn-hangzhou`)
|
||||
- **前缀**: 可选日期前缀
|
||||
- **公开**: 如果您想要公共访问,请启用
|
||||
|
||||
## AWS S3
|
||||
|
||||
### 1. 创建 S3 存储桶
|
||||
|
||||
1. 登录 [AWS 控制台](https://console.aws.amazon.com/s3/)
|
||||
2. 点击 **创建存储桶**
|
||||
3. 输入存储桶名称(全球唯一)
|
||||
4. 选择 AWS 区域
|
||||
5. 根据需要配置存储桶设置
|
||||
6. 点击 **创建存储桶**
|
||||
|
||||
### 2. 创建 IAM 用户
|
||||
|
||||
1. 前往 [IAM 控制台](https://console.aws.amazon.com/iam/)
|
||||
2. 点击 **用户** > **添加用户**
|
||||
3. 输入用户名并选择 **编程访问**
|
||||
4. 附加现有策略或创建具有 S3 权限的自定义策略:
|
||||
```json
|
||||
{
|
||||
"Version": "2012-10-17",
|
||||
"Statement": [
|
||||
{
|
||||
"Effect": "Allow",
|
||||
"Action": [
|
||||
"s3:GetObject",
|
||||
"s3:PutObject",
|
||||
"s3:DeleteObject",
|
||||
"s3:ListBucket"
|
||||
],
|
||||
"Resource": [
|
||||
"arn:aws:s3:::your-bucket-name",
|
||||
"arn:aws:s3:::your-bucket-name/*"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
5. 完成用户创建并保存 **访问密钥 ID** 和 **秘密访问密钥**
|
||||
|
||||
### 3. 在 WR.DO 中配置
|
||||
|
||||
填写配置表单:
|
||||
|
||||
- **提供渠道**: aws (s3)
|
||||
- **渠道名称**: AWS S3(或任何自定义名称)
|
||||
- **S3 端点**: `https://s3.amazonaws.com`(或特定区域端点)
|
||||
- **访问密钥 ID**: 您的 IAM 用户访问密钥 ID
|
||||
- **机密访问密钥**: 您的 IAM 用户秘密访问密钥
|
||||
- **启用**: 开启
|
||||
- **存储桶名称**: 您的 S3 存储桶名称
|
||||
- **公开域名或自定义域名**: 您的存储桶公共 URL 或 CloudFront 分发
|
||||
- **存储桶区域**: 您的 S3 区域(例如:`us-east-1`)
|
||||
- **前缀**: 可选日期前缀
|
||||
- **公开**: 如果您想要公共访问,请启用
|
||||
|
||||
## 通用配置选项
|
||||
|
||||
### 前缀设置
|
||||
- 使用基于日期的前缀(例如:`2025/08/08`)按日期组织文件
|
||||
- 如果您喜欢扁平文件结构,请留空
|
||||
|
||||
### 公共访问
|
||||
- 如果您希望文件可以通过直接 URL 访问,请启用 **公开**
|
||||
- 对于私有文件存储,请禁用
|
||||
|
||||
### 自定义域名
|
||||
- 配置自定义域名以获得更好的品牌体验
|
||||
- 确保为您的域名进行正确的 DNS 配置
|
||||
|
||||
## 故障排除
|
||||
|
||||
### 常见问题
|
||||
|
||||
1. **访问被拒绝**: 检查您的 API 凭证和权限
|
||||
2. **存储桶未找到**: 验证存储桶名称和区域设置
|
||||
3. **CORS 问题**: 如果需要,在您的存储桶中配置 CORS 设置
|
||||
4. **端点错误**: 确保您的提供商端点格式正确
|
||||
|
||||
### 测试配置
|
||||
|
||||
保存配置后,您可以通过以下方式测试:
|
||||
1. 通过管理界面上传测试文件
|
||||
2. 检查文件是否出现在您的云存储桶中
|
||||
3. 验证公共访问(如果启用)是否可以通过文件 URL 访问
|
||||
@@ -0,0 +1,262 @@
|
||||
---
|
||||
title: Cloud Storage
|
||||
description: How to config the cloud storage api
|
||||
---
|
||||
|
||||
<DocsLang en="/docs/developer/cloud-storage" zh="/docs/developer/cloud-storag-zh" />
|
||||
|
||||
## Overview
|
||||
|
||||
Administrators can manage s3 configurations at `/admin/system`,
|
||||
including adding, deleting, and modifying s3 configurations for cloud storage.
|
||||
|
||||
WR.DO now supports multiple cloud storage providers:
|
||||
|
||||
- Cloudflare R2
|
||||
- AWS S3
|
||||
- Tencent COS
|
||||
- Ali OSS
|
||||
- Custom Provider (Support any S3 compatible provider)
|
||||
|
||||
> One provider can configure multiple buckets.
|
||||
|
||||
## Cloudflare R2
|
||||
|
||||
### 1. Create R2 Bucket
|
||||
|
||||
1. Log in to your [Cloudflare dashboard](https://dash.cloudflare.com/)
|
||||
2. Navigate to **R2 Object Storage** from the left sidebar
|
||||
3. Click **Create bucket**
|
||||
4. Enter your bucket name (e.g., `wrdo`)
|
||||
5. Select the location (auto is recommended)
|
||||
6. Click **Create bucket**
|
||||
|
||||
### 2. Get API Credentials
|
||||
|
||||
1. In your Cloudflare dashboard, go to **My Profile** > **API Tokens**
|
||||
2. Click **Create Token**
|
||||
3. Use the **R2 Token** template or create a custom token with:
|
||||
- **Permissions**: `R2:Edit`
|
||||
- **Account Resources**: Include your account
|
||||
- **Zone Resources**: Include all zones (if needed)
|
||||
4. Click **Continue to summary** and then **Create Token**
|
||||
5. Copy and save the token (this is your **Access Key ID** and **Secret Access Key**)
|
||||
|
||||
### 3. Get Account ID
|
||||
|
||||
1. In your Cloudflare dashboard, go to the right sidebar
|
||||
2. Copy your **Account ID**
|
||||
|
||||
### 4. Get Public URL
|
||||
|
||||
1. In your Cloudflare dashboard, go to **R2 Object Storage** > **Bucket Details** > **Public Development URL**
|
||||
|
||||
if you have configured a custom domain, use that instead.
|
||||
|
||||
### 5. Config CORS
|
||||
|
||||
1. In your Cloudflare dashboard, go to **R2 Object Storage** > **Bucket Settings** -> **CORS Policy**
|
||||
|
||||
Fill in the following:
|
||||
|
||||
```json
|
||||
[
|
||||
{
|
||||
"AllowedOrigins": [
|
||||
"http://localhost:3000",
|
||||
"https://wr.do" // Replace with your domain
|
||||
],
|
||||
"AllowedMethods": [
|
||||
"GET",
|
||||
"PUT",
|
||||
"POST",
|
||||
"DELETE",
|
||||
"HEAD"
|
||||
],
|
||||
"AllowedHeaders": [
|
||||
"*"
|
||||
],
|
||||
"ExposeHeaders": [
|
||||
"ETag"
|
||||
],
|
||||
"MaxAgeSeconds": 3600
|
||||
}
|
||||
]
|
||||
```
|
||||
|
||||
### 6. Configuration in WR.DO
|
||||
|
||||
Follow `localhost:3000/admin/system`, fill in the configuration form with:
|
||||
|
||||
- **Provider**: cloudflare (r2)
|
||||
- **Channel Name**: Cloudflare R2 (or any custom name)
|
||||
- **S3 Endpoint**: `https://<account_id>.r2.cloudflarestorage.com` (replace with your account's endpoint)
|
||||
- **Access Key ID**: Your API token from step 2
|
||||
- **Secret Access Key**: Your API token from step 2
|
||||
- **Enable**: Toggle ON
|
||||
- **Bucket Name**: Your bucket name
|
||||
- **Public Domain**: follow step 4
|
||||
- **Storage Region**: auto
|
||||
- **Prefix**: Optional
|
||||
- **Public**: Enable if you want public access
|
||||
|
||||
|
||||
## Tencent COS
|
||||
|
||||
### 1. Create COS Bucket
|
||||
|
||||
1. Log in to [Tencent Cloud Console](https://console.cloud.tencent.com/cos)
|
||||
2. Click **Bucket List** > **Create Bucket**
|
||||
3. Enter bucket name (e.g., `wrdo-1303456836`)
|
||||
4. Select region (e.g., `ap-chengdu`)
|
||||
5. Configure access permissions
|
||||
6. Click **Create**
|
||||
|
||||
### 2. Get API Keys
|
||||
|
||||
1. Go to [CAM Console](https://console.cloud.tencent.com/cam/capi)
|
||||
2. Click **Create Key** or use existing keys
|
||||
3. Save your **SecretId** and **SecretKey**
|
||||
|
||||
### 3. CORS 设置
|
||||
|
||||
1. Follow [COS Console](https://console.cloud.tencent.com/cos)
|
||||
2. Click **Bucket List** > **Select a Bucket** -> 安全管理 -> 跨域访问 CORS 设置
|
||||
3. Fill in the following rules:
|
||||
|
||||

|
||||
|
||||
### 4. Configuration in WR.DO
|
||||
|
||||
Fill in the configuration form with:
|
||||
|
||||
- **Provider**: tencent (cos)
|
||||
- **Channel Name**: 腾讯云 COS (or any custom name)
|
||||
- **S3 Endpoint**: `https://cos.ap-chengdu.myqcloud.com` (replace with your region)
|
||||
- **Access Key ID**: Your SecretId
|
||||
- **Secret Access Key**: Your SecretKey
|
||||
- **Enable**: Toggle ON
|
||||
- **Bucket Name**: Your bucket name (e.g., `wrdo-1303456836`)
|
||||
- **Public Domain**: `https://wrdo-1303456836.cos.ap-chengdu.myqcloud.com` (your bucket's public URL)
|
||||
- **Storage Region**: Your COS region (e.g., `ap-chengdu`)
|
||||
- **Prefix**: Optional date prefix
|
||||
- **Public**: Enable if you want public access
|
||||
|
||||
## Ali OSS
|
||||
|
||||
### 1. Create OSS Bucket
|
||||
|
||||
1. Log in to [Alibaba Cloud Console](https://oss.console.aliyun.com/)
|
||||
2. Click **Create Bucket**
|
||||
3. Enter bucket name
|
||||
4. Select region (e.g., `oss-cn-hangzhou`)
|
||||
5. Configure ACL and other settings
|
||||
6. Click **OK**
|
||||
|
||||
### 2. Get AccessKey
|
||||
|
||||
1. Go to [RAM Console](https://ram.console.aliyun.com/manage/ak)
|
||||
2. Click **Create AccessKey** or use existing keys
|
||||
3. Save your **AccessKeyId** and **AccessKeySecret**
|
||||
|
||||
### 3. Configuration in WR.DO
|
||||
|
||||
Fill in the configuration form with:
|
||||
|
||||
- **Provider**: ali (oss)
|
||||
- **Channel Name**: 阿里云 OSS (or any custom name)
|
||||
- **S3 Endpoint**: `https://oss-cn-hangzhou.aliyuncs.com` (replace with your region)
|
||||
- **Access Key ID**: Your AccessKeyId
|
||||
- **Secret Access Key**: Your AccessKeySecret
|
||||
- **Enable**: Toggle ON
|
||||
- **Bucket Name**: Your bucket name
|
||||
- **Public Domain**: `https://your-bucket.oss-cn-hangzhou.aliyuncs.com` (your bucket's public URL)
|
||||
- **Storage Region**: Your OSS region (e.g., `oss-cn-hangzhou`)
|
||||
- **Prefix**: Optional date prefix
|
||||
- **Public**: Enable if you want public access
|
||||
|
||||
## AWS S3
|
||||
|
||||
### 1. Create S3 Bucket
|
||||
|
||||
1. Log in to [AWS Console](https://console.aws.amazon.com/s3/)
|
||||
2. Click **Create bucket**
|
||||
3. Enter bucket name (globally unique)
|
||||
4. Select AWS region
|
||||
5. Configure bucket settings as needed
|
||||
6. Click **Create bucket**
|
||||
|
||||
### 2. Create IAM User
|
||||
|
||||
1. Go to [IAM Console](https://console.aws.amazon.com/iam/)
|
||||
2. Click **Users** > **Add user**
|
||||
3. Enter username and select **Programmatic access**
|
||||
4. Attach existing policies or create custom policy with S3 permissions:
|
||||
```json
|
||||
{
|
||||
"Version": "2012-10-17",
|
||||
"Statement": [
|
||||
{
|
||||
"Effect": "Allow",
|
||||
"Action": [
|
||||
"s3:GetObject",
|
||||
"s3:PutObject",
|
||||
"s3:DeleteObject",
|
||||
"s3:ListBucket"
|
||||
],
|
||||
"Resource": [
|
||||
"arn:aws:s3:::your-bucket-name",
|
||||
"arn:aws:s3:::your-bucket-name/*"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
5. Complete user creation and save **Access Key ID** and **Secret Access Key**
|
||||
|
||||
### 3. Configuration in WR.DO
|
||||
|
||||
Fill in the configuration form with:
|
||||
|
||||
- **Provider**: aws (s3)
|
||||
- **Channel Name**: AWS S3 (or any custom name)
|
||||
- **S3 Endpoint**: `https://s3.amazonaws.com` (or region-specific endpoint)
|
||||
- **Access Key ID**: Your IAM user's Access Key ID
|
||||
- **Secret Access Key**: Your IAM user's Secret Access Key
|
||||
- **Enable**: Toggle ON
|
||||
- **Bucket Name**: Your S3 bucket name
|
||||
- **Public Domain**: Your bucket's public URL or CloudFront distribution
|
||||
- **Storage Region**: Your S3 region (e.g., `us-east-1`)
|
||||
- **Prefix**: Optional date prefix
|
||||
- **Public**: Enable if you want public access
|
||||
|
||||
|
||||
## Common Configuration Options
|
||||
|
||||
### Prefix Settings
|
||||
- Use date-based prefixes (e.g., `2025/08/08`) to organize files by date
|
||||
- Leave empty if you prefer flat file structure
|
||||
|
||||
### Public Access
|
||||
- Enable **Public** if you want files to be accessible via direct URLs
|
||||
- Disable for private file storage
|
||||
|
||||
### Custom Domains
|
||||
- Configure custom domains for better branding
|
||||
- Ensure proper DNS configuration for your domain
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Common Issues
|
||||
|
||||
1. **Access Denied**: Check your API credentials and permissions
|
||||
2. **Bucket Not Found**: Verify bucket name and region settings
|
||||
3. **CORS Issues**: Configure CORS settings in your bucket if needed
|
||||
4. **Endpoint Errors**: Ensure correct endpoint format for your provider
|
||||
|
||||
### Testing Configuration
|
||||
|
||||
After saving your configuration, you can test it by:
|
||||
1. Uploading a test file through the admin interface
|
||||
2. Checking if the file appears in your cloud storage bucket
|
||||
3. Verifying public access (if enabled) by accessing the file URL
|
||||
@@ -1,10 +0,0 @@
|
||||
---
|
||||
title: S3 Configs
|
||||
description: How to config the s3 api.
|
||||
---
|
||||
|
||||
## Overview
|
||||
|
||||
Administrators can manage s3 configurations at `/admin/system`, including adding, deleting, and modifying s3 configurations.
|
||||
|
||||
## Cloudflare R2
|
||||
+1
-2
@@ -158,9 +158,8 @@ export async function getUserFiles(options: QueryUserFileOptions = {}) {
|
||||
}),
|
||||
prisma.userFile.count({ where }),
|
||||
prisma.userFile.aggregate({
|
||||
// All provider's file size
|
||||
where: {
|
||||
userId,
|
||||
...(userId && { userId }),
|
||||
status: 1,
|
||||
},
|
||||
_sum: { size: true },
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 96 KiB |
+1
-1
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user