mb-rrvideo-server 1.0.5 → 1.0.8
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/DOCKER.md +10 -2
- package/Dockerfile +3 -1
- package/bin/rrvideo-server +5 -4
- package/docker-compose.yml +1 -1
- package/package.json +1 -1
- package/src/index.js +37 -31
- package/src/routes/receive.js +24 -1
package/DOCKER.md
CHANGED
|
@@ -16,8 +16,7 @@
|
|
|
16
16
|
|
|
17
17
|
**快速参考:**
|
|
18
18
|
```bash
|
|
19
|
-
|
|
20
|
-
npm pack mb-rrvideo-server
|
|
19
|
+
|
|
21
20
|
|
|
22
21
|
# 构建 Docker 镜像
|
|
23
22
|
docker build -t mb-rrvideo-converter:latest .
|
|
@@ -31,8 +30,17 @@ docker-compose up -d
|
|
|
31
30
|
#第一次安装
|
|
32
31
|
sudo docker compose up -d --build --progress=plain
|
|
33
32
|
|
|
33
|
+
# 更新docker镜像(里面的npm依赖更新的时候用这个):
|
|
34
|
+
sudo docker compose build --no-cache
|
|
35
|
+
|
|
36
|
+
# 清理旧容器
|
|
37
|
+
sudo docker system prune -f
|
|
38
|
+
|
|
34
39
|
# 容器名称
|
|
35
40
|
docker ps | grep rrvideo-server
|
|
41
|
+
|
|
42
|
+
# 下载 npm 包
|
|
43
|
+
npm pack mb-rrvideo-server
|
|
36
44
|
```
|
|
37
45
|
|
|
38
46
|
## 目录
|
package/Dockerfile
CHANGED
|
@@ -27,13 +27,15 @@ RUN sed -i 's/deb.debian.org/mirrors.aliyun.com/g' /etc/apt/sources.list.d/debia
|
|
|
27
27
|
sed -i 's/security.debian.org/mirrors.aliyun.com/g' /etc/apt/sources.list.d/debian.sources
|
|
28
28
|
|
|
29
29
|
# ============================================
|
|
30
|
-
#
|
|
30
|
+
# 第三步:安装系统依赖
|
|
31
31
|
# ============================================
|
|
32
32
|
RUN apt-get update && apt-get install -y \
|
|
33
33
|
# 基础工具
|
|
34
34
|
curl \
|
|
35
35
|
wget \
|
|
36
36
|
ca-certificates \
|
|
37
|
+
# 安装 ffmpeg 和 ffprobe (合并视频必须)
|
|
38
|
+
ffmpeg \
|
|
37
39
|
# Playwright Chromium 依赖
|
|
38
40
|
libnss3 \
|
|
39
41
|
libnspr4 \
|
package/bin/rrvideo-server
CHANGED
|
@@ -6,9 +6,10 @@
|
|
|
6
6
|
|
|
7
7
|
const path = require('path');
|
|
8
8
|
|
|
9
|
-
//
|
|
10
|
-
const projectRoot = path.resolve(__dirname, '..');
|
|
11
|
-
process.chdir(projectRoot);
|
|
9
|
+
// 设置工作目录为项目根目录(如果有必要,或者保持当前目录)
|
|
10
|
+
// const projectRoot = path.resolve(__dirname, '..');
|
|
11
|
+
// process.chdir(projectRoot);
|
|
12
12
|
|
|
13
13
|
// 启动服务
|
|
14
|
-
require('../src/index.js');
|
|
14
|
+
const { startServer } = require('../src/index.js');
|
|
15
|
+
startServer();
|
package/docker-compose.yml
CHANGED
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -11,6 +11,35 @@ const { handleReceiveRequest } = require('./routes/receive');
|
|
|
11
11
|
const { handleConvertV1, handleConvertV2 } = require('./routes/convert');
|
|
12
12
|
const { handleMerge } = require('./routes/merge');
|
|
13
13
|
|
|
14
|
+
// 全局错误处理
|
|
15
|
+
process.on('exit', (code) => {
|
|
16
|
+
console.log(`进程退出,代码: ${code}`);
|
|
17
|
+
logger.flushAll();
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
process.on('SIGINT', () => {
|
|
21
|
+
console.log('收到 SIGINT 信号,正在关闭...');
|
|
22
|
+
logger.flushAll();
|
|
23
|
+
process.exit(0);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
process.on('SIGTERM', () => {
|
|
27
|
+
console.log('收到 SIGTERM 信号,正在关闭...');
|
|
28
|
+
logger.flushAll();
|
|
29
|
+
process.exit(0);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
process.on('uncaughtException', (err) => {
|
|
33
|
+
console.error(`未捕获的异常: ${err.message}`);
|
|
34
|
+
console.error(err.stack);
|
|
35
|
+
logger.flushAll();
|
|
36
|
+
process.exit(1);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
process.on('unhandledRejection', (reason, promise) => {
|
|
40
|
+
console.error(`未处理的 Promise 拒绝: ${reason}`);
|
|
41
|
+
});
|
|
42
|
+
|
|
14
43
|
// 创建 HTTP 服务器
|
|
15
44
|
const server = http.createServer((req, res) => {
|
|
16
45
|
try {
|
|
@@ -94,8 +123,8 @@ const server = http.createServer((req, res) => {
|
|
|
94
123
|
}
|
|
95
124
|
});
|
|
96
125
|
|
|
97
|
-
//
|
|
98
|
-
|
|
126
|
+
// 封装启动逻辑
|
|
127
|
+
function startServer() {
|
|
99
128
|
const PORT = config.get('server.port', 24203);
|
|
100
129
|
const HOST = config.get('server.host', '0.0.0.0');
|
|
101
130
|
|
|
@@ -104,35 +133,12 @@ if (require.main === module) {
|
|
|
104
133
|
console.log(`Storage type: ${config.get('storage.type')}`);
|
|
105
134
|
console.log(`Log level: ${config.get('log.level')}`);
|
|
106
135
|
});
|
|
107
|
-
|
|
108
|
-
// 程序异常或提前终止时的处理
|
|
109
|
-
process.on('exit', (code) => {
|
|
110
|
-
console.log(`进程退出,代码: ${code}`);
|
|
111
|
-
logger.flushAll();
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
process.on('SIGINT', () => {
|
|
115
|
-
console.log('收到 SIGINT 信号,正在关闭...');
|
|
116
|
-
logger.flushAll();
|
|
117
|
-
process.exit(0);
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
process.on('SIGTERM', () => {
|
|
121
|
-
console.log('收到 SIGTERM 信号,正在关闭...');
|
|
122
|
-
logger.flushAll();
|
|
123
|
-
process.exit(0);
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
process.on('uncaughtException', (err) => {
|
|
127
|
-
console.error(`未捕获的异常: ${err.message}`);
|
|
128
|
-
console.error(err.stack);
|
|
129
|
-
logger.flushAll();
|
|
130
|
-
process.exit(1);
|
|
131
|
-
});
|
|
136
|
+
}
|
|
132
137
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
138
|
+
// 如果是直接运行脚本,则启动服务器
|
|
139
|
+
if (require.main === module) {
|
|
140
|
+
startServer();
|
|
136
141
|
}
|
|
137
142
|
|
|
138
|
-
|
|
143
|
+
// 导出 server 和启动函数
|
|
144
|
+
module.exports = { server, startServer };
|
package/src/routes/receive.js
CHANGED
|
@@ -35,7 +35,30 @@ async function handleReceiveRequest(req, res) {
|
|
|
35
35
|
logFileName = `${recordId}_${actionName}_${Date.now()}`;
|
|
36
36
|
|
|
37
37
|
logger.info(`[${actionName}] 收到统一请求,类型: ${type}, record_id: ${recordId}, request_id: ${requestId}`, logFileName, 'receive');
|
|
38
|
-
|
|
38
|
+
// 创建输入的副本进行日志记录,截断过长的字段
|
|
39
|
+
const logData = { ...inputData };
|
|
40
|
+
|
|
41
|
+
const truncate = (obj) => {
|
|
42
|
+
try {
|
|
43
|
+
const str = JSON.stringify(obj);
|
|
44
|
+
return str.length > 200 ? str.substring(0, 200) + '...' : obj;
|
|
45
|
+
} catch (e) {
|
|
46
|
+
return String(obj).substring(0, 200) + '...';
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
if (logData.events) {
|
|
51
|
+
logData.events = truncate(logData.events);
|
|
52
|
+
}
|
|
53
|
+
if (logData.tasks) {
|
|
54
|
+
logData.tasks = logData.tasks.map(t => {
|
|
55
|
+
const taskLog = { ...t };
|
|
56
|
+
if (taskLog.events) taskLog.events = truncate(taskLog.events);
|
|
57
|
+
return taskLog;
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
logger.debug(`[${actionName}] 收到请求数据: ${JSON.stringify(logData)}`, logFileName, 'receive');
|
|
39
62
|
|
|
40
63
|
if (!recordId) {
|
|
41
64
|
logger.info(`[${actionName}] record_id不能为空`, logFileName, 'receive');
|