filecat 5.13.9 → 5.14.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/build/watch.js ADDED
@@ -0,0 +1,81 @@
1
+ const { fork } = require('child_process');
2
+ const readline = require('readline');
3
+ const path = require('path');
4
+
5
+ let child = null;
6
+
7
+ // 判断是否包含 dev
8
+ const argv = process.argv;
9
+ const isDev = argv.includes('dev');
10
+
11
+ // 子进程入口
12
+ const childScript = path.resolve(__dirname, isDev ? 'server.ts' : 'main.js');
13
+ const childArgs = argv.slice(2); // 传递给子进程的参数
14
+
15
+ let max = 1000
16
+ function startServer() {
17
+ if(max <= 0) {
18
+ return;
19
+ }
20
+ max --
21
+ console.log('🚀 启动子进程...');
22
+
23
+ if (isDev) {
24
+ // dev 模式下 fork ts 文件,使用 ts-node/register
25
+ child = fork(childScript, [...childArgs,'--watch'], {
26
+ stdio: ['inherit', 'inherit', 'inherit', 'ipc'], // 输出 + 消息通道
27
+ execArgv: ['-r', 'ts-node/register'],
28
+ env: { ...process.env }
29
+ });
30
+ } else {
31
+ // 生产模式 fork js 文件
32
+ child = fork(childScript, childArgs, {
33
+ stdio: ['inherit', 'inherit', 'inherit', 'ipc'],
34
+ env: { ...process.env }
35
+ });
36
+ }
37
+
38
+ // 监听子进程发来的消息
39
+ child.on('message', (msg) => {
40
+ if (msg === 'restart') {
41
+ console.log('♻️ 子进程请求重启...');
42
+ restartServer();
43
+ }
44
+ });
45
+
46
+ // 子进程退出事件
47
+ child.on('exit', (code, signal) => {
48
+ console.log(`⚠️ 子进程退出:code=${code}, signal=${signal}`);
49
+ });
50
+ }
51
+
52
+ function restartServer() {
53
+ if (child) {
54
+ console.log('♻️ 正在重启子进程...');
55
+ child.kill('SIGTERM'); // 发送信号让子进程优雅退出
56
+ setTimeout(() => startServer(), 500); // 延迟重启,给端口释放时间
57
+ } else {
58
+ startServer();
59
+ }
60
+ }
61
+
62
+ // 启动子进程
63
+ startServer();
64
+
65
+ // 监听键盘输入
66
+ readline.emitKeypressEvents(process.stdin);
67
+ if (process.stdin.isTTY) process.stdin.setRawMode(true);
68
+
69
+ process.stdin.on('keypress', (str, key) => {
70
+ // Ctrl + R 重启
71
+ if (key.ctrl && key.name === 'r') {
72
+ restartServer();
73
+ }
74
+
75
+ // Ctrl + C 退出
76
+ if (key.ctrl && key.name === 'c') {
77
+ console.log('\n🛑 主进程退出');
78
+ if (child) child.kill('SIGTERM');
79
+ process.exit(0);
80
+ }
81
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "filecat",
3
- "version": "5.13.9",
3
+ "version": "5.14.0",
4
4
  "description": "FileCat Server Manager",
5
5
  "author": "xiaobaidadada",
6
6
  "scripts": {
@@ -9,6 +9,7 @@
9
9
  "dev-inspect": "node --inspect=0.0.0.0:9001 --require ts-node/register ./shell/dev.js --env ./env",
10
10
  "server-dev-inspect": "node --inspect=0.0.0.0:9001 --require ts-node/register ./src/main/server.ts --env ./env ",
11
11
  "server-dev": "ts-node --transpile-only ./src/main/server.ts --env ./env",
12
+ "server-watch": "node ./src/main/watch.js --env ./env dev",
12
13
  "webpack-dev": "npx webpack serve --mode development --config shell/config/webpack.web.config.js",
13
14
  "generate-proto": "node --require ts-node/register ./src/common/proto/proto.generate.ts",
14
15
  "webpack-build": "npx webpack --config shell/config/webpack.web.config.js",
@@ -29,7 +30,8 @@
29
30
  ]
30
31
  },
31
32
  "bin": {
32
- "filecat": "shell/filecat"
33
+ "filecat": "shell/filecat",
34
+ "filecat-watch": "shell/filecat-watch"
33
35
  },
34
36
  "repository": {
35
37
  "type": "git",
package/shell/build.js CHANGED
@@ -82,6 +82,7 @@ const tasksLister = new Listr(
82
82
  // copyFileSync(path.join(__dirname, "..", "src", "main", "domain", "net", "wintun-x86.dll"), path.join(__dirname, "..", "build", "wintun-x86.dll"))
83
83
  // copyFileSync(path.join(__dirname, "..", "src", "main", "domain", "bin", "ffmpeg"), path.join(__dirname, "..", "build", "ffmpeg"))
84
84
  // copyFileSync(path.resolve("build/server/main/domain/file/file.worker.js"), path.join(__dirname, "..", "build", "file.worker.js"))
85
+ copyFileSync(path.resolve("src/main/watch.js"), path.join(__dirname, "..", "build", "watch.js"))
85
86
  copyFileSync(path.resolve("node_modules/node-unrar-js/esm/js/unrar.wasm"), path.join(__dirname, "..", "build", "unrar.wasm"))
86
87
  // 因为不一定不是windows环境 所以都复制一下,发布npm 在windows环境下,不然没有这个dll
87
88
  // copyFiles(path.resolve("node_modules/@xiaobaidadada/node-tuntap2-wintun/wintun_dll"),path.join(__dirname, "..", "build"))
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ require("../build/watch.js");