@trap_stevo/filetide 0.0.78 → 0.0.80

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.
@@ -1451,6 +1451,9 @@ class FileMessager {
1451
1451
  }
1452
1452
  return client;
1453
1453
  }
1454
+ getOnlineClients() {
1455
+ return FileNetClientManager.getOnlineClients();
1456
+ }
1454
1457
  requestFromClient(requesterID, senderID, filePath = process.cwd(), destinationPath) {
1455
1458
  const senderConnectionID = FileNetClientManager.getOnlineClient(senderID).id;
1456
1459
  const client = this.getClientFromID(senderConnectionID);
@@ -1473,8 +1476,9 @@ class FileMessager {
1473
1476
  * @param {Buffer} fileChunk - The file chunk to send
1474
1477
  * @param {String} fileName - The name of the file
1475
1478
  * @param {Number} chunkIndex - The index of the current chunk
1479
+ * @param {Object} metadata - Any additional identifying data attached to the transfer
1476
1480
  */
1477
- sendFileChunkToClient(senderData, clientData, fileChunk, fileName, chunkIndex, chunkSize, totalChunks, filePath = process.cwd(), fileSize = 100) {
1481
+ sendFileChunkToClient(senderData, clientData, fileChunk, fileName, chunkIndex, chunkSize, totalChunks, filePath = process.cwd(), fileSize = 100, metadata = {}) {
1478
1482
  const senderClient = this.getClientFromID(senderData.id);
1479
1483
  const client = this.getClientFromID(clientData.id);
1480
1484
  if (!client) {
@@ -1508,7 +1512,8 @@ class FileMessager {
1508
1512
  fileSize,
1509
1513
  fileName,
1510
1514
  totalChunks,
1511
- chunkSize
1515
+ chunkSize,
1516
+ transferMetadata: metadata
1512
1517
  }
1513
1518
  });
1514
1519
  this.onTideAction({
@@ -1521,7 +1526,8 @@ class FileMessager {
1521
1526
  fileSize,
1522
1527
  fileName,
1523
1528
  totalChunks,
1524
- chunkSize
1529
+ chunkSize,
1530
+ transferMetadata: metadata
1525
1531
  }
1526
1532
  });
1527
1533
  }
@@ -1533,7 +1539,8 @@ class FileMessager {
1533
1539
  chunkIndex,
1534
1540
  chunkSize,
1535
1541
  path: filePath,
1536
- fileSize
1542
+ fileSize,
1543
+ metadata
1537
1544
  });
1538
1545
  _assertClassBrand(_FileMessager_brand, this, _log).call(this, `[FileTide ~ File Messager] ~ Sent chunk ${chunkIndex} of ${fileName} to client ~ ${clientData.userID}!`);
1539
1546
  if (senderClient) {
@@ -1548,7 +1555,8 @@ class FileMessager {
1548
1555
  totalChunks,
1549
1556
  chunkSize,
1550
1557
  path: filePath,
1551
- fileSize
1558
+ fileSize,
1559
+ metadata
1552
1560
  });
1553
1561
  }
1554
1562
  }
@@ -1723,7 +1731,8 @@ class FileMessager {
1723
1731
  chunkIndex,
1724
1732
  chunkSize,
1725
1733
  completedChunks,
1726
- totalChunks
1734
+ totalChunks,
1735
+ metadata = {}
1727
1736
  } = chunkData;
1728
1737
  _assertClassBrand(_FileMessager_brand, this, _log).call(this, `[FileTide ~ File Messager] ~ Transferring file ~ ${fileName} | chunk ${chunkIndex + 1} >> ${completedChunks} of ${totalChunks} to client (${recipientId})`);
1729
1738
  const recipientClient = FileNetClientManager.getOnlineClient(recipientId);
