syncast-cli 0.1.0 → 0.1.2
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 +865 -58
- 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 +863 -33
- package/dist/ws-server.d.ts +106 -0
- package/package.json +8 -2
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 文件传输管理器
|
|
3
|
+
*
|
|
4
|
+
* 处理文件的分片传输(上传和下载)
|
|
5
|
+
*/
|
|
6
|
+
import { type ErrorCode } from "local-sync-protocol";
|
|
7
|
+
export interface FileTransferEvents {
|
|
8
|
+
onChunk: (requestId: string, index: number, total: number, data: string) => void;
|
|
9
|
+
onComplete: (requestId: string, path: string) => void;
|
|
10
|
+
/** 文件保存成功(接收文件时) */
|
|
11
|
+
onFileSaved: (requestId: string, path: string) => void;
|
|
12
|
+
onError: (requestId: string, code: ErrorCode, message: string) => void;
|
|
13
|
+
/** 开始接收文件(用于通知 FileWatcher 忽略) */
|
|
14
|
+
onReceiveStart?: (relativePath: string) => void;
|
|
15
|
+
/** 接收完成(用于通知 FileWatcher 可以处理了) */
|
|
16
|
+
onReceiveEnd?: (relativePath: string) => void;
|
|
17
|
+
}
|
|
18
|
+
export declare class FileTransferManager {
|
|
19
|
+
private rootPath;
|
|
20
|
+
private events;
|
|
21
|
+
private pendingReceives;
|
|
22
|
+
private activeSends;
|
|
23
|
+
constructor(rootPath: string, events: FileTransferEvents);
|
|
24
|
+
/**
|
|
25
|
+
* 发送文件到前端(分片)
|
|
26
|
+
*/
|
|
27
|
+
sendFile(requestId: string, relativePath: string): Promise<void>;
|
|
28
|
+
/**
|
|
29
|
+
* 准备接收文件
|
|
30
|
+
*/
|
|
31
|
+
receiveFile(requestId: string, relativePath: string, totalChunks: number, fileSize: number): Promise<void>;
|
|
32
|
+
/**
|
|
33
|
+
* 处理接收到的分片
|
|
34
|
+
*/
|
|
35
|
+
handleChunk(requestId: string, index: number, base64Data: string): Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* 处理传输完成信号
|
|
38
|
+
*/
|
|
39
|
+
handleTransferComplete(requestId: string): Promise<void>;
|
|
40
|
+
/**
|
|
41
|
+
* 组装分片并保存文件
|
|
42
|
+
*/
|
|
43
|
+
private assembleAndSave;
|
|
44
|
+
/**
|
|
45
|
+
* 取消传输
|
|
46
|
+
*/
|
|
47
|
+
cancelTransfer(requestId: string): Promise<void>;
|
|
48
|
+
/**
|
|
49
|
+
* 获取待处理的传输数量
|
|
50
|
+
*/
|
|
51
|
+
getPendingCount(): number;
|
|
52
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 文件系统监听器
|
|
3
|
+
*
|
|
4
|
+
* 使用 chokidar 监听同步文件夹的变化,
|
|
5
|
+
* 过滤 config.json 和不支持的文件类型。
|
|
6
|
+
*/
|
|
7
|
+
import { type FileInfo, type FolderInfo, type FolderSnapshot } from "local-sync-protocol";
|
|
8
|
+
export interface FileWatcherEvents {
|
|
9
|
+
onFileAdded: (file: FileInfo) => void;
|
|
10
|
+
onFilesAdded: (files: FileInfo[]) => void;
|
|
11
|
+
onFileRemoved: (path: string) => void;
|
|
12
|
+
onFolderAdded: (folder: FolderInfo) => void;
|
|
13
|
+
onFolderRemoved: (path: string) => void;
|
|
14
|
+
}
|
|
15
|
+
export declare class FileWatcher {
|
|
16
|
+
private rootPath;
|
|
17
|
+
private watcher;
|
|
18
|
+
private events;
|
|
19
|
+
private fileCollector;
|
|
20
|
+
private processingFiles;
|
|
21
|
+
constructor(rootPath: string, events: FileWatcherEvents);
|
|
22
|
+
/**
|
|
23
|
+
* 扫描文件夹,返回快照
|
|
24
|
+
*/
|
|
25
|
+
scan(): Promise<FolderSnapshot>;
|
|
26
|
+
/**
|
|
27
|
+
* 递归扫描目录
|
|
28
|
+
*/
|
|
29
|
+
private scanDirectory;
|
|
30
|
+
/**
|
|
31
|
+
* 获取文件信息
|
|
32
|
+
*/
|
|
33
|
+
private getFileInfo;
|
|
34
|
+
/**
|
|
35
|
+
* 获取文件夹信息
|
|
36
|
+
*/
|
|
37
|
+
private getFolderInfo;
|
|
38
|
+
/**
|
|
39
|
+
* 启动监听
|
|
40
|
+
*/
|
|
41
|
+
start(): Promise<void>;
|
|
42
|
+
/**
|
|
43
|
+
* 停止监听
|
|
44
|
+
*/
|
|
45
|
+
stop(): Promise<void>;
|
|
46
|
+
/**
|
|
47
|
+
* 处理文件新增
|
|
48
|
+
*/
|
|
49
|
+
private handleFileAdd;
|
|
50
|
+
/**
|
|
51
|
+
* 处理文件删除
|
|
52
|
+
*/
|
|
53
|
+
private handleFileRemove;
|
|
54
|
+
/**
|
|
55
|
+
* 处理文件夹新增
|
|
56
|
+
*/
|
|
57
|
+
private handleDirAdd;
|
|
58
|
+
/**
|
|
59
|
+
* 处理文件夹删除
|
|
60
|
+
*/
|
|
61
|
+
private handleDirRemove;
|
|
62
|
+
/**
|
|
63
|
+
* 写入 config.json 并设置隐藏属性
|
|
64
|
+
*/
|
|
65
|
+
writeConfig(relativePath: string, assetId?: string, folderId?: string, originalFilename?: string, md5?: string): Promise<void>;
|
|
66
|
+
/**
|
|
67
|
+
* 设置文件隐藏属性
|
|
68
|
+
* macOS: 使用 chflags hidden
|
|
69
|
+
* Windows: 使用 attrib +h (如果需要支持)
|
|
70
|
+
*/
|
|
71
|
+
private setHiddenAttribute;
|
|
72
|
+
/**
|
|
73
|
+
* 标记文件正在处理(防止重复)
|
|
74
|
+
*/
|
|
75
|
+
markProcessing(relativePath: string): void;
|
|
76
|
+
/**
|
|
77
|
+
* 取消标记
|
|
78
|
+
*/
|
|
79
|
+
unmarkProcessing(relativePath: string): void;
|
|
80
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,13 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Syncast CLI - Main library exports
|
|
3
3
|
*/
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
export interface Server {
|
|
9
|
-
start(): Promise<void>;
|
|
10
|
-
stop(): Promise<void>;
|
|
11
|
-
}
|
|
12
|
-
export declare function createServer(options?: ServerOptions): Promise<Server>;
|
|
4
|
+
export { SyncServer, type SyncServerOptions, type SyncServerEvents } from "./ws-server.js";
|
|
5
|
+
export { FileWatcher, type FileWatcherEvents } from "./file-watcher.js";
|
|
6
|
+
export { FileTransferManager, type FileTransferEvents } from "./file-transfer.js";
|
|
7
|
+
export { DEFAULT_PORT, DEFAULT_HOST, PROTOCOL_VERSION, type FileInfo, type FolderInfo, type FolderSnapshot, } from "local-sync-protocol";
|
|
13
8
|
export { runCli } from "./cli.js";
|