egos-transfer 0.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/.lintstagedrc.json +3 -0
- package/.prettierrc +7 -0
- package/.watchmanconfig +6 -0
- package/README.md +343 -0
- package/dist/constant.d.ts +13 -0
- package/dist/constant.js +16 -0
- package/dist/entity.d.ts +159 -0
- package/dist/entity.js +164 -0
- package/dist/file-transfer.d.ts +81 -0
- package/dist/file-transfer.js +476 -0
- package/dist/handler.d.ts +42 -0
- package/dist/handler.js +369 -0
- package/dist/helper.d.ts +2 -0
- package/dist/helper.js +12 -0
- package/dist/http-transfer.d.ts +46 -0
- package/dist/http-transfer.js +243 -0
- package/dist/http-transformer.d.ts +3 -0
- package/dist/http-transformer.js +20 -0
- package/dist/index.d.ts +95 -0
- package/dist/index.js +665 -0
- package/dist/interfaces.d.ts +362 -0
- package/dist/interfaces.js +2 -0
- package/dist/locker.d.ts +115 -0
- package/dist/locker.js +245 -0
- package/dist/router.d.ts +62 -0
- package/dist/router.js +191 -0
- package/dist/server.d.ts +29 -0
- package/dist/server.js +77 -0
- package/dist/utils.d.ts +92 -0
- package/dist/utils.js +333 -0
- package/package.json +42 -0
- package/src/constant.ts +14 -0
- package/src/entity.ts +201 -0
- package/src/file-transfer.ts +517 -0
- package/src/handler.ts +413 -0
- package/src/helper.ts +8 -0
- package/src/http-transfer.ts +261 -0
- package/src/http-transformer.ts +20 -0
- package/src/index.ts +732 -0
- package/src/interfaces.ts +420 -0
- package/src/locker.ts +322 -0
- package/src/router.ts +243 -0
- package/src/server.ts +83 -0
- package/src/utils.ts +386 -0
- package/tsconfig.json +28 -0
|
@@ -0,0 +1,420 @@
|
|
|
1
|
+
import {
|
|
2
|
+
InternalApi,
|
|
3
|
+
MessageStatus,
|
|
4
|
+
NetworkQuality,
|
|
5
|
+
PeerAction,
|
|
6
|
+
TransferError,
|
|
7
|
+
TransferPriority,
|
|
8
|
+
} from './entity';
|
|
9
|
+
|
|
10
|
+
import { DataConnection } from 'peerjs';
|
|
11
|
+
|
|
12
|
+
export type PeerOnOpen = (peerId: string) => void;
|
|
13
|
+
export type PeerOnData = (data: string) => void;
|
|
14
|
+
|
|
15
|
+
export type PeerOnError = (error: Error) => void;
|
|
16
|
+
|
|
17
|
+
export type PeerOnClose = () => void;
|
|
18
|
+
|
|
19
|
+
export type PeerOnConnection = (conn: DataConnection) => void;
|
|
20
|
+
|
|
21
|
+
// Awesome: Enhanced event types
|
|
22
|
+
export type TransferProgressCallback = (progress: TransferProgress) => void;
|
|
23
|
+
export type TransferStatusCallback = (status: MessageStatus) => void;
|
|
24
|
+
export type NetworkQualityCallback = (quality: NetworkQuality) => void;
|
|
25
|
+
export type ErrorCallback = (error: TransferError) => void;
|
|
26
|
+
|
|
27
|
+
export interface IMessage {
|
|
28
|
+
src: string;
|
|
29
|
+
type: string;
|
|
30
|
+
payload: Record<string, any>;
|
|
31
|
+
dst?: string;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export type ConnectionListeners = {
|
|
35
|
+
onOpen?: PeerOnOpen;
|
|
36
|
+
onData: PeerOnData;
|
|
37
|
+
onError?: PeerOnError;
|
|
38
|
+
onClose?: PeerOnClose;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export interface PeerListeners {
|
|
42
|
+
onOpen?: PeerOnOpen;
|
|
43
|
+
onData: PeerOnData;
|
|
44
|
+
onError?: PeerOnError;
|
|
45
|
+
onClose?: PeerOnClose;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface PeerMessage {
|
|
49
|
+
id: string;
|
|
50
|
+
src: string;
|
|
51
|
+
dest: string;
|
|
52
|
+
type?: string;
|
|
53
|
+
method: string;
|
|
54
|
+
action: string;
|
|
55
|
+
route: string;
|
|
56
|
+
body: Record<string, any>;
|
|
57
|
+
error?: Record<string, any> | string;
|
|
58
|
+
createdAt: string | number;
|
|
59
|
+
requestId: string;
|
|
60
|
+
headers: Record<string, any>;
|
|
61
|
+
status?: string;
|
|
62
|
+
// Awesome: Enhanced message properties
|
|
63
|
+
priority?: TransferPriority;
|
|
64
|
+
retryCount?: number;
|
|
65
|
+
timeout?: number;
|
|
66
|
+
metadata?: Record<string, any>;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export interface FileMessageItem extends PeerMessage {
|
|
70
|
+
body: {
|
|
71
|
+
filename: string;
|
|
72
|
+
size: string;
|
|
73
|
+
path: string;
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export type PeerRequestPayload = {
|
|
78
|
+
requestId?: string;
|
|
79
|
+
body: Record<string, any>;
|
|
80
|
+
headers?: Record<string, string | number>;
|
|
81
|
+
route: string;
|
|
82
|
+
id?: string;
|
|
83
|
+
method: string;
|
|
84
|
+
timeout?: number;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
export interface FileMessageBody {
|
|
88
|
+
filename: string;
|
|
89
|
+
size: number;
|
|
90
|
+
path: string;
|
|
91
|
+
type?: string;
|
|
92
|
+
fileId?: number | string;
|
|
93
|
+
// Awesome: Enhanced file properties
|
|
94
|
+
checksum?: string;
|
|
95
|
+
lastModified?: number;
|
|
96
|
+
permissions?: string;
|
|
97
|
+
compression?: boolean;
|
|
98
|
+
encryption?: boolean;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export interface PeerFileItem {
|
|
102
|
+
id: number | string;
|
|
103
|
+
name: string;
|
|
104
|
+
mtime: number | string;
|
|
105
|
+
ctime?: number | string;
|
|
106
|
+
path: string;
|
|
107
|
+
size: number;
|
|
108
|
+
mime: string;
|
|
109
|
+
isFile: boolean;
|
|
110
|
+
isDirectory: boolean;
|
|
111
|
+
iconUrl?: string;
|
|
112
|
+
originalPath?: string;
|
|
113
|
+
createdAt?: string;
|
|
114
|
+
updatedAt?: string;
|
|
115
|
+
action?: string;
|
|
116
|
+
// Awesome: Enhanced file properties
|
|
117
|
+
checksum?: string;
|
|
118
|
+
permissions?: string;
|
|
119
|
+
owner?: string;
|
|
120
|
+
group?: string;
|
|
121
|
+
isHidden?: boolean;
|
|
122
|
+
isReadOnly?: boolean;
|
|
123
|
+
thumbnail?: string;
|
|
124
|
+
tags?: string[];
|
|
125
|
+
metadata?: Record<string, any>;
|
|
126
|
+
progress?: number;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export interface MessageTaskEntity {
|
|
130
|
+
id: number | string;
|
|
131
|
+
transId: string;
|
|
132
|
+
deviceId: string;
|
|
133
|
+
processed: (number | undefined)[];
|
|
134
|
+
status: string;
|
|
135
|
+
cacheFile: string;
|
|
136
|
+
chunkSize: number;
|
|
137
|
+
size: number;
|
|
138
|
+
mime?: string;
|
|
139
|
+
filename: string;
|
|
140
|
+
hash: string;
|
|
141
|
+
createdAt: number;
|
|
142
|
+
updatedAt?: number;
|
|
143
|
+
algorithm: string;
|
|
144
|
+
action: string;
|
|
145
|
+
resource: {
|
|
146
|
+
fileId: string | number;
|
|
147
|
+
filePath: string;
|
|
148
|
+
parent?: { path: string; parentId: number | string };
|
|
149
|
+
token?: string; // for share file
|
|
150
|
+
};
|
|
151
|
+
saved?: Record<string, string>;
|
|
152
|
+
// Awesome: Enhanced task properties
|
|
153
|
+
priority?: TransferPriority;
|
|
154
|
+
retryCount?: number;
|
|
155
|
+
maxRetries?: number;
|
|
156
|
+
startTime?: number;
|
|
157
|
+
endTime?: number;
|
|
158
|
+
bytesTransferred?: number;
|
|
159
|
+
speed?: number;
|
|
160
|
+
estimatedTimeRemaining?: number;
|
|
161
|
+
error?: TransferError;
|
|
162
|
+
metadata?: Record<string, any>;
|
|
163
|
+
tags?: string[];
|
|
164
|
+
compression?: boolean;
|
|
165
|
+
encryption?: boolean;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export type RequestCallbackFn = (conn: DataConnection, message: PeerMessage, next?: any) => any;
|
|
169
|
+
|
|
170
|
+
export interface RouteItem {
|
|
171
|
+
path: string;
|
|
172
|
+
method: string;
|
|
173
|
+
scope: number;
|
|
174
|
+
callback: RequestCallbackFn;
|
|
175
|
+
// Awesome: Enhanced route properties
|
|
176
|
+
priority?: TransferPriority;
|
|
177
|
+
timeout?: number;
|
|
178
|
+
retryOnFailure?: boolean;
|
|
179
|
+
middleware?: string[];
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export interface MiddlewareItem {
|
|
183
|
+
path: string;
|
|
184
|
+
handler: RequestCallbackFn;
|
|
185
|
+
// Awesome: Enhanced middleware properties
|
|
186
|
+
priority?: number;
|
|
187
|
+
async?: boolean;
|
|
188
|
+
errorHandler?: (error: Error) => void;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export type DataMessage = {
|
|
192
|
+
id: string;
|
|
193
|
+
src: string;
|
|
194
|
+
dest: string;
|
|
195
|
+
type: string;
|
|
196
|
+
body: Record<string, any>;
|
|
197
|
+
status: string;
|
|
198
|
+
action: PeerAction;
|
|
199
|
+
userId?: number;
|
|
200
|
+
guid?: string;
|
|
201
|
+
createdAt: number | string;
|
|
202
|
+
processed?: number;
|
|
203
|
+
// Awesome: Enhanced data message properties
|
|
204
|
+
priority?: TransferPriority;
|
|
205
|
+
retryCount?: number;
|
|
206
|
+
metadata?: Record<string, any>;
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
export interface MetaData {
|
|
210
|
+
size: number;
|
|
211
|
+
chunkSize: number;
|
|
212
|
+
fileId: string | number;
|
|
213
|
+
filePath: string;
|
|
214
|
+
hash: string;
|
|
215
|
+
algorithm: string;
|
|
216
|
+
filename: string;
|
|
217
|
+
mime?: string;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
export interface ChunkData {
|
|
221
|
+
chunkSize: number;
|
|
222
|
+
chunkNumber: number;
|
|
223
|
+
data: FormData | Uint8Array;
|
|
224
|
+
transId: string;
|
|
225
|
+
totalChunk: number;
|
|
226
|
+
http: boolean;
|
|
227
|
+
// Awesome: Enhanced chunk properties
|
|
228
|
+
checksum?: string;
|
|
229
|
+
compressed?: boolean;
|
|
230
|
+
encrypted?: boolean;
|
|
231
|
+
timestamp?: number;
|
|
232
|
+
retryCount?: number;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
export interface ApiInfo {
|
|
236
|
+
url: string;
|
|
237
|
+
token: string;
|
|
238
|
+
status: boolean;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
export interface TransferPrepareData {
|
|
242
|
+
fileId: string | number;
|
|
243
|
+
filePath: string;
|
|
244
|
+
transId: string;
|
|
245
|
+
action: string;
|
|
246
|
+
parent?: {
|
|
247
|
+
parentId: number | string;
|
|
248
|
+
path: string;
|
|
249
|
+
};
|
|
250
|
+
status?: MessageStatus;
|
|
251
|
+
mime: string;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
// Awesome: New enhanced interfaces
|
|
255
|
+
export interface TransferProgress {
|
|
256
|
+
transId: string;
|
|
257
|
+
bytesTransferred: number;
|
|
258
|
+
totalBytes: number;
|
|
259
|
+
percentage: number;
|
|
260
|
+
speed: number; // bytes per second
|
|
261
|
+
estimatedTimeRemaining: number; // seconds
|
|
262
|
+
status: MessageStatus;
|
|
263
|
+
startTime: number;
|
|
264
|
+
currentTime: number;
|
|
265
|
+
chunksProcessed: number;
|
|
266
|
+
totalChunks: number;
|
|
267
|
+
networkQuality: NetworkQuality;
|
|
268
|
+
error?: TransferError;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
export interface TransferOptions {
|
|
272
|
+
priority?: TransferPriority;
|
|
273
|
+
chunkSize?: number;
|
|
274
|
+
maxConcurrentChunks?: number;
|
|
275
|
+
retryOnFailure?: boolean;
|
|
276
|
+
maxRetries?: number;
|
|
277
|
+
verifyChecksum?: boolean;
|
|
278
|
+
compression?: boolean;
|
|
279
|
+
encryption?: boolean;
|
|
280
|
+
timeout?: number;
|
|
281
|
+
onProgress?: TransferProgressCallback;
|
|
282
|
+
onStatus?: TransferStatusCallback;
|
|
283
|
+
onError?: ErrorCallback;
|
|
284
|
+
metadata?: Record<string, any>;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
export interface BatchTransferOptions extends TransferOptions {
|
|
288
|
+
concurrent: number;
|
|
289
|
+
queuePriority: TransferPriority;
|
|
290
|
+
stopOnError: boolean;
|
|
291
|
+
resumeOnRestart: boolean;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
export interface NetworkMonitor {
|
|
295
|
+
latency: number;
|
|
296
|
+
bandwidth: number;
|
|
297
|
+
quality: NetworkQuality;
|
|
298
|
+
packetLoss: number;
|
|
299
|
+
jitter: number;
|
|
300
|
+
lastUpdated: number;
|
|
301
|
+
isStable: boolean;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
export interface TransferQueue {
|
|
305
|
+
id: string;
|
|
306
|
+
items: TransferQueueItem[];
|
|
307
|
+
maxConcurrent: number;
|
|
308
|
+
currentRunning: number;
|
|
309
|
+
paused: boolean;
|
|
310
|
+
createdAt: number;
|
|
311
|
+
updatedAt: number;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
export interface FilesResponse {
|
|
315
|
+
data: PeerFileItem[];
|
|
316
|
+
meta: Record<string, any>;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
export interface FileMetaParams {
|
|
320
|
+
transId: string;
|
|
321
|
+
fileId: string;
|
|
322
|
+
filePath: string;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
export interface FileChunkParams {
|
|
326
|
+
fileId: string | number;
|
|
327
|
+
filePath?: string;
|
|
328
|
+
transId: string;
|
|
329
|
+
chunkNumber: number;
|
|
330
|
+
chunkSize: number;
|
|
331
|
+
totalChunk: number;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
export interface FileStartParams {
|
|
335
|
+
transId: string;
|
|
336
|
+
fileId: string;
|
|
337
|
+
filePath: string;
|
|
338
|
+
deviceId: string;
|
|
339
|
+
action: string;
|
|
340
|
+
parent?: {
|
|
341
|
+
parentId: number;
|
|
342
|
+
path: string;
|
|
343
|
+
};
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
export interface ExchangeTokenParams {
|
|
347
|
+
apiInfo: InternalApi;
|
|
348
|
+
onetimeToken: string;
|
|
349
|
+
security: boolean;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
export interface GetFilesParams {
|
|
353
|
+
parent: Record<string, any>;
|
|
354
|
+
offset?: number;
|
|
355
|
+
limit?: number;
|
|
356
|
+
order?: Record<string, string>;
|
|
357
|
+
keyword?: string;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
export interface FileBasic {
|
|
361
|
+
fileId: string | number;
|
|
362
|
+
filePath: string;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
export interface FilePreviewParams {
|
|
366
|
+
fileId: string | number;
|
|
367
|
+
filePath: string;
|
|
368
|
+
thumb: boolean;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
export interface ShareParams {
|
|
372
|
+
token: string;
|
|
373
|
+
thumb?: boolean;
|
|
374
|
+
fileId: number;
|
|
375
|
+
pwd: string;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
export type TransmitFailureParams = {
|
|
379
|
+
transId: string;
|
|
380
|
+
// Awesome: Enhanced failure params
|
|
381
|
+
error?: TransferError;
|
|
382
|
+
retryable?: boolean;
|
|
383
|
+
suggestedAction?: string;
|
|
384
|
+
};
|
|
385
|
+
|
|
386
|
+
// Awesome: New utility interfaces
|
|
387
|
+
export interface DeviceInfo {
|
|
388
|
+
deviceId: string;
|
|
389
|
+
name: string;
|
|
390
|
+
platform: string;
|
|
391
|
+
version: string;
|
|
392
|
+
capabilities: string[];
|
|
393
|
+
networkStats: NetworkStats;
|
|
394
|
+
lastSeen: number;
|
|
395
|
+
isOnline: boolean;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
export interface NetworkStats {
|
|
399
|
+
latency: number;
|
|
400
|
+
bandwidth: number;
|
|
401
|
+
quality: NetworkQuality;
|
|
402
|
+
packetLoss: number;
|
|
403
|
+
jitter: number;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
export interface TransferQueueItem {
|
|
407
|
+
id: string;
|
|
408
|
+
priority: TransferPriority;
|
|
409
|
+
createdAt: number;
|
|
410
|
+
scheduledFor?: number;
|
|
411
|
+
retryCount: number;
|
|
412
|
+
maxRetries: number;
|
|
413
|
+
data: TransferPrepareData;
|
|
414
|
+
options?: TransferOptions;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
export interface IDeviceStatus {
|
|
418
|
+
deviceId: string;
|
|
419
|
+
isOnline: boolean;
|
|
420
|
+
}
|