@trap_stevo/filetide 0.0.86 → 0.0.88

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.
@@ -39,7 +39,6 @@ const {
39
39
  FileTransferStatsManager
40
40
  } = require("./HUDManagers/FileTransferStatsManager.js");
41
41
  const ChunkCapacitor = require("./HUDComponents/ChunkCapacitor.js");
42
- const ConsoleTable = require("./HUDComponents/ConsoleTable.js");
43
42
  const FileMessagerClient = require("./FileMessagerClient.js");
44
43
  const FileTideAnchor = require("./FileTideAnchor.js");
45
44
  var _FileTide_brand = /*#__PURE__*/new WeakSet();
@@ -466,32 +465,6 @@ function _setupFileEventListeners(userID, client, onTransferProgress, onIncoming
466
465
  onBeforeCurrentClientUnauthorizedDisconnect,
467
466
  onCurrentClientUnauthorizedDisconnect
468
467
  } = options;
469
- const cliTable = new ConsoleTable({
470
- padding: 2,
471
- headerAlign: "center",
472
- cellAlign: "left",
473
- borderStyle: "bold",
474
- columnOrder: ["clientID", "originClientID", "connectedOnDisplay"],
475
- columnNames: {
476
- clientID: "Client Name",
477
- originClientID: "Origin Name",
478
- connectedOnDisplay: "Connected On"
479
- },
480
- title: "✨ Online ✨",
481
- tableNumber: 1,
482
- gradient: {
483
- title: ["#00FFFF", "#1E90FF"],
484
- header: ["#FFD700", "#FF8C00"],
485
- border: ["#2e2f30", "#788e9e"],
486
- cell: ["#00BFFF", "#1E90FF"]
487
- },
488
- cellColor: (content, column) => {
489
- if (column === "clientID") {
490
- return chalk.blue(content);
491
- }
492
- return content;
493
- }
494
- });
495
468
  const fileTransferReceiver = new FileTransferReceiverManager();
