filepizza-client 0.1.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/README.md +20 -0
- package/dist/download-helper.d.ts +7 -0
- package/dist/download-helper.js +75 -0
- package/dist/download-helper.js.map +1 -0
- package/dist/event-emitter.d.ts +24 -0
- package/dist/event-emitter.js +64 -0
- package/dist/event-emitter.js.map +1 -0
- package/dist/filepizza-downloader.d.ts +159 -0
- package/dist/filepizza-downloader.js +687 -0
- package/dist/filepizza-downloader.js.map +1 -0
- package/dist/filepizza-uploader.d.ts +138 -0
- package/dist/filepizza-uploader.js +566 -0
- package/dist/filepizza-uploader.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +76 -0
- package/dist/types.js +34 -0
- package/dist/types.js.map +1 -0
- package/package.json +53 -0
|
@@ -0,0 +1,566 @@
|
|
|
1
|
+
import Peer from 'peerjs';
|
|
2
|
+
import { EventEmitter } from './event-emitter';
|
|
3
|
+
import { ConnectionStatus, MessageType } from './types';
|
|
4
|
+
/**
|
|
5
|
+
* FilePizza Uploader - connects to the FilePizza server and uploads files
|
|
6
|
+
*/
|
|
7
|
+
export class FilePizzaUploader extends EventEmitter {
|
|
8
|
+
/**
|
|
9
|
+
* Create a new FilePizza uploader
|
|
10
|
+
* @param options Configuration options
|
|
11
|
+
*/
|
|
12
|
+
constructor(options = {}) {
|
|
13
|
+
super();
|
|
14
|
+
this.connections = new Map();
|
|
15
|
+
this.connectionInfoMap = new Map();
|
|
16
|
+
this.files = [];
|
|
17
|
+
this.filePizzaServerUrl = options.filePizzaServerUrl || 'http://localhost:8081';
|
|
18
|
+
this.password = options.password;
|
|
19
|
+
this.sharedSlug = options.sharedSlug;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Initialize the uploader
|
|
23
|
+
*/
|
|
24
|
+
async initialize() {
|
|
25
|
+
if (this.peer) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
// Get ICE servers
|
|
29
|
+
await this.getIceServers();
|
|
30
|
+
// Initialize PeerJS
|
|
31
|
+
this.peer = new Peer({
|
|
32
|
+
config: {
|
|
33
|
+
iceServers: this.iceServers || [{ urls: 'stun:stun.l.google.com:19302' }],
|
|
34
|
+
},
|
|
35
|
+
debug: 2,
|
|
36
|
+
});
|
|
37
|
+
// Wait for peer to be ready
|
|
38
|
+
if (!this.peer.id) {
|
|
39
|
+
await new Promise((resolve) => {
|
|
40
|
+
const onOpen = () => {
|
|
41
|
+
this.peer?.off('open', onOpen);
|
|
42
|
+
resolve();
|
|
43
|
+
};
|
|
44
|
+
this.peer?.on('open', onOpen);
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
// Set up connection handling
|
|
48
|
+
this.peer.on('connection', this.handleConnection.bind(this));
|
|
49
|
+
// Create channel
|
|
50
|
+
if (this.peer.id) {
|
|
51
|
+
await this.createChannel(this.peer.id, this.sharedSlug || undefined);
|
|
52
|
+
this.startChannelRenewal();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
setPassword(password) {
|
|
56
|
+
this.password = password;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Set files to be shared
|
|
60
|
+
*/
|
|
61
|
+
setFiles(files) {
|
|
62
|
+
this.files = Array.from(files);
|
|
63
|
+
// Update file info for existing connections
|
|
64
|
+
if (this.files.length > 0) {
|
|
65
|
+
for (const [_, connection] of this.connections.entries()) {
|
|
66
|
+
if (connection.status === ConnectionStatus.Ready) {
|
|
67
|
+
connection.dataConnection.send({
|
|
68
|
+
type: MessageType.Info,
|
|
69
|
+
files: this.getFileInfo(),
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Get shareable links for the current channel
|
|
77
|
+
*/
|
|
78
|
+
getShareableLinks() {
|
|
79
|
+
if (!this.channelInfo) {
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
return {
|
|
83
|
+
long: `${this.filePizzaServerUrl}/download/${this.channelInfo.longSlug}`,
|
|
84
|
+
short: `${this.filePizzaServerUrl}/download/${this.channelInfo.shortSlug}`,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Stop sharing and clean up
|
|
89
|
+
*/
|
|
90
|
+
async stop() {
|
|
91
|
+
// Stop channel renewal
|
|
92
|
+
if (this.renewalTimer) {
|
|
93
|
+
clearTimeout(this.renewalTimer);
|
|
94
|
+
this.renewalTimer = undefined;
|
|
95
|
+
}
|
|
96
|
+
// Destroy channel if we have one
|
|
97
|
+
if (this.channelInfo) {
|
|
98
|
+
try {
|
|
99
|
+
await this.destroyChannel(this.channelInfo.shortSlug);
|
|
100
|
+
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
console.error('Error destroying channel:', error);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
// Close all connections
|
|
106
|
+
for (const [_, connection] of this.connections.entries()) {
|
|
107
|
+
if (connection.dataConnection.open) {
|
|
108
|
+
connection.dataConnection.close();
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
// Clear connections
|
|
112
|
+
this.connections.clear();
|
|
113
|
+
// Destroy peer
|
|
114
|
+
if (this.peer) {
|
|
115
|
+
this.peer.destroy();
|
|
116
|
+
this.peer = undefined;
|
|
117
|
+
}
|
|
118
|
+
// Reset state
|
|
119
|
+
this.channelInfo = undefined;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Get ICE servers from the FilePizza server
|
|
123
|
+
*/
|
|
124
|
+
async getIceServers() {
|
|
125
|
+
try {
|
|
126
|
+
const response = await fetch(`${this.filePizzaServerUrl}/api/ice`, {
|
|
127
|
+
method: 'POST',
|
|
128
|
+
});
|
|
129
|
+
if (!response.ok) {
|
|
130
|
+
throw new Error(`Failed to get ICE servers: ${response.status}`);
|
|
131
|
+
}
|
|
132
|
+
const data = await response.json();
|
|
133
|
+
this.iceServers = data.iceServers;
|
|
134
|
+
return data.iceServers;
|
|
135
|
+
}
|
|
136
|
+
catch (error) {
|
|
137
|
+
console.error('Error getting ICE servers:', error);
|
|
138
|
+
return [{ urls: 'stun:stun.l.google.com:19302' }];
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Create a new channel on the FilePizza server
|
|
143
|
+
*/
|
|
144
|
+
async createChannel(uploaderPeerID, sharedSlug) {
|
|
145
|
+
try {
|
|
146
|
+
const payload = { uploaderPeerID };
|
|
147
|
+
if (sharedSlug) {
|
|
148
|
+
payload.sharedSlug = sharedSlug;
|
|
149
|
+
}
|
|
150
|
+
const response = await fetch(`${this.filePizzaServerUrl}/api/create`, {
|
|
151
|
+
method: 'POST',
|
|
152
|
+
headers: { 'Content-Type': 'application/json' },
|
|
153
|
+
body: JSON.stringify(payload),
|
|
154
|
+
});
|
|
155
|
+
if (!response.ok) {
|
|
156
|
+
throw new Error(`Failed to create channel: ${response.status}`);
|
|
157
|
+
}
|
|
158
|
+
this.channelInfo = await response.json();
|
|
159
|
+
}
|
|
160
|
+
catch (error) {
|
|
161
|
+
console.error('Error creating channel:', error);
|
|
162
|
+
throw error;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Renew the channel to keep it alive
|
|
167
|
+
*/
|
|
168
|
+
async renewChannel() {
|
|
169
|
+
if (!this.channelInfo || !this.channelInfo.secret) {
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
try {
|
|
173
|
+
const response = await fetch(`${this.filePizzaServerUrl}/api/renew`, {
|
|
174
|
+
method: 'POST',
|
|
175
|
+
headers: { 'Content-Type': 'application/json' },
|
|
176
|
+
body: JSON.stringify({
|
|
177
|
+
slug: this.channelInfo.shortSlug,
|
|
178
|
+
secret: this.channelInfo.secret,
|
|
179
|
+
}),
|
|
180
|
+
});
|
|
181
|
+
if (!response.ok) {
|
|
182
|
+
throw new Error(`Failed to renew channel: ${response.status}`);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
catch (error) {
|
|
186
|
+
console.error('Error renewing channel:', error);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Destroy a channel
|
|
191
|
+
*/
|
|
192
|
+
async destroyChannel(slug) {
|
|
193
|
+
try {
|
|
194
|
+
const response = await fetch(`${this.filePizzaServerUrl}/api/destroy`, {
|
|
195
|
+
method: 'POST',
|
|
196
|
+
headers: { 'Content-Type': 'application/json' },
|
|
197
|
+
body: JSON.stringify({ slug }),
|
|
198
|
+
});
|
|
199
|
+
if (!response.ok) {
|
|
200
|
+
throw new Error(`Failed to destroy channel: ${response.status}`);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
catch (error) {
|
|
204
|
+
console.error('Error destroying channel:', error);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Start channel renewal
|
|
209
|
+
*/
|
|
210
|
+
startChannelRenewal() {
|
|
211
|
+
if (!this.channelInfo || !this.channelInfo.secret) {
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
// Renew every 30 minutes
|
|
215
|
+
const renewalInterval = 30 * 60 * 1000;
|
|
216
|
+
this.renewalTimer = setInterval(() => {
|
|
217
|
+
this.renewChannel();
|
|
218
|
+
}, renewalInterval);
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Handle new connection
|
|
222
|
+
*/
|
|
223
|
+
handleConnection(conn) {
|
|
224
|
+
// Ignore connections for reporting (handled separately)
|
|
225
|
+
if (conn.metadata?.type === 'report') {
|
|
226
|
+
this.emit('report', conn.peer);
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
console.log(`[FilePizzaUploader] New connection from ${conn.peer}`);
|
|
230
|
+
const connectionContext = {
|
|
231
|
+
status: ConnectionStatus.Pending,
|
|
232
|
+
dataConnection: conn,
|
|
233
|
+
fileIndex: 0,
|
|
234
|
+
filesInfo: this.getFileInfo(),
|
|
235
|
+
totalFiles: this.files.length,
|
|
236
|
+
bytesTransferred: 0,
|
|
237
|
+
totalBytes: this.getTotalBytes(),
|
|
238
|
+
currentFileProgress: 0,
|
|
239
|
+
};
|
|
240
|
+
this.connections.set(conn.peer, connectionContext);
|
|
241
|
+
// Set up event handlers
|
|
242
|
+
conn.on('data', (data) => this.handleData(conn, data));
|
|
243
|
+
conn.on('close', () => this.handleClose(conn));
|
|
244
|
+
conn.on('error', (error) => this.handleError(conn, error));
|
|
245
|
+
// Emit connection event
|
|
246
|
+
this.emit('connection', this.getConnectionInfo(conn.peer));
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Handle data messages from connection
|
|
250
|
+
*/
|
|
251
|
+
handleData(conn, data) {
|
|
252
|
+
const context = this.connections.get(conn.peer);
|
|
253
|
+
if (!context)
|
|
254
|
+
return;
|
|
255
|
+
try {
|
|
256
|
+
// WebRTC messages follow a specific format with a type field
|
|
257
|
+
const message = data;
|
|
258
|
+
switch (message.type) {
|
|
259
|
+
case MessageType.RequestInfo:
|
|
260
|
+
this.handleRequestInfo(conn, context, message);
|
|
261
|
+
break;
|
|
262
|
+
case MessageType.UsePassword:
|
|
263
|
+
this.handleUsePassword(conn, context, message);
|
|
264
|
+
break;
|
|
265
|
+
case MessageType.Start:
|
|
266
|
+
this.handleStart(conn, context, message);
|
|
267
|
+
break;
|
|
268
|
+
case MessageType.Pause:
|
|
269
|
+
this.handlePause(conn, context);
|
|
270
|
+
break;
|
|
271
|
+
case MessageType.Resume:
|
|
272
|
+
this.handleResume(conn, context, message);
|
|
273
|
+
break;
|
|
274
|
+
case MessageType.Done:
|
|
275
|
+
this.handleDone(conn, context);
|
|
276
|
+
break;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
catch (error) {
|
|
280
|
+
console.error('[FilePizzaUploader] Error handling message:', error);
|
|
281
|
+
conn.send({
|
|
282
|
+
type: MessageType.Error,
|
|
283
|
+
error: 'Failed to process message',
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Handle connection close
|
|
289
|
+
*/
|
|
290
|
+
handleClose(conn) {
|
|
291
|
+
const context = this.connections.get(conn.peer);
|
|
292
|
+
if (!context)
|
|
293
|
+
return;
|
|
294
|
+
// Update connection status
|
|
295
|
+
context.status = ConnectionStatus.Closed;
|
|
296
|
+
// Emit connection closed event
|
|
297
|
+
this.emit('disconnection', conn.peer);
|
|
298
|
+
// Remove connection
|
|
299
|
+
this.connections.delete(conn.peer);
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* Handle connection error
|
|
303
|
+
*/
|
|
304
|
+
handleError(conn, error) {
|
|
305
|
+
const context = this.connections.get(conn.peer);
|
|
306
|
+
if (!context)
|
|
307
|
+
return;
|
|
308
|
+
// Update connection status
|
|
309
|
+
context.status = ConnectionStatus.Error;
|
|
310
|
+
// Emit error event
|
|
311
|
+
this.emit('error', { connectionId: conn.peer, error });
|
|
312
|
+
// Close connection
|
|
313
|
+
if (conn.open) {
|
|
314
|
+
conn.close();
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* Handle RequestInfo message
|
|
319
|
+
*/
|
|
320
|
+
handleRequestInfo(conn, context, message) {
|
|
321
|
+
// Store browser info in connection metadata
|
|
322
|
+
this.connectionInfoMap.set(conn.connectionId, {
|
|
323
|
+
browserName: message.browserName,
|
|
324
|
+
browserVersion: message.browserVersion,
|
|
325
|
+
osName: message.osName,
|
|
326
|
+
osVersion: message.osVersion,
|
|
327
|
+
mobileVendor: message.mobileVendor,
|
|
328
|
+
mobileModel: message.mobileModel,
|
|
329
|
+
});
|
|
330
|
+
// Check if password is required
|
|
331
|
+
if (this.password) {
|
|
332
|
+
conn.send({
|
|
333
|
+
type: MessageType.PasswordRequired,
|
|
334
|
+
});
|
|
335
|
+
context.status = ConnectionStatus.Authenticating;
|
|
336
|
+
}
|
|
337
|
+
else {
|
|
338
|
+
// Send file info
|
|
339
|
+
conn.send({
|
|
340
|
+
type: MessageType.Info,
|
|
341
|
+
files: context.filesInfo,
|
|
342
|
+
});
|
|
343
|
+
context.status = ConnectionStatus.Ready;
|
|
344
|
+
}
|
|
345
|
+
// Emit connection update
|
|
346
|
+
this.emit('connectionUpdate', this.getConnectionInfo(conn.peer));
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* Handle UsePassword message
|
|
350
|
+
*/
|
|
351
|
+
handleUsePassword(conn, context, message) {
|
|
352
|
+
// Check password
|
|
353
|
+
if (message.password === this.password) {
|
|
354
|
+
// Password correct, send file info
|
|
355
|
+
conn.send({
|
|
356
|
+
type: MessageType.Info,
|
|
357
|
+
files: context.filesInfo,
|
|
358
|
+
});
|
|
359
|
+
context.status = ConnectionStatus.Ready;
|
|
360
|
+
}
|
|
361
|
+
else {
|
|
362
|
+
// Password incorrect
|
|
363
|
+
conn.send({
|
|
364
|
+
type: MessageType.PasswordRequired,
|
|
365
|
+
errorMessage: 'Incorrect password',
|
|
366
|
+
});
|
|
367
|
+
context.status = ConnectionStatus.InvalidPassword;
|
|
368
|
+
}
|
|
369
|
+
// Emit connection update
|
|
370
|
+
this.emit('connectionUpdate', this.getConnectionInfo(conn.peer));
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
373
|
+
* Handle Start message
|
|
374
|
+
*/
|
|
375
|
+
handleStart(conn, context, message) {
|
|
376
|
+
// Find the requested file
|
|
377
|
+
const fileName = message.fileName;
|
|
378
|
+
const offset = message.offset;
|
|
379
|
+
const file = this.findFile(fileName);
|
|
380
|
+
if (!file) {
|
|
381
|
+
conn.send({
|
|
382
|
+
type: MessageType.Error,
|
|
383
|
+
error: `File not found: ${fileName}`,
|
|
384
|
+
});
|
|
385
|
+
return;
|
|
386
|
+
}
|
|
387
|
+
// Update connection status
|
|
388
|
+
context.status = ConnectionStatus.Uploading;
|
|
389
|
+
context.uploadingFileName = fileName;
|
|
390
|
+
context.uploadingOffset = offset;
|
|
391
|
+
// Emit status update
|
|
392
|
+
this.emit('connectionUpdate', this.getConnectionInfo(conn.peer));
|
|
393
|
+
// Begin sending file chunks
|
|
394
|
+
this.sendFileChunks(conn, context, file, offset);
|
|
395
|
+
}
|
|
396
|
+
/**
|
|
397
|
+
* Handle Pause message
|
|
398
|
+
*/
|
|
399
|
+
handlePause(conn, context) {
|
|
400
|
+
context.status = ConnectionStatus.Paused;
|
|
401
|
+
this.emit('connectionUpdate', this.getConnectionInfo(conn.peer));
|
|
402
|
+
}
|
|
403
|
+
/**
|
|
404
|
+
* Handle Resume message
|
|
405
|
+
*/
|
|
406
|
+
handleResume(conn, context, message) {
|
|
407
|
+
const fileName = message.fileName;
|
|
408
|
+
const offset = message.offset;
|
|
409
|
+
const file = this.findFile(fileName);
|
|
410
|
+
if (!file) {
|
|
411
|
+
conn.send({
|
|
412
|
+
type: MessageType.Error,
|
|
413
|
+
error: `File not found: ${fileName}`,
|
|
414
|
+
});
|
|
415
|
+
return;
|
|
416
|
+
}
|
|
417
|
+
context.status = ConnectionStatus.Uploading;
|
|
418
|
+
context.uploadingFileName = fileName;
|
|
419
|
+
context.uploadingOffset = offset;
|
|
420
|
+
this.emit('connectionUpdate', this.getConnectionInfo(conn.peer));
|
|
421
|
+
this.sendFileChunks(conn, context, file, offset);
|
|
422
|
+
}
|
|
423
|
+
/**
|
|
424
|
+
* Handle Done message
|
|
425
|
+
*/
|
|
426
|
+
handleDone(conn, context) {
|
|
427
|
+
context.status = ConnectionStatus.Done;
|
|
428
|
+
this.emit('connectionUpdate', this.getConnectionInfo(conn.peer));
|
|
429
|
+
conn.close();
|
|
430
|
+
}
|
|
431
|
+
/**
|
|
432
|
+
* Send file chunks to the downloader
|
|
433
|
+
*/
|
|
434
|
+
sendFileChunks(conn, context, file, startOffset) {
|
|
435
|
+
let offset = startOffset;
|
|
436
|
+
const CHUNK_SIZE = 256 * 1024; // 256 KB
|
|
437
|
+
const sendNextChunk = () => {
|
|
438
|
+
// Check if connection is still open and in uploading state
|
|
439
|
+
if (!conn.open || context.status !== ConnectionStatus.Uploading) {
|
|
440
|
+
return;
|
|
441
|
+
}
|
|
442
|
+
const end = Math.min(file.size, offset + CHUNK_SIZE);
|
|
443
|
+
const chunkSize = end - offset;
|
|
444
|
+
const final = end >= file.size;
|
|
445
|
+
// Create chunk
|
|
446
|
+
const chunk = file.slice(offset, end);
|
|
447
|
+
// Send chunk
|
|
448
|
+
conn.send({
|
|
449
|
+
type: MessageType.Chunk,
|
|
450
|
+
fileName: file.name,
|
|
451
|
+
offset,
|
|
452
|
+
bytes: chunk,
|
|
453
|
+
final,
|
|
454
|
+
});
|
|
455
|
+
// Update progress
|
|
456
|
+
offset = end;
|
|
457
|
+
context.uploadingOffset = offset;
|
|
458
|
+
context.currentFileProgress = offset / file.size;
|
|
459
|
+
context.bytesTransferred += chunkSize;
|
|
460
|
+
// Emit progress update
|
|
461
|
+
this.emit('progress', this.getProgressInfo(conn.peer));
|
|
462
|
+
// If this was the final chunk
|
|
463
|
+
if (final) {
|
|
464
|
+
if (context.fileIndex < context.totalFiles - 1) {
|
|
465
|
+
// Move to next file
|
|
466
|
+
context.fileIndex++;
|
|
467
|
+
context.currentFileProgress = 0;
|
|
468
|
+
context.status = ConnectionStatus.Ready;
|
|
469
|
+
// Emit update
|
|
470
|
+
this.emit('connectionUpdate', this.getConnectionInfo(conn.peer));
|
|
471
|
+
}
|
|
472
|
+
else {
|
|
473
|
+
// All files completed
|
|
474
|
+
context.fileIndex = context.totalFiles;
|
|
475
|
+
context.currentFileProgress = 1;
|
|
476
|
+
context.status = ConnectionStatus.Done;
|
|
477
|
+
// Emit update
|
|
478
|
+
this.emit('connectionUpdate', this.getConnectionInfo(conn.peer));
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
else {
|
|
482
|
+
// Schedule next chunk
|
|
483
|
+
setTimeout(sendNextChunk, 0);
|
|
484
|
+
}
|
|
485
|
+
};
|
|
486
|
+
// Start sending chunks
|
|
487
|
+
sendNextChunk();
|
|
488
|
+
}
|
|
489
|
+
/**
|
|
490
|
+
* Find a file by name
|
|
491
|
+
*/
|
|
492
|
+
findFile(fileName) {
|
|
493
|
+
return this.files.find(file => file.name === fileName);
|
|
494
|
+
}
|
|
495
|
+
/**
|
|
496
|
+
* Get file info for all files
|
|
497
|
+
*/
|
|
498
|
+
getFileInfo() {
|
|
499
|
+
return this.files.map(file => ({
|
|
500
|
+
fileName: file.name,
|
|
501
|
+
size: file.size,
|
|
502
|
+
type: file.type,
|
|
503
|
+
}));
|
|
504
|
+
}
|
|
505
|
+
/**
|
|
506
|
+
* Get connection info for a specific connection
|
|
507
|
+
*/
|
|
508
|
+
getConnectionInfo(peerId) {
|
|
509
|
+
const context = this.connections.get(peerId);
|
|
510
|
+
if (!context) {
|
|
511
|
+
throw new Error(`Connection not found: ${peerId}`);
|
|
512
|
+
}
|
|
513
|
+
return {
|
|
514
|
+
id: peerId,
|
|
515
|
+
status: context.status,
|
|
516
|
+
browserName: context.dataConnection.metadata?.browserName,
|
|
517
|
+
browserVersion: context.dataConnection.metadata?.browserVersion,
|
|
518
|
+
osName: context.dataConnection.metadata?.osName,
|
|
519
|
+
osVersion: context.dataConnection.metadata?.osVersion,
|
|
520
|
+
mobileVendor: context.dataConnection.metadata?.mobileVendor,
|
|
521
|
+
mobileModel: context.dataConnection.metadata?.mobileModel,
|
|
522
|
+
};
|
|
523
|
+
}
|
|
524
|
+
/**
|
|
525
|
+
* Get connection info for all connections
|
|
526
|
+
*/
|
|
527
|
+
getConnectionInfoAll() {
|
|
528
|
+
const connectionInfos = [];
|
|
529
|
+
for (const [peerId, context] of this.connections.entries()) {
|
|
530
|
+
const connectionInfo = this.getConnectionInfo(peerId);
|
|
531
|
+
connectionInfos.push(connectionInfo);
|
|
532
|
+
}
|
|
533
|
+
return connectionInfos;
|
|
534
|
+
}
|
|
535
|
+
/**
|
|
536
|
+
* Remove connection info
|
|
537
|
+
*/
|
|
538
|
+
removeConnectionInfo(connectionId) {
|
|
539
|
+
this.connectionInfoMap.delete(connectionId);
|
|
540
|
+
}
|
|
541
|
+
/**
|
|
542
|
+
* Get total bytes for all files
|
|
543
|
+
*/
|
|
544
|
+
getTotalBytes() {
|
|
545
|
+
return this.files.reduce((total, file) => total + file.size, 0);
|
|
546
|
+
}
|
|
547
|
+
/**
|
|
548
|
+
* Get progress info for a specific connection
|
|
549
|
+
*/
|
|
550
|
+
getProgressInfo(peerId) {
|
|
551
|
+
const context = this.connections.get(peerId);
|
|
552
|
+
if (!context) {
|
|
553
|
+
throw new Error(`Connection not found: ${peerId}`);
|
|
554
|
+
}
|
|
555
|
+
return {
|
|
556
|
+
fileIndex: context.fileIndex,
|
|
557
|
+
fileName: context.uploadingFileName || '',
|
|
558
|
+
totalFiles: context.totalFiles,
|
|
559
|
+
currentFileProgress: context.currentFileProgress,
|
|
560
|
+
overallProgress: context.bytesTransferred / context.totalBytes,
|
|
561
|
+
bytesTransferred: context.bytesTransferred,
|
|
562
|
+
totalBytes: context.totalBytes,
|
|
563
|
+
};
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
//# sourceMappingURL=filepizza-uploader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filepizza-uploader.js","sourceRoot":"","sources":["../src/filepizza-uploader.ts"],"names":[],"mappings":"AAAA,OAAO,IAAwB,MAAM,QAAQ,CAAA;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAC9C,OAAO,EAA0C,gBAAgB,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEhG;;GAEG;AACH,MAAM,OAAO,iBAAkB,SAAQ,YAAY;IAYjD;;;OAGG;IACH,YAAY,UAIR,EAAE;QACJ,KAAK,EAAE,CAAC;QAnBF,gBAAW,GAAqB,IAAI,GAAG,EAAE,CAAC;QAC1C,sBAAiB,GAAG,IAAI,GAAG,EAAe,CAAC;QAC3C,U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AAC,CAAC,CAAC;IAClE,CAAC;IAED;;OAEG;IACK,eAAe,CAAC,MAAc;QACpC,MAAM,OAAO,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QAC7C,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,MAAM,IAAI,KAAK,CAAC,yBAAyB,MAAM,EAAE,CAAC,CAAC;QACrD,CAAC;QAED,OAAO;YACL,SAAS,EAAE,OAAO,CAAC,SAAS;YAC5B,QAAQ,EAAE,OAAO,CAAC,iBAAiB,IAAI,EAAE;YACzC,UAAU,EAAE,OAAO,CAAC,UAAU;YAC9B,mBAAmB,EAAE,OAAO,CAAC,mBAAmB;YAChD,eAAe,EAAE,OAAO,CAAC,gBAAgB,GAAG,OAAO,CAAC,UAAU;YAC9D,gBAAgB,EAAE,OAAO,CAAC,gBAAgB;YAC1C,UAAU,EAAE,OAAO,CAAC,UAAU;SAC/B,CAAC;IACJ,CAAC;CACF"}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
export * from './types';
|
|
3
|
+
export { EventEmitter } from './event-emitter';
|
|
4
|
+
export { DownloadHelper } from './download-helper';
|
|
5
|
+
export { FilePizzaDownloader } from './filepizza-downloader';
|
|
6
|
+
export { FilePizzaUploader } from './filepizza-uploader';
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,eAAe;AACf,cAAc,SAAS,CAAA;AAEvB,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAClD,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAA;AAC5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
export interface EventEmitter {
|
|
2
|
+
on(event: string, listener: (...args: any[]) => void): this;
|
|
3
|
+
off(event: string, listener: (...args: any[]) => void): this;
|
|
4
|
+
emit(event: string, ...args: any[]): boolean;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Connection status
|
|
8
|
+
*/
|
|
9
|
+
export declare enum ConnectionStatus {
|
|
10
|
+
Pending = "PENDING",
|
|
11
|
+
Ready = "READY",
|
|
12
|
+
Paused = "PAUSED",
|
|
13
|
+
Uploading = "UPLOADING",
|
|
14
|
+
Downloading = "DOWNLOADING",
|
|
15
|
+
Done = "DONE",
|
|
16
|
+
Authenticating = "AUTHENTICATING",
|
|
17
|
+
InvalidPassword = "INVALID_PASSWORD",
|
|
18
|
+
Closed = "CLOSED",
|
|
19
|
+
Error = "ERROR"
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* File information
|
|
23
|
+
*/
|
|
24
|
+
export interface FileInfo {
|
|
25
|
+
fileName: string;
|
|
26
|
+
size: number;
|
|
27
|
+
type: string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Interface for a completed file ready to download
|
|
31
|
+
*/
|
|
32
|
+
export interface CompletedFile extends FileInfo {
|
|
33
|
+
data: Uint8Array;
|
|
34
|
+
downloadUrl?: string;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Progress information
|
|
38
|
+
*/
|
|
39
|
+
export interface ProgressInfo {
|
|
40
|
+
fileIndex: number;
|
|
41
|
+
fileName: string;
|
|
42
|
+
totalFiles: number;
|
|
43
|
+
currentFileProgress: number;
|
|
44
|
+
overallProgress: number;
|
|
45
|
+
bytesTransferred: number;
|
|
46
|
+
totalBytes: number;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Connection information
|
|
50
|
+
*/
|
|
51
|
+
export interface ConnectionInfo {
|
|
52
|
+
id: string;
|
|
53
|
+
status: ConnectionStatus;
|
|
54
|
+
browserName?: string;
|
|
55
|
+
browserVersion?: string;
|
|
56
|
+
osName?: string;
|
|
57
|
+
osVersion?: string;
|
|
58
|
+
mobileVendor?: string;
|
|
59
|
+
mobileModel?: string;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Message types for peer-to-peer communication
|
|
63
|
+
*/
|
|
64
|
+
export declare enum MessageType {
|
|
65
|
+
RequestInfo = "RequestInfo",
|
|
66
|
+
Info = "Info",
|
|
67
|
+
Start = "Start",
|
|
68
|
+
Chunk = "Chunk",
|
|
69
|
+
Pause = "Pause",
|
|
70
|
+
Resume = "Resume",
|
|
71
|
+
Done = "Done",
|
|
72
|
+
Error = "Error",
|
|
73
|
+
PasswordRequired = "PasswordRequired",
|
|
74
|
+
UsePassword = "UsePassword",
|
|
75
|
+
Report = "Report"
|
|
76
|
+
}
|