syncast-cli 0.1.0 → 0.1.1
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/dist/cli.js +740 -59
- package/dist/file-transfer.d.ts +52 -0
- package/dist/file-watcher.d.ts +80 -0
- package/dist/index.d.ts +4 -9
- package/dist/index.js +738 -35
- package/dist/ws-server.d.ts +106 -0
- package/package.json +8 -2
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WebSocket 服务器核心
|
|
3
|
+
*
|
|
4
|
+
* 处理与前端的 WebSocket 连接和消息通信
|
|
5
|
+
*/
|
|
6
|
+
import { type WebSocket } from "ws";
|
|
7
|
+
export interface SyncServerOptions {
|
|
8
|
+
port?: number;
|
|
9
|
+
host?: string;
|
|
10
|
+
}
|
|
11
|
+
export interface SyncServerEvents {
|
|
12
|
+
onClientConnected?: (client: WebSocket) => void;
|
|
13
|
+
onClientDisconnected?: (client: WebSocket) => void;
|
|
14
|
+
onError?: (error: Error) => void;
|
|
15
|
+
}
|
|
16
|
+
export declare class SyncServer {
|
|
17
|
+
private wss;
|
|
18
|
+
private client;
|
|
19
|
+
private fileWatcher;
|
|
20
|
+
private fileTransfer;
|
|
21
|
+
private port;
|
|
22
|
+
private host;
|
|
23
|
+
private cwd;
|
|
24
|
+
private syncFolder;
|
|
25
|
+
private events;
|
|
26
|
+
private messageQueue;
|
|
27
|
+
private isProcessingQueue;
|
|
28
|
+
private currentProjectId;
|
|
29
|
+
constructor(options?: SyncServerOptions, events?: SyncServerEvents);
|
|
30
|
+
/**
|
|
31
|
+
* 启动 WebSocket 服务器
|
|
32
|
+
*/
|
|
33
|
+
start(): Promise<void>;
|
|
34
|
+
/**
|
|
35
|
+
* 停止服务器
|
|
36
|
+
*/
|
|
37
|
+
stop(): Promise<void>;
|
|
38
|
+
/**
|
|
39
|
+
* 处理新的 WebSocket 连接
|
|
40
|
+
*/
|
|
41
|
+
private handleConnection;
|
|
42
|
+
/**
|
|
43
|
+
* 处理项目注册
|
|
44
|
+
*/
|
|
45
|
+
private handleProjectRegistration;
|
|
46
|
+
/**
|
|
47
|
+
* 清理连接相关状态
|
|
48
|
+
*/
|
|
49
|
+
private cleanupConnection;
|
|
50
|
+
/**
|
|
51
|
+
* 处理前端消息
|
|
52
|
+
*/
|
|
53
|
+
private handleMessage;
|
|
54
|
+
/**
|
|
55
|
+
* 列出目录内容
|
|
56
|
+
*/
|
|
57
|
+
private handleListDirectory;
|
|
58
|
+
/**
|
|
59
|
+
* 选择同步文件夹
|
|
60
|
+
*/
|
|
61
|
+
private handleSelectFolder;
|
|
62
|
+
/**
|
|
63
|
+
* 处理文件请求(前端请求下载本地文件)
|
|
64
|
+
*/
|
|
65
|
+
private handleRequestFile;
|
|
66
|
+
/**
|
|
67
|
+
* 处理前端发送文件(前端上传文件到本地)
|
|
68
|
+
*/
|
|
69
|
+
private handleSendFile;
|
|
70
|
+
/**
|
|
71
|
+
* 处理文件分片
|
|
72
|
+
*/
|
|
73
|
+
private handleFileChunk;
|
|
74
|
+
/**
|
|
75
|
+
* 处理传输完成
|
|
76
|
+
*/
|
|
77
|
+
private handleFileTransferComplete;
|
|
78
|
+
/**
|
|
79
|
+
* 写入 config.json
|
|
80
|
+
*/
|
|
81
|
+
private handleWriteConfig;
|
|
82
|
+
/**
|
|
83
|
+
* 取消传输
|
|
84
|
+
*/
|
|
85
|
+
private handleCancelTransfer;
|
|
86
|
+
/**
|
|
87
|
+
* 发送消息给客户端
|
|
88
|
+
*/
|
|
89
|
+
private send;
|
|
90
|
+
/**
|
|
91
|
+
* 获取服务器地址
|
|
92
|
+
*/
|
|
93
|
+
getAddress(): string;
|
|
94
|
+
/**
|
|
95
|
+
* 检查是否有客户端连接
|
|
96
|
+
*/
|
|
97
|
+
isClientConnected(): boolean;
|
|
98
|
+
/**
|
|
99
|
+
* 将消息加入队列
|
|
100
|
+
*/
|
|
101
|
+
private enqueueMessage;
|
|
102
|
+
/**
|
|
103
|
+
* 处理消息队列(确保顺序执行)
|
|
104
|
+
*/
|
|
105
|
+
private processQueue;
|
|
106
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "syncast-cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Syncast CLI tool",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -32,12 +32,18 @@
|
|
|
32
32
|
"author": "",
|
|
33
33
|
"license": "MIT",
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"
|
|
35
|
+
"chokidar": "^4.0.3",
|
|
36
|
+
"commander": "^13.1.0",
|
|
37
|
+
"local-sync-protocol": "workspace:*",
|
|
38
|
+
"mime-types": "^2.1.35",
|
|
39
|
+
"ws": "^8.18.0"
|
|
36
40
|
},
|
|
37
41
|
"devDependencies": {
|
|
38
42
|
"@biomejs/biome": "2.3.2",
|
|
39
43
|
"@rslib/core": "^0.15.0",
|
|
44
|
+
"@types/mime-types": "^2.1.4",
|
|
40
45
|
"@types/node": "^22.18.6",
|
|
46
|
+
"@types/ws": "^8.5.13",
|
|
41
47
|
"typescript": "^5.9.2"
|
|
42
48
|
}
|
|
43
49
|
}
|