@trap_stevo/filetide 0.0.48 → 0.0.49

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.
@@ -435,7 +435,11 @@ function _setupFileEventListeners(userID, client, onTransferProgress, onIncoming
435
435
  });
436
436
  }
437
437
  if (onIncomingFile) {
438
- onIncomingFile(verifiedSender, data, fileTransferReceiver.activeTransfers);
438
+ const taskBarStats = this.progressBarManager.getTaskBar(data.fileName);
439
+ onIncomingFile(verifiedSender, {
440
+ ...data,
441
+ stats: taskBarStats
442
+ }, fileTransferReceiver.activeTransfers);
439
443
  }
440
444
  if (verifiedSender && !fs.existsSync(saveDir)) {
441
445
  fs.mkdirSync(saveDir, {
@@ -471,7 +475,11 @@ function _setupFileEventListeners(userID, client, onTransferProgress, onIncoming
471
475
  currentTransferState.transferredSize += data.chunkSize || 512 * 1024;
472
476
  FileTransferRecoveryManager.saveTransferState(userID, data.senderName, `${data.path}-${data.fileName}`, data.chunkIndex, currentTransferState.transferredSize);
473
477
  if (onTransferProgress) {
474
- onTransferProgress(data);
478
+ const taskBarStats = this.progressBarManager.getTaskBar(data.fileName);
479
+ onTransferProgress({
480
+ ...data,
481
+ stats: taskBarStats
482
+ });
475
483
  }
476
484
  });
477
485
  client.clientTide.onEvent(userID, "transfer-status", data => {
@@ -489,7 +497,11 @@ function _setupFileEventListeners(userID, client, onTransferProgress, onIncoming
489
497
  }
490
498
  this.progressBarManager.updateTaskProgress(fileName, chunkSize);
491
499
  if (onTransferStatus) {
492
- onTransferStatus(data);
500
+ const taskBarStats = this.progressBarManager.getTaskBar(fileName);
501
+ onTransferStatus({
502
+ ...data,
503
+ stats: taskBarStats
504
+ });
493
505
  }
494
506
  return;
495
507
  });
@@ -509,13 +521,21 @@ function _setupFileEventListeners(userID, client, onTransferProgress, onIncoming
509
521
  _FileTide.outputGradient(`[${userID}] Did not save file at : ${savePath}\n\t${error}\n`, errorMessageColors);
510
522
  }
511
523
  if (onTransferComplete) {
512
- onTransferComplete(data, fileTransferReceiver.activeTransfers, success);
524
+ const taskBarStats = this.progressBarManager.getTaskBar(data.fileName);
525
+ onTransferComplete({
526
+ ...data,
527
+ stats: taskBarStats
528
+ }, fileTransferReceiver.activeTransfers, success);
513
529
  }
514
530
  });
515
531
  } catch (error) {
516
532
  _FileTide.outputGradient(`[${userID}] Did not save file at : ${savePath}\n${error}`, errorMessageColors);
517
533
  if (onTransferComplete) {
518
- onTransferComplete(data, fileTransferReceiver.activeTransfers, false);
534
+ const taskBarStats = this.progressBarManager.getTaskBar(data.fileName);
535
+ onTransferComplete({
536
+ ...data,
537
+ stats: taskBarStats
538
+ }, fileTransferReceiver.activeTransfers, false);
519
539
  }
520
540
  }
521
541
  });
@@ -4,7 +4,8 @@ const readline = require("readline");
4
4
  const chalk = require("chalk");
5
5
  class ConsoleProgressBarManager {
6
6
  constructor(tasks = [], options = {}) {
7
- this.visibleBars = process.stdout.rows - 3;
7
+ const rows = process.stdout.rows || 24;
8
+ this.visibleBars = rows - 3;
8
9
  this.currentPage = 0;
9
10
  this.barsPerPage = this.visibleBars;
10
11
  this.maxCompletionFeedSize = 5;
@@ -107,8 +108,10 @@ class ConsoleProgressBarManager {
107
108
  };
108
109
  },
109
110
  redraw: () => {
110
- readline.cursorTo(process.stdout, 0, newBar.taskIndex % this.barsPerPage);
111
- process.stdout.clearLine();
111
+ if (!isNaN(newBar.taskIndex) && !isNaN(this.barsPerPage)) {
112
+ readline.cursorTo(process.stdout, 0, newBar.taskIndex % this.barsPerPage);
113
+ process.stdout.clearLine();
114
+ }
112
115
  if (newBar.completed) {
113
116
  process.stdout.write(settings.taskCompletedColor(`${newBar.taskName}: Completed!`));
114
117
  return;
@@ -167,6 +170,9 @@ class ConsoleProgressBarManager {
167
170
  this.exitInputListener();
168
171
  this.displayPage();
169
172
  this.displayCompletionMessage();
173
+ setTimeout(() => {
174
+ this.clearTaskBars();
175
+ }, this.completionTimeout);
170
176
  }
171
177
  }
172
178
  };
@@ -202,6 +208,55 @@ class ConsoleProgressBarManager {
202
208
  console.log(chalk.red(`Task ${taskName} not found.`));
203
209
  }
204
210
  }
