更新前后端代码

This commit is contained in:
2026-08-23 00:48:10 +08:00
parent 1b5468995f
commit 5c1313e4f6
74 changed files with 9995 additions and 306 deletions
+128 -8
View File
@@ -397,6 +397,28 @@ CREATE INDEX idx_system_logs_created ON system_logs(created_at);
## API设计
### 基础信息
- **API基础地址**:
- 开发环境:`http://localhost:8100/api/v1`
- 生产环境:`https://file.yunzer.cn/api/v1`
- **响应格式**:`{"code": 0, "message": "ok", "data": ...}`
- **认证方式**:JWT Bearer Token 或 API Key 签名
- **分页格式**:`{"list": [], "total": 0, "page": 1, "page_size": 20}`
### 域名配置说明
系统支持通过配置文件设置域名,用于生成完整的URL:
```yaml
# config.yaml
server:
domain: https://file.yunzer.cn # 生产环境域名
```
生成的完整URL示例:
- 文件下载:`https://file.yunzer.cn/api/v1/files/1/download`
- 临时链接:`https://file.yunzer.cn/api/v1/files/temp/abc123`
- 站点状态:`https://file.yunzer.cn/api/v1/status`
### 认证相关
- `POST /api/v1/auth/register` - 用户注册
- `POST /api/v1/auth/login` - 用户登录
@@ -501,8 +523,22 @@ CREATE INDEX idx_system_logs_created ON system_logs(created_at);
### 环境要求
- Go 1.21+
- SQLite 3
- Node.js 16+
- npm 或 yarn
### 安装和运行
### 域名配置
#### 开发环境
- 后端服务地址:`http://localhost:8100`
- 前端服务地址:`http://localhost:5173`
- API基础地址:`http://localhost:8100/api/v1`
#### 生产环境
- 域名:`https://file.yunzer.cn`
- API基础地址:`https://file.yunzer.cn/api/v1`
- 建议配置Nginx反向代理,将80/8080端口重定向到443端口
### 后端安装和运行
```bash
# 进入Go后端目录
cd go
@@ -514,12 +550,26 @@ go mod tidy
go run main.go
```
### 前端安装和运行
```bash
# 进入前端目录
cd backend
# 安装依赖
npm install
# 启动开发服务器
npm run dev
```
### 配置文件
#### 后端配置 (go/config.yaml)
```yaml
# config.yaml
server:
port: 8080
mode: debug # debug/release
port: 8100
mode: debug
domain: https://file.yunzer.cn # 生产环境域名
database:
driver: sqlite
@@ -527,17 +577,87 @@ database:
storage:
root: ./storage/files
max_size: 100MB # 单文件最大限制
backups: ./storage/backups
admin:
username: admin
password: admin123 # 首次运行后请修改
email: admin@example.com
role: super_admin # 默认角色
role: super_admin
jwt:
secret: your-secret-key # 请修改为随机密钥
expire: 24h # Token过期时间
secret: please-change-this-secret-key # 生产环境请修改为随机密钥
expire: 24h
log:
level: info
dir: ./storage/logs
max_days: 7
```
#### 前端配置
##### 开发环境 (.env.development)
```
VITE_API_BASE_URL=http://localhost:8100/api/v1
VITE_APP_TITLE=云泽文件存储云平台 (开发)
VITE_APP_ENV=development
```
##### 生产环境 (.env.production)
```
VITE_API_BASE_URL=https://file.yunzer.cn/api/v1
VITE_APP_TITLE=云泽文件存储云平台
VITE_APP_ENV=production
```
### Nginx配置示例(生产环境)
```nginx
server {
listen 80;
server_name file.yunzer.cn;
# 重定向到HTTPS
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl http2;
server_name file.yunzer.cn;
# SSL证书配置
ssl_certificate /path/to/your/certificate.crt;
ssl_certificate_key /path/to/your/private.key;
ssl_protocols TLSv1.2 TLSv1.3;
# 前端静态文件
location / {
root /path/to/your/frontend/dist;
try_files $uri $uri/ /index.html;
}
# API代理
location /api/ {
proxy_pass http://127.0.0.1:8100;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
# 超时设置
proxy_connect_timeout 60s;
proxy_read_timeout 60s;
proxy_send_timeout 60s;
}
# 文件上传大小限制
client_max_body_size 100M;
# 静态资源缓存
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
expires 1y;
add_header Cache-Control "public, immutable";
}
}
```
## 注意事项