496
469
  client.clientTide.onEvent(userID, "current-online-clients", data => {
497
470
  client.clientTide.emitEvent(userID, "check-client-banned", {
@@ -509,15 +482,11 @@ function _setupFileEventListeners(userID, client, onTransferProgress, onIncoming
509
482
  }
510
483
  });
511
484
  if (Object.keys(currentClients).length <= 0) {
512
- _FileTide.outputGradient(`\n✨ No Clients Online in ${this.currentChannel} ✨`, significantMessageColors);
513
485
  if (onCurrentOnlineClients) {
514
486
  onCurrentOnlineClients(currentClients, true);
515
487
  }
516
488
  return;
517
489
  }
518
- cliTable.setTitle(`✨ >${Object.keys(currentClients).length}< Online in ${this.currentChannel} ✨`, 1);
519
- cliTable.setData(currentClients);
520
- console.log("\n", cliTable.render(), "\n");
521
490
  if (onCurrentOnlineClients) {
522
491
  onCurrentOnlineClients(currentClients, true);
523
492
  }
@@ -1845,14 +1845,33 @@ class FileTideAnchor {
1845
1845
  }
1846
1846
  }
1847
1847
  handleClientTransferBarrierResponse(senderTide, data) {
1848
- console.log(`[FileTide ~ Anchor] Checking ${data.recipientID}'s transfer barrier for transfer ~ ${data.transferID}...`);
1848
+ console.log(`[FileTide ~ Anchor] Checking ${data?.recipientID}'s transfer barrier for transfer ~ ${data?.transferID}...`);
1849
1849
  try {
1850
- const recipientConnectionID = FileTideAnchorClientManager.getOnlineClient(data.recipientID).id;
1851
- const senderConnectionID = FileTideAnchorClientManager.getOnlineClient(data.clientID).id;
1850
+ if (!data || !data.clientID || !data.recipientID || !data.transferID) {
1851
+ console.log(`[FileTide ~ Anchor Barrier] ~ Invalid transfer barrier request.`);
1852
+ return;
1853
+ }
1854
+ const recipientDetails = FileTideAnchorClientManager.getOnlineClient(data.recipientID);
1855
+ const senderDetails = FileTideAnchorClientManager.getOnlineClient(data.clientID);
1856
+ if (!recipientDetails || !senderDetails) {
1857
+ console.log(!senderDetails ? `[FileTide ~ Anchor Barrier] ~ Sender ~ ${data.clientID} not online.` : `[FileTide ~ Anchor Barrier] ~ Recipient ~ ${data.recipientID} not online.`);
1858
+ const senderClient = senderDetails ? this.getClientFromID(senderDetails.id) : null;
1859
+ if (senderClient) {
1860
+ this.anchor.emitToTide(senderClient.tideID, "transfer-barrier-response", false);
1861
+ }
1862
+ this.currentTransferBarrierTransfers.delete(data.transferID);
1863
+ return;
1864
+ }
1865
+ const recipientConnectionID = recipientDetails.id;
1866
+ const senderConnectionID = senderDetails.id;
1852
1867
  const senderClient = this.getClientFromID(senderConnectionID);
1853
1868
  const client = this.getClientFromID(recipientConnectionID);
1854
1869
  if (!client || !senderClient) {
1855
- console.log(`[FileTide ~ Anchor Barrier] ~ Both, recipient and sender connection authorization required.`);
1870
+ console.log(`[FileTide ~ Anchor Barrier] ~ Both recipient and sender connection authorization required.`);
1871
+ if (senderClient) {
1872
+ this.anchor.emitToTide(senderClient.tideID, "transfer-barrier-response", false);
1873
+ }
1874
+ this.currentTransferBarrierTransfers.delete(data.transferID);
1856
1875
  return;
1857
1876
  }
1858
1877
  this.anchor.emitToTide(client.tideID, "queue-incoming-transfer", {
@@ -1955,10 +1974,17 @@ class FileTideAnchor {
1955
1974
  ...data
1956
1975
  });
1957
1976
  }).catch(error => {
1977
+ this.currentTransferBarrierTransfers.delete(data.transferID);
1958
1978
  console.error(`[FileTide ~ Anchor Barrier] ~ ${error.message}`);
1979
+ const currentSenderDetails = FileTideAnchorClientManager.getOnlineClient(data.clientID);
1980
+ const currentSenderClient = currentSenderDetails ? this.getClientFromID(currentSenderDetails.id) : null;
1981
+ if (currentSenderClient) {
1982
+ this.anchor.emitToTide(currentSenderClient.tideID, "transfer-barrier-response", false);
1983
+ }
1959
1984
  });
1960
1985
  return;
1961
1986
  } catch (error) {
1987
+ this.currentTransferBarrierTransfers.delete(data?.transferID);
1962
1988
  console.error(`[FileTide ~ Anchor Barrier] ~ `, error);
1963
1989
  return;
1964
1990
  }
@@ -1997,12 +2023,6 @@ class FileTideAnchor {
1997
2023
  const recipientDetails = data.recipientName ? FileTideAnchorClientManager.getOnlineClient(data.recipientName) : null;
1998
2024
  const senderClient = senderDetails ? this.getClientFromID(senderDetails.id) : null;
1999
2025
  const recipientClient = recipientDetails ? this.getClientFromID(recipientDetails.id) : null;
2000
-
2001
- /*
2002
- * Sender progress reflects receiver-confirmed persistence,
2003
- * not merely Anchor forwarding. This keeps the sender's
2004
- * tracking aligned with the authoritative receiver state.
2005
- */
2006
2026
  if (senderClient) {
2007
2027
  this.anchor.emitToTide(senderClient.tideID, "transfer-status", {
2008
2028
  transferId: data.transferId,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trap_stevo/filetide",
3
- "version": "0.0.86",
3
+ "version": "0.0.88",
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": {
@@ -1,350 +0,0 @@
1
- "use strict";
2
-
3
- const chalk = require("chalk");
4
- class ConsoleTable {
5
- constructor(options = {}) {
6
- this.options = {
7
- padding: 1,
8
- headerAlign: "center",
9
- cellAlign: "left",
10
- borderStyle: "solid",
11
- headerColor: null,
12
- borderColor: null,
13
- cellColor: (content, columnName, rowData) => content,
14
- columnOrder: null,
15
- columnNames: {},
16
- title: "",
17
- tableNumber: null,
18
- gradient: {
19
- title: null,
20
- header: null,
21
- border: null,
22
- cell: null
23
- },
24
- ...options
25
- };
26
- this.borderChars = this.getBorderChars(this.options.borderStyle);
27
- }
28
- getBorderChars(style) {
29
- const styles = {
30
- solid: {
31
- topLeft: "┌",
32
- topRight: "┐",
33
- bottomLeft: "└",
34
- bottomRight: "┘",
35
- horizontal: "─",
36
- vertical: "│",
37
- topJoin: "┬",
38
- bottomJoin: "┴",
39
- leftJoin: "├",
40
- rightJoin: "┤",
41
- center: "┼"
42
- },
43
- double: {
44
- topLeft: "╔",
45
- topRight: "╗",
46
- bottomLeft: "╚",
47
- bottomRight: "╝",
48
- horizontal: "═",
49
- vertical: "║",
50
- topJoin: "╦",
51
- bottomJoin: "╩",
52
- leftJoin: "╠",
53
- rightJoin: "╣",
54
- center: "╬"
55
- },
56
- round: {
57
- topLeft: "╭",
58
- topRight: "╮",
59
- bottomLeft: "╰",
60
- bottomRight: "╯",
61
- horizontal: "─",
62
- vertical: "│",
63
- topJoin: "┬",
64
- bottomJoin: "┴",
65
- leftJoin: "├",
66
- rightJoin: "┤",
67
- center: "┼"
68
- },
69
- bold: {
70
- topLeft: "┏",
71
- topRight: "┓",
72
- bottomLeft: "┗",
73
- bottomRight: "┛",
74
- horizontal: "━",
75
- vertical: "┃",
76
- topJoin: "┳",
77
- bottomJoin: "┻",
78
- leftJoin: "┣",
79
- rightJoin: "┫",
80
- center: "╋"
81
- }
82
- };
83
- return styles[style] || styles["solid"];
84
- }
85
- setData(data) {
86
- if (Array.isArray(data)) {
87
- this.data = data;
88
- } else if (typeof data === "object") {
89
- this.data = Object.values(data);
90
- } else {
91
- throw new Error("Array or an object only.");
92
- }
93
- this.extractColumns();
94
- this.calculateColumnWidths();
95
- }
96
- extractColumns() {
97
- if (this.options.columnOrder && Array.isArray(this.options.columnOrder)) {
98
- this.columns = this.options.columnOrder;
99
- } else {
100
- const columnsSet = new Set();
101
- this.data.forEach(item => {
102
- Object.keys(item).forEach(key => columnsSet.add(key));
103
- });
104
- this.columns = Array.from(columnsSet);
105
- }
106
- }
107
- calculateColumnWidths() {
108
- const {
109
- padding
110
- } = this.options;
111
- this.columnWidths = {};
112
- this.totalWidth = 0;
113
- this.columns.forEach(column => {
114
- const headerName = this.options.columnNames[column] || column;
115
- let maxWidth = String(headerName).length;
116
- this.data.forEach(item => {
117
- const cellContent = item[column] !== undefined ? String(item[column]) : "";
118
- maxWidth = Math.max(maxWidth, cellContent.length);
119
- });
120
- const columnWidth = maxWidth + padding * 2;
121
- this.columnWidths[column] = columnWidth;
122
- this.totalWidth += columnWidth;
123
- });
124
- this.totalWidth += this.columns.length + 1;
125
- }
126
- alignText(text, width, align) {
127
- const {
128
- padding
129
- } = this.options;
130
- const textLength = text.length;
131
- let totalPadding = width - textLength;
132
- let leftPadding = " ".repeat(padding);
133
- let rightPadding = " ".repeat(padding);
134
- if (totalPadding < padding * 2) {
135
- leftPadding = "";
136
- rightPadding = "";
137
- } else {
138
- totalPadding -= padding * 2;
139
- if (align === "left") {
140
- rightPadding += " ".repeat(totalPadding);
141
- } else if (align === "right") {
142
- leftPadding += " ".repeat(totalPadding);
143
- } else {
144
- const half = Math.floor(totalPadding / 2);
145
- leftPadding += " ".repeat(half);
146
- rightPadding += " ".repeat(totalPadding - half);
147
- }
148
- }
149
- return leftPadding + text + rightPadding;
150
- }
151
- generateGradientText(text, startColor, endColor) {
152
- const length = text.length;
153
- const startRGB = this.hexToRgb(startColor);
154
- const endRGB = this.hexToRgb(endColor);
155
- let gradientText = "";
156
- for (let i = 0; i < length; i++) {
157
- const ratio = i / (length - 1 || 1);
158
- const color = {
159
- r: Math.round(startRGB.r + ratio * (endRGB.r - startRGB.r)),
160
- g: Math.round(startRGB.g + ratio * (endRGB.g - startRGB.g)),
161
- b: Math.round(startRGB.b + ratio * (endRGB.b - startRGB.b))
162
- };
163
- gradientText += chalk.rgb(color.r, color.g, color.b)(text[i]);
164
- }
165
- return gradientText;
166
- }
167
- hexToRgb(hex) {
168
- const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
169
- return result ? {
170
- r: parseInt(result[1], 16),
171
- g: parseInt(result[2], 16),
172
- b: parseInt(result[3], 16)
173
- } : null;
174
- }
175
- generateBorder(type) {
176
- const {
177
- columns,
178
- columnWidths
179
- } = this;
180
- let {
181
- horizontal,
182
- vertical,
183
- topLeft,
184
- topRight,
185
- bottomLeft,
186
- bottomRight,
187
- topJoin,
188
- bottomJoin,
189
- leftJoin,
190
- rightJoin,
191
- center
192
- } = this.borderChars;
193
- const {
194
- borderColor
195
- } = this.options;
196
- const borderGradient = this.options.gradient.border;
197
- if (borderGradient && borderGradient.length === 2) {
198
- const chars = [topLeft, topRight, bottomLeft, bottomRight, horizontal, vertical, topJoin, bottomJoin, leftJoin, rightJoin, center];
199
- const coloredChars = {};
200
- chars.forEach((char, index) => {
201
- coloredChars[char] = this.generateGradientText(char, borderGradient[0], borderGradient[1]);
202
- });
203
- bottomRight = coloredChars[bottomRight];
204
- bottomLeft = coloredChars[bottomLeft];
205
- topRight = coloredChars[topRight];
206
- topLeft = coloredChars[topLeft];
207
- horizontal = coloredChars[horizontal];
208
- vertical = coloredChars[vertical];
209
- bottomJoin = coloredChars[bottomJoin];
210
- rightJoin = coloredChars[rightJoin];
211
- leftJoin = coloredChars[leftJoin];
212
- topJoin = coloredChars[topJoin];
213
- center = coloredChars[center];
214
- } else if (borderColor) {
215
- bottomRight = borderColor(bottomRight);
216
- bottomLeft = borderColor(bottomLeft);
217
- topRight = borderColor(topRight);
218
- topLeft = borderColor(topLeft);
219
- horizontal = borderColor(horizontal);
220
- vertical = borderColor(vertical);
221
- bottomJoin = borderColor(bottomJoin);
222
- rightJoin = borderColor(rightJoin);
223
- leftJoin = borderColor(leftJoin);
224
- topJoin = borderColor(topJoin);
225
- center = borderColor(center);
226
- }
227
- let border = "";
228
- columns.forEach((column, index) => {
229
- const first = index === 0;
230
- const last = index === columns.length - 1;
231
- const width = columnWidths[column];
232
- const line = horizontal.repeat(width);
233
- if (type === "top") {
234
- border += first ? topLeft : topJoin;
235
- } else if (type === "bottom") {
236
- border += first ? bottomLeft : bottomJoin;
237
- } else {
238
- border += first ? leftJoin : center;
239
- }
240
- border += line;
241
- if (last) {
242
- if (type === "top") {
243
- border += topRight;
244
- } else if (type === "bottom") {
245
- border += bottomRight;
246
- } else {
247
- border += rightJoin;
248
- }
249
- }
250
- });
251
- return border;
252
- }
253
- generateRow(rowData, headerRow = false) {
254
- const {
255
- columns,
256
- columnWidths
257
- } = this;
258
- let {
259
- vertical
260
- } = this.borderChars;
261
- const {
262
- headerAlign,
263
- cellAlign,
264
- headerColor,
265
- cellColor
266
- } = this.options;
267
- const align = headerRow ? headerAlign : cellAlign;
268
- const headerGradient = this.options.gradient.header;
269
- const cellGradient = this.options.gradient.cell;
270
- const borderGradient = this.options.gradient.border;
271
- if (borderGradient && borderGradient.length === 2) {
272
- vertical = this.generateGradientText(vertical, borderGradient[0], borderGradient[1]);
273
- } else if (this.options.borderColor) {
274
- vertical = this.options.borderColor(vertical);
275
- }
276
- let row = "";
277
- columns.forEach((column, index) => {
278
- const content = rowData[column] !== undefined ? String(rowData[column]) : "";
279
- const width = columnWidths[column];
280
- const alignedText = this.alignText(content, width, align);
281
- let cellContent = alignedText;
282
- const first = index === 0;
283
- if (headerRow) {
284
- if (headerGradient && headerGradient.length === 2) {
285
- cellContent = this.generateGradientText(cellContent, headerGradient[0], headerGradient[1]);
286
- } else if (headerColor) {
287
- cellContent = headerColor(cellContent);
288
- }
289
- } else {
290
- if (cellGradient && cellGradient.length === 2) {
291
- cellContent = this.generateGradientText(cellContent, cellGradient[0], cellGradient[1]);
292
- } else if (cellColor) {
293
- cellContent = cellColor(cellContent, column, rowData);
294
- }
295
- }
296
- if (first) {
297
- row += vertical;
298
- }
299
- row += cellContent + vertical;
300
- });
301
- return row;
302
- }
303
- setTitle(title, tableNumber = null) {
304
- this.options.title = title;
305
- if (tableNumber !== null) {
306
- this.options.tableNumber = tableNumber;
307
- }
308
- }
309
- renderTitle() {
310
- let titleText = this.options.title;
311
- if (this.options.tableNumber !== null) {
312
- titleText = titleText;
313
- }
314
- const totalWidth = this.totalWidth - 2;
315
- const titleLength = titleText.length;
316
- let leftPadding = Math.floor((totalWidth - titleLength) / 2);
317
- if (leftPadding < 0) leftPadding = 0;
318
- let titleLine = " ".repeat(leftPadding) + titleText;
319
- const titleGradient = this.options.gradient.title;
320
- if (titleGradient && titleGradient.length === 2) {
321
- titleLine = this.generateGradientText(titleLine.trim(), titleGradient[0], titleGradient[1]);
322
- }
323
- return titleLine;
324
- }
325
- render() {
326
- const {
327
- data
328
- } = this;
329
- if (!data || data.length === 0) return "";
330
- const lines = [];
331
- if (this.options.title) {
332
- const title = this.renderTitle();
333
- lines.push(title);
334
- }
335
- lines.push(this.generateBorder("top"));
336
- const headerData = {};
337
- this.columns.forEach(column => {
338
- headerData[column] = this.options.columnNames[column] || column;
339
- });
340
- lines.push(this.generateRow(headerData, true));
341
- lines.push(this.generateBorder("middle"));
342
- data.forEach(rowData => {
343
- lines.push(this.generateRow(rowData));
344
- });
345
- lines.push(this.generateBorder("bottom"));
346
- return lines.join("\n");
347
- }
348
- }
349
- ;
350
- module.exports = ConsoleTable;