211
+ getCurrentStats() {
212
+ const completedTasks = this.taskBars.filter(bar => bar.completed).length;
213
+ const totalTasks = this.taskBars.length;
214
+ const overallProgress = this.taskBars.reduce((acc, bar) => acc + bar.current / bar.totalSize * 100, 0) / totalTasks;
215
+ const stats = {
216
+ completedTasks,
217
+ totalTasks,
218
+ overallProgress: `${overallProgress.toFixed(2)}%`,
219
+ taskDetails: this.taskBars.map(bar => ({
220
+ taskName: bar.taskName,
221
+ progress: `${(bar.current / bar.totalSize * 100).toFixed(2)}%`,
222
+ completed: bar.completed,
223
+ currentSize: bar.getFormattedSize(bar.current),
224
+ totalSize: bar.getFormattedSize(bar.totalSize),
225
+ speed: `${bar.getUnitData(bar.speed).current} ${bar.getUnitData(bar.speed).unit}/s`,
226
+ timeLeft: this.convertSeconds(bar.timeLeft.toFixed(2))
227
+ }))
228
+ };
229
+ return stats;
230
+ }
231
+ getTaskBar(taskID) {
232
+ if (typeof taskID === "string") {
233
+ return this.taskBars.find(bar => bar.taskName === taskID) || null;
234
+ } else if (typeof taskID === "number") {
235
+ return this.taskBars[taskID] || null;
236
+ }
237
+ return null;
238
+ }
239
+ clearTaskBars() {
240
+ this.taskBars = [];
241
+ this.totalTasks = 0;
242
+ this.completedTasksCount = 0;
243
+ this.completionFeed = [];
244
+ this.allTasksCompleted = false;
245
+ }
246
+ clearTaskBar(taskID) {
247
+ let taskIndex = null;
248
+ if (typeof taskID === "string") {
249
+ taskIndex = this.taskBars.findIndex(bar => bar.taskName === taskID);
250
+ } else if (typeof taskID === "number") {
251
+ taskIndex = identifier;
252
+ }
253
+ if (taskIndex !== null && taskIndex >= 0 && taskIndex < this.taskBars.length) {
254
+ this.taskBars.splice(taskIndex, 1);
255
+ this.totalTasks--;
256
+ return true;
257
+ }
258
+ return false;
259
+ }
205
260
  clearPage() {
206
261
  for (let i = 0; i < this.barsPerPage + 2; i++) {
207
262
  readline.cursorTo(process.stdout, 0, i);
@@ -221,21 +276,27 @@ class ConsoleProgressBarManager {
221
276
  }
222
277
  redrawCompletionFeed(customPagePrefix = "Page", bottomMessage, pageFooterMessageColor = chalk.blue, bottomMessageColor = chalk.gray, recentlyCompletedColor = chalk.green) {
223
278
  const bottomPosition = this.barsPerPage;
224
- readline.cursorTo(process.stdout, 0, bottomPosition);
225
- process.stdout.clearLine();
279
+ if (!isNaN(bottomPosition)) {
280
+ readline.cursorTo(process.stdout, 0, bottomPosition);
281
+ process.stdout.clearLine();
282
+ }
226
283
  process.stdout.write(pageFooterMessageColor(`${customPagePrefix} ${this.currentPage + 1}/${Math.max(1, Math.ceil(this.taskBars.length / this.barsPerPage))} | Completed: ${this.completedTasksCount}/${this.totalTasks}`));
227
284
  if (this.completionFeed.length > 0) {
228
285
  process.stdout.write(recentlyCompletedColor(` | Recently completed: ${this.completionFeed.join(", ")}`));
229
286
  }
230
- readline.cursorTo(process.stdout, 0, bottomPosition + 1);
231
- process.stdout.clearLine();
287
+ if (!isNaN(bottomPosition)) {
288
+ readline.cursorTo(process.stdout, 0, bottomPosition + 1);
289
+ process.stdout.clearLine();
290
+ }
232
291
  if (bottomMessage) {
233
292
  process.stdout.write(bottomMessageColor(bottomMessage));
234
293
  }
235
294
  }
236
295
  listenForInput(customPagePrefix = "Page", bottomMessage, bottomMessageColor = chalk.gray, recentlyCompletedColor = chalk.green) {
237
- process.stdin.setRawMode(true);
238
- process.stdin.resume();
296
+ if (!isNaN(this.barsPerPage)) {
297
+ process.stdin.setRawMode(true);
298
+ process.stdin.resume();
299
+ }
239
300
  process.stdin.setEncoding("utf-8");
240
301
  this.inputListener = key => {
241
302
  if (key === "\u0003") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trap_stevo/filetide",
3
- "version": "0.0.48",
3
+ "version": "0.0.49",
4
4
  "description": "Revolutionizing real-time file transfer with seamless, instant communication across any device. Deliver files instantly, regardless of platform, and experience unparalleled speed and control in managing transfers. Elevate your file-sharing capabilities with a tool designed for precision, efficiency, and effortless connectivity.",
5
5
  "main": "dist/cjs/FileTide.js",
6
6
  "scripts": {
@@ -10,6 +10,10 @@
10
10
  "start": "node dist/cjs/FileTide.js"
11
11
  },
12
12
  "keywords": [
13
+ "Legendary",
14
+ "Enlightened",
15
+ "Steven Compton",
16
+ "Magical",
13
17
  "real-time",
14
18
  "nodejs",
15
19
  "ota",