befly-tpl 3.3.4 → 3.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env.development +0 -11
- package/SYSTEMD_DEPLOY.md +468 -0
- package/apis/user/login.ts +1 -3
- package/befly.service +93 -0
- package/package.json +6 -11
- package/main.ts +0 -9
- package/pm2.config.cjs +0 -85
- package/types/api.ts +0 -128
- package/types/index.ts +0 -6
- package/types/models.example.ts +0 -267
- package/types/models.ts +0 -67
package/.env.development
CHANGED
|
@@ -70,14 +70,3 @@ MAIL_ADDRESS='demo@qq.com'
|
|
|
70
70
|
LOCAL_DIR="/wwwroot/static2/"
|
|
71
71
|
# 微信配置
|
|
72
72
|
PAY_NOTIFY_URL=""
|
|
73
|
-
|
|
74
|
-
# --- 同步脚本开关(仅影响表结构同步) ---
|
|
75
|
-
# 仅打印计划,不执行(0/1)
|
|
76
|
-
# 合并每表多项 DDL(0/1)
|
|
77
|
-
SYNC_MERGE_ALTER=1
|
|
78
|
-
# 索引操作尽量在线(0/1)
|
|
79
|
-
SYNC_ONLINE_INDEX=0
|
|
80
|
-
# 禁止长度收缩(0/1)
|
|
81
|
-
SYNC_DISALLOW_SHRINK=1
|
|
82
|
-
# 允许类型变更(0/1)
|
|
83
|
-
SYNC_ALLOW_TYPE_CHANGE=0
|
|
@@ -0,0 +1,468 @@
|
|
|
1
|
+
# Befly Systemd 部署指南
|
|
2
|
+
|
|
3
|
+
## 快速开始
|
|
4
|
+
|
|
5
|
+
### 1. 安装 Bun
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
# Linux/macOS
|
|
9
|
+
curl -fsSL https://bun.sh/install | bash
|
|
10
|
+
|
|
11
|
+
# 验证安装
|
|
12
|
+
bun --version
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
### 2. 部署项目
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
# 创建项目目录
|
|
19
|
+
sudo mkdir -p /var/www/befly
|
|
20
|
+
sudo chown -R www-data:www-data /var/www/befly
|
|
21
|
+
|
|
22
|
+
# 上传项目文件到服务器
|
|
23
|
+
# 方式1:使用 git
|
|
24
|
+
cd /var/www/befly
|
|
25
|
+
git clone <your-repo-url> .
|
|
26
|
+
|
|
27
|
+
# 方式2:使用 rsync
|
|
28
|
+
rsync -avz --exclude 'node_modules' ./ user@server:/var/www/befly/
|
|
29
|
+
|
|
30
|
+
# 安装依赖
|
|
31
|
+
cd /var/www/befly
|
|
32
|
+
bun install --production
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### 3. 配置环境变量
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
# 复制环境变量模板
|
|
39
|
+
cp .env.development .env.production
|
|
40
|
+
|
|
41
|
+
# 编辑生产环境配置
|
|
42
|
+
nano .env.production
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### 4. 配置 systemd 服务
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
# 复制 service 文件
|
|
49
|
+
sudo cp befly.service /etc/systemd/system/
|
|
50
|
+
|
|
51
|
+
# 编辑配置(修改路径、用户等)
|
|
52
|
+
sudo nano /etc/systemd/system/befly.service
|
|
53
|
+
|
|
54
|
+
# 需要修改的配置项:
|
|
55
|
+
# - WorkingDirectory: 项目实际路径
|
|
56
|
+
# - User/Group: 运行用户
|
|
57
|
+
# - ExecStart: bun 的实际路径(使用 which bun 查看)
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### 5. 启动服务
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
# 重载 systemd 配置
|
|
64
|
+
sudo systemctl daemon-reload
|
|
65
|
+
|
|
66
|
+
# 启动服务
|
|
67
|
+
sudo systemctl start befly
|
|
68
|
+
|
|
69
|
+
# 查看状态
|
|
70
|
+
sudo systemctl status befly
|
|
71
|
+
|
|
72
|
+
# 设置开机自启
|
|
73
|
+
sudo systemctl enable befly
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## 常用命令
|
|
77
|
+
|
|
78
|
+
### 服务管理
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
# 启动服务
|
|
82
|
+
sudo systemctl start befly
|
|
83
|
+
|
|
84
|
+
# 停止服务
|
|
85
|
+
sudo systemctl stop befly
|
|
86
|
+
|
|
87
|
+
# 重启服务
|
|
88
|
+
sudo systemctl restart befly
|
|
89
|
+
|
|
90
|
+
# 重载配置(不重启服务)
|
|
91
|
+
sudo systemctl reload befly
|
|
92
|
+
|
|
93
|
+
# 查看服务状态
|
|
94
|
+
sudo systemctl status befly
|
|
95
|
+
|
|
96
|
+
# 查看服务是否开机自启
|
|
97
|
+
sudo systemctl is-enabled befly
|
|
98
|
+
|
|
99
|
+
# 启用开机自启
|
|
100
|
+
sudo systemctl enable befly
|
|
101
|
+
|
|
102
|
+
# 禁用开机自启
|
|
103
|
+
sudo systemctl disable befly
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### 日志查看
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
# 实时查看日志
|
|
110
|
+
sudo journalctl -u befly -f
|
|
111
|
+
|
|
112
|
+
# 查看最近100行日志
|
|
113
|
+
sudo journalctl -u befly -n 100
|
|
114
|
+
|
|
115
|
+
# 查看今天的日志
|
|
116
|
+
sudo journalctl -u befly --since today
|
|
117
|
+
|
|
118
|
+
# 查看指定时间的日志
|
|
119
|
+
sudo journalctl -u befly --since "2025-01-01 00:00:00" --until "2025-01-01 23:59:59"
|
|
120
|
+
|
|
121
|
+
# 查看错误日志
|
|
122
|
+
sudo journalctl -u befly -p err
|
|
123
|
+
|
|
124
|
+
# 查看完整日志(包括被截断的内容)
|
|
125
|
+
sudo journalctl -u befly --no-pager
|
|
126
|
+
|
|
127
|
+
# 导出日志
|
|
128
|
+
sudo journalctl -u befly > befly.log
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### 配置修改后重载
|
|
132
|
+
|
|
133
|
+
```bash
|
|
134
|
+
# 修改 service 文件后
|
|
135
|
+
sudo systemctl daemon-reload
|
|
136
|
+
sudo systemctl restart befly
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
## 配置说明
|
|
140
|
+
|
|
141
|
+
### 集群模式选择
|
|
142
|
+
|
|
143
|
+
```ini
|
|
144
|
+
# 选项1:单进程模式(适合小型应用)
|
|
145
|
+
ExecStart=/usr/local/bin/bun run befly start
|
|
146
|
+
|
|
147
|
+
# 选项2:自动集群模式(推荐,使用所有CPU核心)
|
|
148
|
+
ExecStart=/usr/local/bin/bun run befly start --cluster max
|
|
149
|
+
|
|
150
|
+
# 选项3:指定进程数(如4个进程)
|
|
151
|
+
ExecStart=/usr/local/bin/bun run befly start --cluster 4
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
### 用户和权限
|
|
155
|
+
|
|
156
|
+
```bash
|
|
157
|
+
# 创建专用用户(推荐)
|
|
158
|
+
sudo useradd -r -s /bin/false befly
|
|
159
|
+
|
|
160
|
+
# 设置目录权限
|
|
161
|
+
sudo chown -R befly:befly /var/www/befly
|
|
162
|
+
|
|
163
|
+
# 修改 service 文件
|
|
164
|
+
User=befly
|
|
165
|
+
Group=befly
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
### 资源限制调整
|
|
169
|
+
|
|
170
|
+
```ini
|
|
171
|
+
# 根据服务器配置调整
|
|
172
|
+
MemoryMax=4G # 4个Worker进程,每个约1G
|
|
173
|
+
MemoryHigh=3G # 内存高水位警告
|
|
174
|
+
LimitNOFILE=65536 # 高并发场景增加
|
|
175
|
+
CPUQuota=200% # 限制最多使用2个CPU核心
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### 环境变量配置
|
|
179
|
+
|
|
180
|
+
```ini
|
|
181
|
+
# 在 service 文件中添加
|
|
182
|
+
Environment="NODE_ENV=production"
|
|
183
|
+
Environment="APP_PORT=3000"
|
|
184
|
+
Environment="APP_HOST=0.0.0.0"
|
|
185
|
+
Environment="DATABASE_URL=postgresql://..."
|
|
186
|
+
Environment="REDIS_URL=redis://..."
|
|
187
|
+
|
|
188
|
+
# 或使用环境文件
|
|
189
|
+
EnvironmentFile=/var/www/befly/.env.production
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
## 反向代理配置
|
|
193
|
+
|
|
194
|
+
### Nginx 配置示例
|
|
195
|
+
|
|
196
|
+
```nginx
|
|
197
|
+
upstream befly_cluster {
|
|
198
|
+
# 集群模式下配置多个端口
|
|
199
|
+
server 127.0.0.1:3000;
|
|
200
|
+
server 127.0.0.1:3001;
|
|
201
|
+
server 127.0.0.1:3002;
|
|
202
|
+
server 127.0.0.1:3003;
|
|
203
|
+
|
|
204
|
+
# 负载均衡策略
|
|
205
|
+
least_conn; # 最少连接
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
server {
|
|
209
|
+
listen 80;
|
|
210
|
+
server_name yourdomain.com;
|
|
211
|
+
|
|
212
|
+
# HTTPS 配置(推荐)
|
|
213
|
+
# listen 443 ssl http2;
|
|
214
|
+
# ssl_certificate /path/to/cert.pem;
|
|
215
|
+
# ssl_certificate_key /path/to/key.pem;
|
|
216
|
+
|
|
217
|
+
location / {
|
|
218
|
+
proxy_pass http://befly_cluster;
|
|
219
|
+
proxy_http_version 1.1;
|
|
220
|
+
|
|
221
|
+
# WebSocket 支持
|
|
222
|
+
proxy_set_header Upgrade $http_upgrade;
|
|
223
|
+
proxy_set_header Connection "upgrade";
|
|
224
|
+
|
|
225
|
+
# 传递客户端信息
|
|
226
|
+
proxy_set_header Host $host;
|
|
227
|
+
proxy_set_header X-Real-IP $remote_addr;
|
|
228
|
+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
229
|
+
proxy_set_header X-Forwarded-Proto $scheme;
|
|
230
|
+
|
|
231
|
+
# 超时设置
|
|
232
|
+
proxy_connect_timeout 60s;
|
|
233
|
+
proxy_send_timeout 60s;
|
|
234
|
+
proxy_read_timeout 60s;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
# 静态文件(如果有)
|
|
238
|
+
location /static/ {
|
|
239
|
+
root /var/www/befly/public;
|
|
240
|
+
expires 30d;
|
|
241
|
+
add_header Cache-Control "public, immutable";
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
### Caddy 配置示例
|
|
247
|
+
|
|
248
|
+
```caddyfile
|
|
249
|
+
yourdomain.com {
|
|
250
|
+
reverse_proxy localhost:3000 localhost:3001 localhost:3002 localhost:3003 {
|
|
251
|
+
lb_policy least_conn
|
|
252
|
+
health_uri /health
|
|
253
|
+
health_interval 10s
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
## 监控和告警
|
|
259
|
+
|
|
260
|
+
### 基础监控脚本
|
|
261
|
+
|
|
262
|
+
```bash
|
|
263
|
+
#!/bin/bash
|
|
264
|
+
# 保存为 /usr/local/bin/befly-monitor.sh
|
|
265
|
+
|
|
266
|
+
SERVICE="befly"
|
|
267
|
+
EMAIL="admin@example.com"
|
|
268
|
+
|
|
269
|
+
# 检查服务状态
|
|
270
|
+
if ! systemctl is-active --quiet $SERVICE; then
|
|
271
|
+
echo "Service $SERVICE is down! Attempting restart..." | mail -s "Alert: Befly Service Down" $EMAIL
|
|
272
|
+
systemctl restart $SERVICE
|
|
273
|
+
fi
|
|
274
|
+
|
|
275
|
+
# 检查内存使用
|
|
276
|
+
MEMORY=$(systemctl show $SERVICE -p MemoryCurrent --value)
|
|
277
|
+
MEMORY_MB=$((MEMORY / 1024 / 1024))
|
|
278
|
+
if [ $MEMORY_MB -gt 3500 ]; then
|
|
279
|
+
echo "Service $SERVICE using ${MEMORY_MB}MB memory (high)" | mail -s "Warning: High Memory Usage" $EMAIL
|
|
280
|
+
fi
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
### 定时监控(crontab)
|
|
284
|
+
|
|
285
|
+
```bash
|
|
286
|
+
# 编辑 crontab
|
|
287
|
+
sudo crontab -e
|
|
288
|
+
|
|
289
|
+
# 每5分钟检查一次
|
|
290
|
+
*/5 * * * * /usr/local/bin/befly-monitor.sh
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
## 故障排查
|
|
294
|
+
|
|
295
|
+
### 服务启动失败
|
|
296
|
+
|
|
297
|
+
```bash
|
|
298
|
+
# 查看详细错误信息
|
|
299
|
+
sudo systemctl status befly -l
|
|
300
|
+
|
|
301
|
+
# 查看完整日志
|
|
302
|
+
sudo journalctl -u befly -n 100 --no-pager
|
|
303
|
+
|
|
304
|
+
# 检查配置文件语法
|
|
305
|
+
sudo systemd-analyze verify /etc/systemd/system/befly.service
|
|
306
|
+
|
|
307
|
+
# 测试启动命令
|
|
308
|
+
cd /var/www/befly
|
|
309
|
+
sudo -u www-data bun run befly start --cluster max
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
### 权限问题
|
|
313
|
+
|
|
314
|
+
```bash
|
|
315
|
+
# 检查文件权限
|
|
316
|
+
ls -la /var/www/befly
|
|
317
|
+
|
|
318
|
+
# 修复权限
|
|
319
|
+
sudo chown -R www-data:www-data /var/www/befly
|
|
320
|
+
sudo chmod -R 755 /var/www/befly
|
|
321
|
+
|
|
322
|
+
# 检查日志目录权限
|
|
323
|
+
sudo mkdir -p /var/www/befly/logs
|
|
324
|
+
sudo chown -R www-data:www-data /var/www/befly/logs
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
### 端口占用
|
|
328
|
+
|
|
329
|
+
```bash
|
|
330
|
+
# 检查端口是否被占用
|
|
331
|
+
sudo netstat -tulpn | grep :3000
|
|
332
|
+
|
|
333
|
+
# 或使用 ss
|
|
334
|
+
sudo ss -tulpn | grep :3000
|
|
335
|
+
|
|
336
|
+
# 杀死占用端口的进程
|
|
337
|
+
sudo kill -9 <PID>
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
## 升级和维护
|
|
341
|
+
|
|
342
|
+
### 应用升级
|
|
343
|
+
|
|
344
|
+
```bash
|
|
345
|
+
# 拉取最新代码
|
|
346
|
+
cd /var/www/befly
|
|
347
|
+
git pull
|
|
348
|
+
|
|
349
|
+
# 安装新依赖
|
|
350
|
+
bun install --production
|
|
351
|
+
|
|
352
|
+
# 重启服务
|
|
353
|
+
sudo systemctl restart befly
|
|
354
|
+
|
|
355
|
+
# 查看状态
|
|
356
|
+
sudo systemctl status befly
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
### 日志清理
|
|
360
|
+
|
|
361
|
+
```bash
|
|
362
|
+
# 查看日志占用空间
|
|
363
|
+
sudo journalctl --disk-usage
|
|
364
|
+
|
|
365
|
+
# 清理旧日志(保留最近7天)
|
|
366
|
+
sudo journalctl --vacuum-time=7d
|
|
367
|
+
|
|
368
|
+
# 清理日志(保留最近1GB)
|
|
369
|
+
sudo journalctl --vacuum-size=1G
|
|
370
|
+
|
|
371
|
+
# 配置自动清理(编辑配置文件)
|
|
372
|
+
sudo nano /etc/systemd/journald.conf
|
|
373
|
+
|
|
374
|
+
# 添加配置
|
|
375
|
+
SystemMaxUse=1G
|
|
376
|
+
MaxRetentionSec=7day
|
|
377
|
+
```
|
|
378
|
+
|
|
379
|
+
## 安全建议
|
|
380
|
+
|
|
381
|
+
### 防火墙配置
|
|
382
|
+
|
|
383
|
+
```bash
|
|
384
|
+
# 使用 ufw
|
|
385
|
+
sudo ufw allow 80/tcp
|
|
386
|
+
sudo ufw allow 443/tcp
|
|
387
|
+
sudo ufw enable
|
|
388
|
+
|
|
389
|
+
# 或使用 firewalld
|
|
390
|
+
sudo firewall-cmd --permanent --add-service=http
|
|
391
|
+
sudo firewall-cmd --permanent --add-service=https
|
|
392
|
+
sudo firewall-cmd --reload
|
|
393
|
+
```
|
|
394
|
+
|
|
395
|
+
### 最小权限原则
|
|
396
|
+
|
|
397
|
+
```bash
|
|
398
|
+
# 禁止 befly 用户登录
|
|
399
|
+
sudo usermod -s /bin/false befly
|
|
400
|
+
|
|
401
|
+
# 限制目录访问
|
|
402
|
+
sudo chmod 750 /var/www/befly
|
|
403
|
+
```
|
|
404
|
+
|
|
405
|
+
### 定期更新
|
|
406
|
+
|
|
407
|
+
```bash
|
|
408
|
+
# 更新系统
|
|
409
|
+
sudo apt update && sudo apt upgrade -y # Debian/Ubuntu
|
|
410
|
+
# 或
|
|
411
|
+
sudo yum update -y # CentOS/RHEL
|
|
412
|
+
|
|
413
|
+
# 更新 Bun
|
|
414
|
+
bun upgrade
|
|
415
|
+
```
|
|
416
|
+
|
|
417
|
+
## 备份策略
|
|
418
|
+
|
|
419
|
+
```bash
|
|
420
|
+
#!/bin/bash
|
|
421
|
+
# 保存为 /usr/local/bin/befly-backup.sh
|
|
422
|
+
|
|
423
|
+
DATE=$(date +%Y%m%d_%H%M%S)
|
|
424
|
+
BACKUP_DIR="/var/backups/befly"
|
|
425
|
+
PROJECT_DIR="/var/www/befly"
|
|
426
|
+
|
|
427
|
+
# 创建备份目录
|
|
428
|
+
mkdir -p $BACKUP_DIR
|
|
429
|
+
|
|
430
|
+
# 备份配置和代码
|
|
431
|
+
tar -czf $BACKUP_DIR/befly_$DATE.tar.gz \
|
|
432
|
+
$PROJECT_DIR/.env.production \
|
|
433
|
+
$PROJECT_DIR/package.json \
|
|
434
|
+
$PROJECT_DIR/bun.lockb \
|
|
435
|
+
/etc/systemd/system/befly.service
|
|
436
|
+
|
|
437
|
+
# 保留最近30天的备份
|
|
438
|
+
find $BACKUP_DIR -name "befly_*.tar.gz" -mtime +30 -delete
|
|
439
|
+
```
|
|
440
|
+
|
|
441
|
+
## 性能优化
|
|
442
|
+
|
|
443
|
+
### Bun 优化
|
|
444
|
+
|
|
445
|
+
```bash
|
|
446
|
+
# 使用生产模式
|
|
447
|
+
NODE_ENV=production
|
|
448
|
+
|
|
449
|
+
# 禁用调试日志
|
|
450
|
+
DEBUG=0
|
|
451
|
+
```
|
|
452
|
+
|
|
453
|
+
### 系统优化
|
|
454
|
+
|
|
455
|
+
```bash
|
|
456
|
+
# 增加文件描述符限制
|
|
457
|
+
echo "* soft nofile 65536" | sudo tee -a /etc/security/limits.conf
|
|
458
|
+
echo "* hard nofile 65536" | sudo tee -a /etc/security/limits.conf
|
|
459
|
+
|
|
460
|
+
# 优化内核参数
|
|
461
|
+
sudo sysctl -w net.core.somaxconn=65535
|
|
462
|
+
sudo sysctl -w net.ipv4.tcp_max_syn_backlog=8192
|
|
463
|
+
```
|
|
464
|
+
|
|
465
|
+
## 联系和支持
|
|
466
|
+
|
|
467
|
+
- 文档:https://github.com/chenbimo/befly
|
|
468
|
+
- 问题反馈:GitHub Issues
|
package/apis/user/login.ts
CHANGED
package/befly.service
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# Befly Systemd Service 配置文件
|
|
2
|
+
#
|
|
3
|
+
# 使用方法:
|
|
4
|
+
# 1. 复制此文件到 /etc/systemd/system/befly.service
|
|
5
|
+
# sudo cp befly.service /etc/systemd/system/
|
|
6
|
+
#
|
|
7
|
+
# 2. 修改配置中的路径和用户信息
|
|
8
|
+
# sudo nano /etc/systemd/system/befly.service
|
|
9
|
+
#
|
|
10
|
+
# 3. 重载 systemd 配置
|
|
11
|
+
# sudo systemctl daemon-reload
|
|
12
|
+
#
|
|
13
|
+
# 4. 启动服务
|
|
14
|
+
# sudo systemctl start befly
|
|
15
|
+
#
|
|
16
|
+
# 5. 开机自启
|
|
17
|
+
# sudo systemctl enable befly
|
|
18
|
+
#
|
|
19
|
+
# 6. 查看状态
|
|
20
|
+
# sudo systemctl status befly
|
|
21
|
+
#
|
|
22
|
+
# 7. 查看日志
|
|
23
|
+
# sudo journalctl -u befly -f
|
|
24
|
+
#
|
|
25
|
+
# 8. 重启服务
|
|
26
|
+
# sudo systemctl restart befly
|
|
27
|
+
#
|
|
28
|
+
# 9. 停止服务
|
|
29
|
+
# sudo systemctl stop befly
|
|
30
|
+
|
|
31
|
+
[Unit]
|
|
32
|
+
Description=Befly Application Server
|
|
33
|
+
Documentation=https://github.com/chenbimo/befly
|
|
34
|
+
After=network.target
|
|
35
|
+
|
|
36
|
+
[Service]
|
|
37
|
+
Type=simple
|
|
38
|
+
|
|
39
|
+
# 运行用户和组(根据实际情况修改)
|
|
40
|
+
User=www-data
|
|
41
|
+
Group=www-data
|
|
42
|
+
|
|
43
|
+
# 工作目录(修改为实际项目路径)
|
|
44
|
+
WorkingDirectory=/var/www/befly
|
|
45
|
+
|
|
46
|
+
# 环境变量配置
|
|
47
|
+
Environment="NODE_ENV=production"
|
|
48
|
+
Environment="APP_PORT=3000"
|
|
49
|
+
Environment="APP_HOST=0.0.0.0"
|
|
50
|
+
|
|
51
|
+
# 启动命令
|
|
52
|
+
# 单进程模式:
|
|
53
|
+
# ExecStart=/usr/local/bin/bun run befly start
|
|
54
|
+
#
|
|
55
|
+
# 集群模式(推荐,自动使用所有CPU核心):
|
|
56
|
+
ExecStart=/usr/local/bin/bun run befly start --cluster max
|
|
57
|
+
#
|
|
58
|
+
# 集群模式(指定进程数):
|
|
59
|
+
# ExecStart=/usr/local/bin/bun run befly start --cluster 4
|
|
60
|
+
|
|
61
|
+
# 重启策略
|
|
62
|
+
Restart=always # 总是自动重启(崩溃、OOM、异常退出等)
|
|
63
|
+
RestartSec=10 # 重启前等待10秒
|
|
64
|
+
StartLimitInterval=300 # 5分钟内
|
|
65
|
+
StartLimitBurst=5 # 最多重启5次(防止无限重启)
|
|
66
|
+
|
|
67
|
+
# 资源限制
|
|
68
|
+
MemoryMax=4G # 最大内存限制
|
|
69
|
+
MemoryHigh=3G # 内存高水位警告
|
|
70
|
+
LimitNOFILE=65536 # 最大打开文件数
|
|
71
|
+
LimitNPROC=4096 # 最大进程数
|
|
72
|
+
|
|
73
|
+
# CPU 限制(可选)
|
|
74
|
+
# CPUQuota=200% # 最多使用2个CPU核心(200%)
|
|
75
|
+
|
|
76
|
+
# 安全加固(可选,根据需要启用)
|
|
77
|
+
# PrivateTmp=true # 使用私有 /tmp 目录
|
|
78
|
+
# NoNewPrivileges=true # 禁止提升权限
|
|
79
|
+
# ProtectSystem=strict # 保护系统目录只读
|
|
80
|
+
# ProtectHome=true # 保护家目录
|
|
81
|
+
|
|
82
|
+
# 日志配置
|
|
83
|
+
StandardOutput=journal # 标准输出到 systemd journal
|
|
84
|
+
StandardError=journal # 错误输出到 systemd journal
|
|
85
|
+
SyslogIdentifier=befly # 日志标识符
|
|
86
|
+
|
|
87
|
+
# 优雅关闭
|
|
88
|
+
# KillMode=mixed # 混合模式:先 SIGTERM,超时后 SIGKILL
|
|
89
|
+
# KillSignal=SIGTERM # 发送 SIGTERM 信号
|
|
90
|
+
# TimeoutStopSec=30 # 30秒后强制停止
|
|
91
|
+
|
|
92
|
+
[Install]
|
|
93
|
+
WantedBy=multi-user.target # 多用户模式下启动
|
package/package.json
CHANGED
|
@@ -1,19 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "befly-tpl",
|
|
3
|
-
"version": "3.
|
|
4
|
-
"main": "main.ts",
|
|
5
|
-
"types": "main.ts",
|
|
3
|
+
"version": "3.4.0",
|
|
6
4
|
"description": "Befly 3.0 TypeScript Template",
|
|
7
5
|
"private": false,
|
|
8
6
|
"publishConfig": {
|
|
9
7
|
"access": "public",
|
|
10
8
|
"registry": "https://registry.npmjs.org"
|
|
11
9
|
},
|
|
12
|
-
"scripts": {
|
|
13
|
-
"dev": "bun --env-file=.env.development run main.ts",
|
|
14
|
-
"serve": "bunx --bun pm2 start pm2.config.cjs -a",
|
|
15
|
-
"test": "bun test"
|
|
16
|
-
},
|
|
10
|
+
"scripts": {},
|
|
17
11
|
"files": [
|
|
18
12
|
"apis",
|
|
19
13
|
"checks",
|
|
@@ -24,20 +18,21 @@
|
|
|
24
18
|
"tests",
|
|
25
19
|
".env.development",
|
|
26
20
|
".npmrc",
|
|
21
|
+
"befly.service",
|
|
27
22
|
"LICENSE",
|
|
28
|
-
"main.ts",
|
|
29
23
|
"package.json",
|
|
30
24
|
"pm2.config.cjs",
|
|
31
25
|
"README.md",
|
|
26
|
+
"SYSTEMD_DEPLOY.md",
|
|
32
27
|
"tsconfig.json"
|
|
33
28
|
],
|
|
34
29
|
"type": "module",
|
|
35
30
|
"dependencies": {
|
|
36
31
|
"@befly-addon/admin": "1.0.2",
|
|
37
|
-
"befly": "^3.
|
|
32
|
+
"befly": "^3.4.0"
|
|
38
33
|
},
|
|
39
34
|
"engines": {
|
|
40
35
|
"bun": ">=1.3.0"
|
|
41
36
|
},
|
|
42
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "2fbc9a9d7f4e6a30945c0bb274f3c5982949a8f6"
|
|
43
38
|
}
|
package/main.ts
DELETED
package/pm2.config.cjs
DELETED
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
apps: [
|
|
3
|
-
{
|
|
4
|
-
name: 'tpl',
|
|
5
|
-
instances: 4,
|
|
6
|
-
script: './main.js',
|
|
7
|
-
exec_mode: 'cluster',
|
|
8
|
-
watch: false,
|
|
9
|
-
autorestart: true,
|
|
10
|
-
interpreter: 'bun',
|
|
11
|
-
ignore_watch: ['node_modules', 'logs', 'data'],
|
|
12
|
-
max_memory_restart: '200M',
|
|
13
|
-
env: {
|
|
14
|
-
NODE_ENV: 'production',
|
|
15
|
-
// 项目名称
|
|
16
|
-
APP_NAME: '易接口',
|
|
17
|
-
APP_PORT: 3000,
|
|
18
|
-
// 监听端口,
|
|
19
|
-
APP_HOST: '127.0.0.1',
|
|
20
|
-
// 开发管理员邮箱
|
|
21
|
-
DEV_EMAIL: 'dev@qq.com',
|
|
22
|
-
// 开发管理员密码,
|
|
23
|
-
DEV_PASSWORD: '123456',
|
|
24
|
-
// 请求体大小,
|
|
25
|
-
BODY_LIMIT: 10,
|
|
26
|
-
// 参数检查,
|
|
27
|
-
PARAMS_CHECK: 0,
|
|
28
|
-
// 日志等级,
|
|
29
|
-
LOG_EXCLUDE_FIELDS: 'password,token',
|
|
30
|
-
LOG_LEVEL: 'info',
|
|
31
|
-
LOG_DIR: './logs',
|
|
32
|
-
LOG_TO_CONSOLE: 1,
|
|
33
|
-
LOG_MAX_SIZE: 52428800, // 50MB,
|
|
34
|
-
// 时区,
|
|
35
|
-
TZ: 'Asia/Shanghai',
|
|
36
|
-
// 跨域配置
|
|
37
|
-
ALLOWED_METHODS: 'GET, POST, PUT, DELETE, OPTIONS',
|
|
38
|
-
ALLOWED_HEADERS: 'Content-Type, Authorization, authorization, token',
|
|
39
|
-
EXPOSE_HEADERS: 'Content-Range, X-Content-Range, Authorization, authorization, token',
|
|
40
|
-
MAX_AGE: 86400,
|
|
41
|
-
ALLOW_CREDENTIALS: 'true',
|
|
42
|
-
// 数据库配置(DB_* 通用参数),
|
|
43
|
-
DB_ENABLE: 1,
|
|
44
|
-
DB_TYPE: 'mysql',
|
|
45
|
-
DB_HOST: '127.0.0.1',
|
|
46
|
-
DB_PORT: 3306,
|
|
47
|
-
DB_USER: 'root',
|
|
48
|
-
DB_PASS: 'root',
|
|
49
|
-
DB_NAME: 'test',
|
|
50
|
-
DB_POOL_MAX: 10,
|
|
51
|
-
DB_DEBUG: 0,
|
|
52
|
-
// redis 配置,
|
|
53
|
-
REDIS_ENABLE: 1,
|
|
54
|
-
REDIS_URL: 'redis://root:root@127.0.0.1:6379',
|
|
55
|
-
REDIS_HOST: '127.0.0.1',
|
|
56
|
-
REDIS_PORT: 6379,
|
|
57
|
-
REDIS_USERNAME: '',
|
|
58
|
-
REDIS_PASSWORD: '',
|
|
59
|
-
REDIS_DB: 3,
|
|
60
|
-
REDIS_KEY_PREFIX: '',
|
|
61
|
-
// JWT 配置,
|
|
62
|
-
JWT_SECRET: 'dbfaf2c3-7ade-5042-b843-eca8814714b3',
|
|
63
|
-
JWT_EXPIRES_IN: '30d',
|
|
64
|
-
JWT_ALGORITHM: 'HS256',
|
|
65
|
-
// 邮箱配置,
|
|
66
|
-
MAIL_HOST: 'smtp.qq.com',
|
|
67
|
-
MAIL_PORT: 465,
|
|
68
|
-
MAIL_POOL: 1,
|
|
69
|
-
MAIL_SECURE: 1,
|
|
70
|
-
MAIL_USER: '',
|
|
71
|
-
MAIL_PASS: '',
|
|
72
|
-
MAIL_SENDER: '',
|
|
73
|
-
MAIL_ADDRESS: 'demo@qq.com',
|
|
74
|
-
// 上传配置,
|
|
75
|
-
LOCAL_DIR: '/wwwroot/static2/',
|
|
76
|
-
// 微信配置,
|
|
77
|
-
PAY_NOTIFY_URL: '',
|
|
78
|
-
// --- 同步脚本开关(用于表结构同步) ---
|
|
79
|
-
SYNC_MERGE_ALTER: 1,
|
|
80
|
-
SYNC_DISALLOW_SHRINK: 1,
|
|
81
|
-
SYNC_ALLOW_TYPE_CHANGE: 0
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
]
|
|
85
|
-
};
|
package/types/api.ts
DELETED
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* API 请求/响应类型定义示例
|
|
3
|
-
* 注意:实际项目中可能不需要这些类型定义
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* 用户登录请求
|
|
8
|
-
*/
|
|
9
|
-
export interface LoginRequest {
|
|
10
|
-
username: string;
|
|
11
|
-
password: string;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* 用户登录响应
|
|
16
|
-
*/
|
|
17
|
-
export interface LoginResponse {
|
|
18
|
-
token: string;
|
|
19
|
-
user: Omit<User, 'password'>;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* 用户注册请求
|
|
24
|
-
*/
|
|
25
|
-
export interface RegisterRequest {
|
|
26
|
-
username: string;
|
|
27
|
-
email: string;
|
|
28
|
-
password: string;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* 获取用户列表请求
|
|
33
|
-
*/
|
|
34
|
-
export interface GetUsersRequest extends PaginationParams {
|
|
35
|
-
role?: string;
|
|
36
|
-
keyword?: string;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* 获取用户列表响应
|
|
41
|
-
*/
|
|
42
|
-
export type GetUsersResponse = ListResponse<Omit<User, 'password'>>;
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* 创建文章请求
|
|
46
|
-
*/
|
|
47
|
-
export interface CreateArticleRequest {
|
|
48
|
-
title: string;
|
|
49
|
-
content: string;
|
|
50
|
-
categoryId: number;
|
|
51
|
-
tags: string[];
|
|
52
|
-
summary?: string;
|
|
53
|
-
coverImage?: string;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* 获取文章列表请求
|
|
58
|
-
*/
|
|
59
|
-
export interface GetArticlesRequest extends PaginationParams {
|
|
60
|
-
categoryId?: number;
|
|
61
|
-
authorId?: number;
|
|
62
|
-
keyword?: string;
|
|
63
|
-
published?: boolean;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* 获取文章列表响应
|
|
68
|
-
*/
|
|
69
|
-
export type GetArticlesResponse = ListResponse<Article>;
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* 创建产品请求
|
|
73
|
-
*/
|
|
74
|
-
export interface CreateProductRequest {
|
|
75
|
-
name: string;
|
|
76
|
-
price: number;
|
|
77
|
-
stock: number;
|
|
78
|
-
categoryId: number;
|
|
79
|
-
description: string;
|
|
80
|
-
images?: string[];
|
|
81
|
-
tags?: string[];
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* 获取产品列表请求
|
|
86
|
-
*/
|
|
87
|
-
export interface GetProductsRequest extends PaginationParams {
|
|
88
|
-
categoryId?: number;
|
|
89
|
-
minPrice?: number;
|
|
90
|
-
maxPrice?: number;
|
|
91
|
-
keyword?: string;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* 获取产品列表响应
|
|
96
|
-
*/
|
|
97
|
-
export type GetProductsResponse = ListResponse<Product>;
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* 创建订单请求
|
|
101
|
-
*/
|
|
102
|
-
export interface CreateOrderRequest {
|
|
103
|
-
productId: number;
|
|
104
|
-
quantity: number;
|
|
105
|
-
address?: string;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* 创建订单响应
|
|
110
|
-
*/
|
|
111
|
-
export interface CreateOrderResponse {
|
|
112
|
-
orderId: number;
|
|
113
|
-
orderNo: string;
|
|
114
|
-
totalPrice: number;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* 获取订单列表请求
|
|
119
|
-
*/
|
|
120
|
-
export interface GetOrdersRequest extends PaginationParams {
|
|
121
|
-
userId?: number;
|
|
122
|
-
status?: string;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* 获取订单列表响应
|
|
127
|
-
*/
|
|
128
|
-
export type GetOrdersResponse = ListResponse<Order>;
|
package/types/index.ts
DELETED
package/types/models.example.ts
DELETED
|
@@ -1,267 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 数据模型类型定义
|
|
3
|
-
*
|
|
4
|
-
* 这个文件定义了常用的数据模型类型
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* 基础实体接口(所有表共有的字段)
|
|
9
|
-
*/
|
|
10
|
-
export interface BaseEntity {
|
|
11
|
-
/** 主键 ID */
|
|
12
|
-
id: number;
|
|
13
|
-
/** 创建时间(时间戳) */
|
|
14
|
-
createdAt: number;
|
|
15
|
-
/** 更新时间(时间戳) */
|
|
16
|
-
updatedAt: number;
|
|
17
|
-
/** 删除时间(时间戳,null 表示未删除) */
|
|
18
|
-
deletedAt: number | null;
|
|
19
|
-
/** 状态(0=正常,1=禁用) */
|
|
20
|
-
state: number;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* 用户角色类型
|
|
25
|
-
*/
|
|
26
|
-
export type UserRole = 'admin' | 'user' | 'guest' | 'editor' | 'viewer';
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* 用户模型
|
|
30
|
-
*/
|
|
31
|
-
export interface User extends BaseEntity {
|
|
32
|
-
/** 用户名 */
|
|
33
|
-
username: string;
|
|
34
|
-
/** 邮箱 */
|
|
35
|
-
email: string;
|
|
36
|
-
/** 密码(哈希后) */
|
|
37
|
-
password: string;
|
|
38
|
-
/** 角色 */
|
|
39
|
-
role: UserRole;
|
|
40
|
-
/** 手机号 */
|
|
41
|
-
phone?: string;
|
|
42
|
-
/** 头像 URL */
|
|
43
|
-
avatar?: string;
|
|
44
|
-
/** 昵称 */
|
|
45
|
-
nickname?: string;
|
|
46
|
-
/** 个人简介 */
|
|
47
|
-
bio?: string;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* 产品分类
|
|
52
|
-
*/
|
|
53
|
-
export interface Category extends BaseEntity {
|
|
54
|
-
/** 分类名称 */
|
|
55
|
-
name: string;
|
|
56
|
-
/** 父分类 ID */
|
|
57
|
-
parentId: number | null;
|
|
58
|
-
/** 排序 */
|
|
59
|
-
sort: number;
|
|
60
|
-
/** 描述 */
|
|
61
|
-
description?: string;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* 产品模型
|
|
66
|
-
*/
|
|
67
|
-
export interface Product extends BaseEntity {
|
|
68
|
-
/** 产品名称 */
|
|
69
|
-
name: string;
|
|
70
|
-
/** 价格(单位:分) */
|
|
71
|
-
price: number;
|
|
72
|
-
/** 库存 */
|
|
73
|
-
stock: number;
|
|
74
|
-
/** 分类 ID */
|
|
75
|
-
categoryId: number;
|
|
76
|
-
/** 标签 */
|
|
77
|
-
tags: string[];
|
|
78
|
-
/** 描述 */
|
|
79
|
-
description: string;
|
|
80
|
-
/** 图片 URL 列表 */
|
|
81
|
-
images?: string[];
|
|
82
|
-
/** SKU */
|
|
83
|
-
sku?: string;
|
|
84
|
-
/** 原价 */
|
|
85
|
-
originalPrice?: number;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* 订单状态
|
|
90
|
-
*/
|
|
91
|
-
export type OrderStatus = 'pending' | 'paid' | 'shipped' | 'completed' | 'cancelled' | 'refunded';
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* 订单模型
|
|
95
|
-
*/
|
|
96
|
-
export interface Order extends BaseEntity {
|
|
97
|
-
/** 订单号 */
|
|
98
|
-
orderNo: string;
|
|
99
|
-
/** 用户 ID */
|
|
100
|
-
userId: number;
|
|
101
|
-
/** 产品 ID */
|
|
102
|
-
productId: number;
|
|
103
|
-
/** 数量 */
|
|
104
|
-
quantity: number;
|
|
105
|
-
/** 总价 */
|
|
106
|
-
totalPrice: number;
|
|
107
|
-
/** 状态 */
|
|
108
|
-
status: OrderStatus;
|
|
109
|
-
/** 收货地址 */
|
|
110
|
-
address?: string;
|
|
111
|
-
/** 收货人 */
|
|
112
|
-
recipient?: string;
|
|
113
|
-
/** 联系电话 */
|
|
114
|
-
phone?: string;
|
|
115
|
-
/** 备注 */
|
|
116
|
-
remark?: string;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* 文章模型
|
|
121
|
-
*/
|
|
122
|
-
export interface Article extends BaseEntity {
|
|
123
|
-
/** 标题 */
|
|
124
|
-
title: string;
|
|
125
|
-
/** 内容 */
|
|
126
|
-
content: string;
|
|
127
|
-
/** 作者 ID */
|
|
128
|
-
authorId: number;
|
|
129
|
-
/** 分类 ID */
|
|
130
|
-
categoryId: number;
|
|
131
|
-
/** 标签 */
|
|
132
|
-
tags: string[];
|
|
133
|
-
/** 摘要 */
|
|
134
|
-
summary?: string;
|
|
135
|
-
/** 封面图 */
|
|
136
|
-
coverImage?: string;
|
|
137
|
-
/** 浏览次数 */
|
|
138
|
-
viewCount: number;
|
|
139
|
-
/** 点赞次数 */
|
|
140
|
-
likeCount: number;
|
|
141
|
-
/** 是否发布 */
|
|
142
|
-
published: boolean;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* 评论模型
|
|
147
|
-
*/
|
|
148
|
-
export interface Comment extends BaseEntity {
|
|
149
|
-
/** 评论内容 */
|
|
150
|
-
content: string;
|
|
151
|
-
/** 用户 ID */
|
|
152
|
-
userId: number;
|
|
153
|
-
/** 关联 ID(文章、产品等) */
|
|
154
|
-
targetId: number;
|
|
155
|
-
/** 关联类型 */
|
|
156
|
-
targetType: 'article' | 'product' | 'order';
|
|
157
|
-
/** 父评论 ID */
|
|
158
|
-
parentId: number | null;
|
|
159
|
-
/** 点赞次数 */
|
|
160
|
-
likeCount: number;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
/**
|
|
164
|
-
* 文件模型
|
|
165
|
-
*/
|
|
166
|
-
export interface File extends BaseEntity {
|
|
167
|
-
/** 文件名 */
|
|
168
|
-
filename: string;
|
|
169
|
-
/** 原始文件名 */
|
|
170
|
-
originalName: string;
|
|
171
|
-
/** 文件路径 */
|
|
172
|
-
path: string;
|
|
173
|
-
/** 文件大小(字节) */
|
|
174
|
-
size: number;
|
|
175
|
-
/** MIME 类型 */
|
|
176
|
-
mimeType: string;
|
|
177
|
-
/** 文件哈希 */
|
|
178
|
-
hash: string;
|
|
179
|
-
/** 上传者 ID */
|
|
180
|
-
uploaderId: number;
|
|
181
|
-
/** 文件类型 */
|
|
182
|
-
type: 'image' | 'video' | 'audio' | 'document' | 'other';
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
/**
|
|
186
|
-
* 配置模型
|
|
187
|
-
*/
|
|
188
|
-
export interface Config extends BaseEntity {
|
|
189
|
-
/** 配置键 */
|
|
190
|
-
key: string;
|
|
191
|
-
/** 配置值 */
|
|
192
|
-
value: string;
|
|
193
|
-
/** 配置类型 */
|
|
194
|
-
type: 'string' | 'number' | 'boolean' | 'json';
|
|
195
|
-
/** 描述 */
|
|
196
|
-
description?: string;
|
|
197
|
-
/** 分组 */
|
|
198
|
-
group?: string;
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
/**
|
|
202
|
-
* 日志模型
|
|
203
|
-
*/
|
|
204
|
-
export interface Log extends BaseEntity {
|
|
205
|
-
/** 日志级别 */
|
|
206
|
-
level: 'info' | 'warn' | 'error' | 'debug';
|
|
207
|
-
/** 日志消息 */
|
|
208
|
-
message: string;
|
|
209
|
-
/** 用户 ID */
|
|
210
|
-
userId?: number;
|
|
211
|
-
/** IP 地址 */
|
|
212
|
-
ip?: string;
|
|
213
|
-
/** 用户代理 */
|
|
214
|
-
userAgent?: string;
|
|
215
|
-
/** 额外数据 */
|
|
216
|
-
metadata?: Record<string, any>;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
/**
|
|
220
|
-
* 通知模型
|
|
221
|
-
*/
|
|
222
|
-
export interface Notification extends BaseEntity {
|
|
223
|
-
/** 标题 */
|
|
224
|
-
title: string;
|
|
225
|
-
/** 内容 */
|
|
226
|
-
content: string;
|
|
227
|
-
/** 接收者 ID */
|
|
228
|
-
receiverId: number;
|
|
229
|
-
/** 类型 */
|
|
230
|
-
type: 'system' | 'order' | 'comment' | 'like' | 'follow';
|
|
231
|
-
/** 是否已读 */
|
|
232
|
-
read: boolean;
|
|
233
|
-
/** 关联 ID */
|
|
234
|
-
targetId?: number;
|
|
235
|
-
/** 关联类型 */
|
|
236
|
-
targetType?: string;
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
/**
|
|
240
|
-
* 权限模型
|
|
241
|
-
*/
|
|
242
|
-
export interface Permission extends BaseEntity {
|
|
243
|
-
/** 权限名称 */
|
|
244
|
-
name: string;
|
|
245
|
-
/** 权限标识 */
|
|
246
|
-
code: string;
|
|
247
|
-
/** 描述 */
|
|
248
|
-
description?: string;
|
|
249
|
-
/** 资源类型 */
|
|
250
|
-
resource: string;
|
|
251
|
-
/** 操作类型 */
|
|
252
|
-
action: 'create' | 'read' | 'update' | 'delete' | 'execute';
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
/**
|
|
256
|
-
* 角色模型
|
|
257
|
-
*/
|
|
258
|
-
export interface Role extends BaseEntity {
|
|
259
|
-
/** 角色名称 */
|
|
260
|
-
name: string;
|
|
261
|
-
/** 角色标识 */
|
|
262
|
-
code: string;
|
|
263
|
-
/** 描述 */
|
|
264
|
-
description?: string;
|
|
265
|
-
/** 权限 ID 列表 */
|
|
266
|
-
permissions: number[];
|
|
267
|
-
}
|
package/types/models.ts
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 数据模型类型定义示例
|
|
3
|
-
* 注意:实际项目中可能不需要这些类型定义
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* 用户模型
|
|
8
|
-
*/
|
|
9
|
-
export interface User extends BaseEntity {
|
|
10
|
-
username: string;
|
|
11
|
-
email: string;
|
|
12
|
-
password: string;
|
|
13
|
-
role: UserRole;
|
|
14
|
-
avatar?: string;
|
|
15
|
-
nickname?: string;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* 用户角色
|
|
20
|
-
*/
|
|
21
|
-
export type UserRole = 'admin' | 'user' | 'guest';
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* 文章模型
|
|
25
|
-
*/
|
|
26
|
-
export interface Article extends BaseEntity {
|
|
27
|
-
title: string;
|
|
28
|
-
content: string;
|
|
29
|
-
authorId: number;
|
|
30
|
-
categoryId: number;
|
|
31
|
-
tags: string[];
|
|
32
|
-
summary?: string;
|
|
33
|
-
coverImage?: string;
|
|
34
|
-
viewCount: number;
|
|
35
|
-
published: boolean;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* 产品模型
|
|
40
|
-
*/
|
|
41
|
-
export interface Product extends BaseEntity {
|
|
42
|
-
name: string;
|
|
43
|
-
price: number;
|
|
44
|
-
stock: number;
|
|
45
|
-
categoryId: number;
|
|
46
|
-
description: string;
|
|
47
|
-
images: string[];
|
|
48
|
-
tags: string[];
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* 订单模型
|
|
53
|
-
*/
|
|
54
|
-
export interface Order extends BaseEntity {
|
|
55
|
-
orderNo: string;
|
|
56
|
-
userId: number;
|
|
57
|
-
productId: number;
|
|
58
|
-
quantity: number;
|
|
59
|
-
totalPrice: number;
|
|
60
|
-
status: OrderStatus;
|
|
61
|
-
address?: string;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* 订单状态
|
|
66
|
-
*/
|
|
67
|
-
export type OrderStatus = 'pending' | 'paid' | 'shipped' | 'completed' | 'cancelled';
|