@trap_stevo/filetide 0.0.48 → 0.0.50

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) && process.stdout.isTTY) {
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,10 +208,61 @@ 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);
208
- process.stdout.clearLine();
263
+ if (process.stdout.isTTY) {
264
+ process.stdout.clearLine();
265
+ }
209
266
  }
210
267
  }
211
268
  displayPage(customPagePrefix = "Page", bottomMessage, bottomMessageColor = chalk.gray) {
@@ -221,21 +278,27 @@ class ConsoleProgressBarManager {
221
278
  }
222
279
  redrawCompletionFeed(customPagePrefix = "Page", bottomMessage, pageFooterMessageColor = chalk.blue, bottomMessageColor = chalk.gray, recentlyCompletedColor = chalk.green) {
223
280
  const bottomPosition = this.barsPerPage;
224
- readline.cursorTo(process.stdout, 0, bottomPosition);
225
- process.stdout.clearLine();
281
+ if (!isNaN(bottomPosition) && process.stdout.isTTY) {
282
+ readline.cursorTo(process.stdout, 0, bottomPosition);
283
+ process.stdout.clearLine();
284
+ }
226
285
  process.stdout.write(pageFooterMessageColor(`${customPagePrefix} ${this.currentPage + 1}/${Math.max(1, Math.ceil(this.taskBars.length / this.barsPerPage))} | Completed: ${this.completedTasksCount}/${this.totalTasks}`));
227
286
  if (this.completionFeed.length > 0) {
228
287
  process.stdout.write(recentlyCompletedColor(` | Recently completed: ${this.completionFeed.join(", ")}`));
229
288
  }
230
- readline.cursorTo(process.stdout, 0, bottomPosition + 1);
231
- process.stdout.clearLine();
289
+ if (!isNaN(bottomPosition) && process.stdout.isTTY) {
290
+ readline.cursorTo(process.stdout, 0, bottomPosition + 1);
291
+ process.stdout.clearLine();
292
+ }
232
293
  if (bottomMessage) {
233
294
  process.stdout.write(bottomMessageColor(bottomMessage));
234
295
  }
235
296
  }
236
297
  listenForInput(customPagePrefix = "Page", bottomMessage, bottomMessageColor = chalk.gray, recentlyCompletedColor = chalk.green) {
237
- process.stdin.setRawMode(true);
238
- process.stdin.resume();
298
+ if (!isNaN(this.barsPerPage)) {
299
+ process.stdin.setRawMode(true);
300
+ process.stdin.resume();
301
+ }
239
302
  process.stdin.setEncoding("utf-8");
240
303
  this.inputListener = key => {
241
304
  if (key === "\u0003") {
@@ -260,7 +323,9 @@ class ConsoleProgressBarManager {
260
323
  displayCompletionMessage() {
261
324
  const lastLine = Math.min(this.taskBars.length, this.barsPerPage);
262
325
  readline.cursorTo(process.stdout, 0, lastLine);
263
- process.stdout.clearLine();
326
+ if (process.stdout.isTTY) {
327
+ process.stdout.clearLine();
328
+ }
264
329
  console.log(this.completionMessageColor(this.completionMessage));
265
330
  }
266
331
  }
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.50",
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",