@@ -1734,7 +1743,7 @@ class FileMessager {
1734
1743
  }, {
1735
1744
  userID: recipientId,
1736
1745
  id: recipientClient.id
1737
- }, fileChunk, fileName, chunkIndex, chunkSize, totalChunks, filePath, fileSize);
1746
+ }, fileChunk, fileName, chunkIndex, chunkSize, totalChunks, filePath, fileSize, metadata);
1738
1747
  if (completedChunks === totalChunks) {
1739
1748
  this.fileNet.emitToTide(recipientClient.tideID, "transfer-complete", {
1740
1749
  senderID,
@@ -1767,7 +1776,8 @@ class FileMessager {
1767
1776
  fileName,
1768
1777
  completedChunks,
1769
1778
  totalChunks,
1770
- chunkSize
1779
+ chunkSize,
1780
+ transferMetadata: metadata
1771
1781
  }
1772
1782
  });
1773
1783
  this.onTideAction({
@@ -1781,7 +1791,8 @@ class FileMessager {
1781
1791
  fileName,
1782
1792
  completedChunks,
1783
1793
  totalChunks,
1784
- chunkSize
1794
+ chunkSize,
1795
+ transferMetadata: metadata
1785
1796
  }
1786
1797
  });
1787
1798
  console.log(`[FileTide ~ File Messager] ~ File transfer completed: ${fileName} from ${senderID} to ${recipientId}`);
@@ -1803,7 +1814,8 @@ class FileMessager {
1803
1814
  chunkIndex,
1804
1815
  chunkSize,
1805
1816
  completedChunks,
1806
- totalChunks
1817
+ totalChunks,
1818
+ metadata = {}
1807
1819
  } = transferData;
1808
1820
  _assertClassBrand(_FileMessager_brand, this, _log).call(this, `[FileTide ~ File Messager] ~ Transferring file ~ ${fileName} | chunk ${chunkIndex + 1} >> ${completedChunks} of ${totalChunks} to client (${recipientId})`);
1809
1821
  const recipientClient = FileNetClientManager.getOnlineClient(recipientId);
@@ -1814,7 +1826,7 @@ class FileMessager {
1814
1826
  }, {
1815
1827
  userID: recipientId,
1816
1828
  id: recipientClient.id
1817
- }, fileChunk, fileName, chunkIndex, chunkSize, totalChunks, filePath, fileSize);
1829
+ }, fileChunk, fileName, chunkIndex, chunkSize, totalChunks, filePath, fileSize, metadata);
1818
1830
  if (chunkIndex + 1 === totalChunks) {
1819
1831
  this.fileNet.emitToTide(recipientClient.tideID, "transfer-complete", {
1820
1832
  senderID,
@@ -1847,7 +1859,8 @@ class FileMessager {
1847
1859
  fileName,
1848
1860
  completedChunks,
1849
1861
  totalChunks,
1850
- chunkSize
1862
+ chunkSize,
1863
+ transferMetadata: metadata
1851
1864
  }
1852
1865
  });
1853
1866
  this.onTideAction({
@@ -1861,7 +1874,8 @@ class FileMessager {
1861
1874
  fileName,
1862
1875
  completedChunks,
1863
1876
  totalChunks,
1864
- chunkSize
1877
+ chunkSize,
1878
+ transferMetadata: metadata
1865
1879
  }
1866
1880
  });
1867
1881
  console.log(`[FileTide ~ File Messager] ~ File transfer completed: ${fileName} from ${senderID} to ${recipientId}`);
@@ -2055,6 +2069,8 @@ class FileMessager {
2055
2069
  const transferSize = FileNetUtilityManager.getFormattedSize(data.transferStats.totalSize, true);
2056
2070
  const transferSpeed = FileNetUtilityManager.getFormattedSize(data.transferStats.speed, true);
2057
2071
  const transferStartTime = data.transferStats.startTime;
2072
+ const transferMetadata = data.metadata;
2073
+ const contentType = transferMetadata?.contentType ?? "file";
2058
2074
  const fileName = data.fileName;
2059
2075
  console.log(`[FileTide ~ Net Activity] ~ ${data.recipientName} acknowledged tide transfer from ${data.senderName}.\n\n\t~ [${fileName}-${transferStartTime}] ~\n\n\t\tFile Name ~ ${fileName}\n\t\tDestination ~ ${data.path}\n\n\t\t\tProgress ~ ${transferProgress}%\n\t\t\tETA ~ ${transferETA}\n\t\t\tSpeed ~ ${transferSpeed}/s\n\t\t\tSize ~ ${transferSize}\n\t\t\tTransferred ~ ${currentTransferredSize}\n`);
2060
2076
  tidalytics.track("tide:transfer-state", {
@@ -2068,6 +2084,7 @@ class FileMessager {
2068
2084
  path: data.path,
2069
2085
  startTime: transferStartTime,
2070
2086
  transferSize,
2087
+ contentType,
2071
2088
  fileName
2072
2089
  },
2073
2090
  metadata: {
@@ -2081,7 +2098,8 @@ class FileMessager {
2081
2098
  transferProgress,
2082
2099
  transferSize,
2083
2100
  transferETA,
2084
- fileName
2101
+ fileName,
2102
+ transferMetadata
2085
2103
  }
2086
2104
  });
2087
2105
  this.onTideAction({
@@ -2098,7 +2116,9 @@ class FileMessager {
2098
2116
  transferProgress,
2099
2117
  transferSize,
2100
2118
  transferETA,
2101
- fileName
2119
+ contentType,
2120
+ fileName,
2121
+ transferMetadata
2102
2122
  }
2103
2123
  });
2104
2124
  } catch (error) {
@@ -136,8 +136,9 @@ class FileMessagerClient {
136
136
  * @param {Number} minTideSize - The minimum tide size in sending files (10).
137
137
  * @param {Number} maxTideSize - The maximum tide size in sending files (2000).
138
138
  * @param {Number} transferRequestExpirationTime - The maximum time until the transfer barrier times out the transfer request.
139
+ * @param {Object} metadata - Any additional identifying data attached to the transfer.
139
140
  */
140
- async sendDirectoryFiles(clientID, recipientId, filesData, baseDirectory, destinationPath, tideSize = 500, minTideSize = 10, maxTideSize = 2000, transferRequestExpirationTime = 30000) {
141
+ async sendDirectoryFiles(clientID, recipientId, filesData, baseDirectory, destinationPath, tideSize = 500, minTideSize = 10, maxTideSize = 2000, transferRequestExpirationTime = 30000, metadata = {}) {
141
142
  try {
142
143
  const baseDirectoryName = path.basename(baseDirectory);
143
144
  const adjustedDestinationPath = FileUtilityManager.normalizePath(path.join(destinationPath, baseDirectoryName));
@@ -157,23 +158,23 @@ class FileMessagerClient {
157
158
  const relativeFilePath = path.dirname(path.relative(baseDirectory, fileInfo.filePath));
158
159
  const fileDestinationPath = FileUtilityManager.normalizePath(path.join(adjustedDestinationPath, relativeFilePath));
159
160
  if (fileInfo.largeFile) {
160
- return await this.sendDirectoryLargeFile(clientID, recipientId, fileInfo.fileName, fileInfo.filePath, fileDestinationPath, fileInfo.fileSize, index, tideSize, minTideSize, maxTideSize, transferRequestExpirationTime);
161
+ return await this.sendDirectoryLargeFile(clientID, recipientId, fileInfo.fileName, fileInfo.filePath, fileDestinationPath, fileInfo.fileSize, index, tideSize, minTideSize, maxTideSize, transferRequestExpirationTime, metadata);
161
162
  }
162
- return await this.sendDirectoryFile(clientID, recipientId, fileInfo.fileName, fileInfo.filePath, fileInfo.size, fileDestinationPath, index, tideSize, minTideSize, maxTideSize, transferRequestExpirationTime);
163
+ return await this.sendDirectoryFile(clientID, recipientId, fileInfo.fileName, fileInfo.filePath, fileInfo.size, fileDestinationPath, index, tideSize, minTideSize, maxTideSize, transferRequestExpirationTime, metadata);
163
164
  });
164
165
  Promise.all(sendFilePromises).then(() => console.log("\nAll files in directory transferred successfully!")).catch(error => console.error("Did not transfer directory: ", error));
165
166
  } catch (error) {
166
167
  FileTideDebugUtilityManager.outputGradient(`[FileTide ~ File Messager] ~ Refused directory transfer: ${error}`, errorMessageColors);
167
168
  }
168
169
  }
169
- async sendDirectoryLargeFile(clientID, recipientId, fileName, filePath = process.cwd(), destinationPath = null, fileSize, index = 0, tideSize = 500, minTideSize = 10, maxTideSize = 2000, transferRequestExpirationTime = 30000) {
170
+ async sendDirectoryLargeFile(clientID, recipientId, fileName, filePath = process.cwd(), destinationPath = null, fileSize, index = 0, tideSize = 500, minTideSize = 10, maxTideSize = 2000, transferRequestExpirationTime = 30000, metadata = {}) {
170
171
  let initiatingTransfer = false;
171
172
  if (index === 0) {
172
173
  initiatingTransfer = true;
173
174
  }
174
- return await this.sendFile(clientID, recipientId, fileName, filePath, destinationPath, fileSize, tideSize, minTideSize, maxTideSize, initiatingTransfer, true, true, true, transferRequestExpirationTime);
175
+ return await this.sendFile(clientID, recipientId, fileName, filePath, destinationPath, fileSize, tideSize, minTideSize, maxTideSize, initiatingTransfer, true, true, true, transferRequestExpirationTime, metadata);
175
176
  }
176
- async sendDirectoryFile(clientID, recipientId, fileName, filePath = process.cwd(), fileSize, directoryPath = null, index = 0, tideSize = 200, minTideSize = 10, maxTideSize = 2000, transferRequestExpirationTime = 30000) {
177
+ async sendDirectoryFile(clientID, recipientId, fileName, filePath = process.cwd(), fileSize, directoryPath = null, index = 0, tideSize = 200, minTideSize = 10, maxTideSize = 2000, transferRequestExpirationTime = 30000, metadata = {}) {
177
178
  if (!filePath) {
178
179
  return;
179
180
  }
@@ -184,13 +185,14 @@ class FileMessagerClient {
184
185
  senderID: clientID,
185
186
  recipientID: recipientId,
186
187
  path: directoryPath || filePath,
187
- fileSize
188
+ fileSize,
189
+ metadata
188
190
  });
189
191
  initiatingTransfer = true;
190
192
  }
191
- return await this.sendFile(clientID, recipientId, fileName, filePath, directoryPath, fileSize, tideSize, minTideSize, maxTideSize, initiatingTransfer, true, true, false, transferRequestExpirationTime);
193
+ return await this.sendFile(clientID, recipientId, fileName, filePath, directoryPath, fileSize, tideSize, minTideSize, maxTideSize, initiatingTransfer, true, true, false, transferRequestExpirationTime, metadata);
192
194
  }
193
- async sendFile(clientID, recipientId, fileName, filePath = process.cwd(), destination = process.cwd(), fileSize, tideSize = 500, minTideSize = 10, maxTideSize = 2000, initiatingTransfer = true, inDirectory = false, largeFile = false, transferRequestExpirationTime = 30000) {
195
+ async sendFile(clientID, recipientId, fileName, filePath = process.cwd(), destination = process.cwd(), fileSize, tideSize = 500, minTideSize = 10, maxTideSize = 2000, initiatingTransfer = true, inDirectory = false, largeFile = false, transferRequestExpirationTime = 30000, metadata = {}) {
194
196
  const destinationPath = FileUtilityManager.normalizePath(path.join(destination, fileName));
195
197
  FileTideDebugUtilityManager.outputGradient(largeFile ? `[FileTide ~ File Messager] ~ Requesting to transfer large file ~ ${destinationPath} to ${recipientId}!` : `[FileTide ~ File Messager] ~ Requesting to transfer ~ ${destinationPath} to ${recipientId}!`, significantMessageColors);
196
198
  const incomingType = this.activeTransferTypes.get(filePath);
@@ -207,7 +209,8 @@ class FileMessagerClient {
207
209
  senderID: clientID,
208
210
  recipientID: recipientId,
209
211
  path: destination,
210
- fileSize
212
+ fileSize,
213
+ metadata
211
214
  });
212
215
  } else if (inDirectory && !initiatingTransfer) {
213
216
  if (incomingType) {
@@ -247,7 +250,8 @@ class FileMessagerClient {
247
250
  chunkIndex,
248
251
  chunkSize,
249
252
  filePath: destination,
250
- fileSize
253
+ fileSize,
254
+ metadata
251
255
  });
252
256
  if (!transferInitiated) {
253
257
  this.clientTide.emitEvent(clientID, "client-to-client-transfer", {
@@ -286,7 +290,8 @@ class FileMessagerClient {
286
290
  senderID: clientID,
287
291
  recipientId,
288
292
  fileName,
289
- filePath: destination
293
+ filePath: destination,
294
+ metadata
290
295
  });
291
296
  resolve();
292
297
  });
@@ -270,8 +270,9 @@ class FileTide {
270
270
  * @param {Number} minTideSize - The minimum tide size in sending files (10).
271
271
  * @param {Number} maxTideSize - The maximum tide size in sending files (2000).
272
272
  * @param {Number} transferRequestExpirationTime - The maximum time until the transfer barrier times out the transfer request.
273
+ * @param {Object} metadata - Any additional identifying data attached to the transfer.
273
274
  */
274
- async sendToDevice(recipientID, filePath, destinationPath, filterDirectoryContent = [], tideSize = 200, tidalSize = 500, minTideSize = 10, maxTideSize = 2000, transferRequestExpirationTime = 30000) {
275
+ async sendToDevice(recipientID, filePath, destinationPath, filterDirectoryContent = [], tideSize = 200, tidalSize = 500, minTideSize = 10, maxTideSize = 2000, transferRequestExpirationTime = 30000, metadata = {}) {
275
276
  return await TideTokenEnforcer.protect(async () => {
276
277
  const clientID = this.currentUserID;
277
278
  const clientMessager = this.clients.get(clientID);
@@ -295,19 +296,23 @@ class FileTide {
295
296
  FileTide.outputGradient(`[${clientID}] File at path ${filePath} not found.`, errorMessageColors);
296
297
  return false;
297
298
  }
299
+ const transferMetadata = {
300
+ ...(metadata ?? {}),
301
+ contentType: fileDetails.type
302
+ };
298
303
  if (fileDetails.type === "file") {
299
304
  if (fileDetails.largeFile) {
300
305
  FileTide.outputGradient(`[${clientID}] Sending large file ~ ${fileDetails.fileName} to client ~ ${recipientID}...`, significantMessageColors);
301
- await clientMessager.sendFile(clientID, recipientID, fileDetails.fileName, fileDetails.filePath, destinationPath, fileDetails.fileSize, tidalSize, minTideSize, maxTideSize, true, false, true, transferRequestExpirationTime);
306
+ await clientMessager.sendFile(clientID, recipientID, fileDetails.fileName, fileDetails.filePath, destinationPath, fileDetails.fileSize, tidalSize, minTideSize, maxTideSize, true, false, true, transferRequestExpirationTime, transferMetadata);
302
307
  return true;
303
308
  }
304
309
  FileTide.outputGradient(`[${clientID}] Sending file ~ ${fileDetails.content.fileName} to client ~ ${recipientID}...`, significantMessageColors);
305
- await clientMessager.sendFile(clientID, recipientID, fileDetails.content.fileName, fileDetails.content.filePath, destinationPath, fileDetails.content.size, tideSize, minTideSize, maxTideSize, transferRequestExpirationTime);
310
+ await clientMessager.sendFile(clientID, recipientID, fileDetails.content.fileName, fileDetails.content.filePath, destinationPath, fileDetails.content.size, tideSize, minTideSize, maxTideSize, true, false, false, transferRequestExpirationTime, transferMetadata);
306
311
  return true;
307
312
  }
308
313
  if (fileDetails.type === "directory") {
309
314
  FileTide.outputGradient(`[${clientID}] Sending ${fileDetails.content.length} files in directory ~ ${path.basename(filePath)} to client ~ ${recipientID}...`, significantMessageColors);
310
- await clientMessager.sendDirectoryFiles(clientID, recipientID, fileDetails.content, this.getTidePath(filePath), destinationPath, tideSize, minTideSize, maxTideSize, transferRequestExpirationTime);
315
+ await clientMessager.sendDirectoryFiles(clientID, recipientID, fileDetails.content, this.getTidePath(filePath), destinationPath, tideSize, minTideSize, maxTideSize, true, true, false, transferRequestExpirationTime, transferMetadata);
311
316
  return true;
312
317
  }
313
318
  FileTide.outputGradient(`[FileTide] ~ No active client ~ ${recipientID} found.`, errorMessageColors);
@@ -682,12 +687,14 @@ function _setupFileEventListeners(userID, client, onTransferProgress, onIncoming
682
687
  recipientName: userID,
683
688
  transferStateID: `${data.path}-${data.fileName}`,
684
689
  path: data.path,
685
- transferStats: taskBarStats
690
+ transferStats: taskBarStats,
691
+ metadata: data.metadata
686
692
  });
687
693
  if (onTransferProgress) {
688
694
  onTransferProgress({
689
695
  ...data,
690
- stats: taskBarStats
696
+ stats: taskBarStats,
697
+ metadata: data.metadata
691
698
  });
692
699
  }
693
700
  });
@@ -346,4 +346,5 @@ class ConsoleTable {
346
346
  return lines.join("\n");
347
347
  }
348
348
  }
349
+ ;
349
350
  module.exports = ConsoleTable;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trap_stevo/filetide",
3
- "version": "0.0.78",
3
+ "version": "0.0.80",
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": {