@trap_stevo/filetide 0.0.79 → 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.
@@ -1476,8 +1476,9 @@ class FileMessager {
1476
1476
  * @param {Buffer} fileChunk - The file chunk to send
1477
1477
  * @param {String} fileName - The name of the file
1478
1478
  * @param {Number} chunkIndex - The index of the current chunk
1479
+ * @param {Object} metadata - Any additional identifying data attached to the transfer
1479
1480
  */
1480
- 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 = {}) {
1481
1482
  const senderClient = this.getClientFromID(senderData.id);
1482
1483
  const client = this.getClientFromID(clientData.id);
1483
1484
  if (!client) {
@@ -1511,7 +1512,8 @@ class FileMessager {
1511
1512
  fileSize,
1512
1513
  fileName,
1513
1514
  totalChunks,
1514
- chunkSize
1515
+ chunkSize,
1516
+ transferMetadata: metadata
1515
1517
  }
1516
1518
  });
1517
1519
  this.onTideAction({
@@ -1524,7 +1526,8 @@ class FileMessager {
1524
1526
  fileSize,
1525
1527
  fileName,
1526
1528
  totalChunks,
1527
- chunkSize
1529
+ chunkSize,
1530
+ transferMetadata: metadata
1528
1531
  }
1529
1532
  });
1530
1533
  }
@@ -1536,7 +1539,8 @@ class FileMessager {
1536
1539
  chunkIndex,
1537
1540
  chunkSize,
1538
1541
  path: filePath,
1539
- fileSize
1542
+ fileSize,
1543
+ metadata
1540
1544
  });
1541
1545
  _assertClassBrand(_FileMessager_brand, this, _log).call(this, `[FileTide ~ File Messager] ~ Sent chunk ${chunkIndex} of ${fileName} to client ~ ${clientData.userID}!`);
1542
1546
  if (senderClient) {
@@ -1551,7 +1555,8 @@ class FileMessager {
1551
1555
  totalChunks,
1552
1556
  chunkSize,
1553
1557
  path: filePath,
1554
- fileSize
1558
+ fileSize,
1559
+ metadata
1555
1560
  });
1556
1561
  }
1557
1562
  }
@@ -1726,7 +1731,8 @@ class FileMessager {
1726
1731
  chunkIndex,
1727
1732
  chunkSize,
1728
1733
  completedChunks,
1729
- totalChunks
1734
+ totalChunks,
1735
+ metadata = {}
1730
1736
  } = chunkData;
1731
1737
  _assertClassBrand(_FileMessager_brand, this, _log).call(this, `[FileTide ~ File Messager] ~ Transferring file ~ ${fileName} | chunk ${chunkIndex + 1} >> ${completedChunks} of ${totalChunks} to client (${recipientId})`);
1732
1738
  const recipientClient = FileNetClientManager.getOnlineClient(recipientId);
@@ -1737,7 +1743,7 @@ class FileMessager {
1737
1743
  }, {
1738
1744
  userID: recipientId,
1739
1745
  id: recipientClient.id
1740
- }, fileChunk, fileName, chunkIndex, chunkSize, totalChunks, filePath, fileSize);
1746
+ }, fileChunk, fileName, chunkIndex, chunkSize, totalChunks, filePath, fileSize, metadata);
1741
1747
  if (completedChunks === totalChunks) {
1742
1748
  this.fileNet.emitToTide(recipientClient.tideID, "transfer-complete", {
1743
1749
  senderID,
@@ -1770,7 +1776,8 @@ class FileMessager {
1770
1776
  fileName,
1771
1777
  completedChunks,
1772
1778
  totalChunks,
1773
- chunkSize
1779
+ chunkSize,
1780
+ transferMetadata: metadata
1774
1781
  }
1775
1782
  });
1776
1783
  this.onTideAction({
@@ -1784,7 +1791,8 @@ class FileMessager {
1784
1791
  fileName,
1785
1792
  completedChunks,
1786
1793
  totalChunks,
1787
- chunkSize
1794
+ chunkSize,
1795
+ transferMetadata: metadata
1788
1796
  }
1789
1797
  });
1790
1798
  console.log(`[FileTide ~ File Messager] ~ File transfer completed: ${fileName} from ${senderID} to ${recipientId}`);
@@ -1806,7 +1814,8 @@ class FileMessager {
1806
1814
  chunkIndex,
1807
1815
  chunkSize,
1808
1816
  completedChunks,
1809
- totalChunks
1817
+ totalChunks,
1818
+ metadata = {}
1810
1819
  } = transferData;
1811
1820
  _assertClassBrand(_FileMessager_brand, this, _log).call(this, `[FileTide ~ File Messager] ~ Transferring file ~ ${fileName} | chunk ${chunkIndex + 1} >> ${completedChunks} of ${totalChunks} to client (${recipientId})`);
1812
1821
  const recipientClient = FileNetClientManager.getOnlineClient(recipientId);
@@ -1817,7 +1826,7 @@ class FileMessager {
1817
1826
  }, {
1818
1827
  userID: recipientId,
1819
1828
  id: recipientClient.id
1820
- }, fileChunk, fileName, chunkIndex, chunkSize, totalChunks, filePath, fileSize);
1829
+ }, fileChunk, fileName, chunkIndex, chunkSize, totalChunks, filePath, fileSize, metadata);
1821
1830
  if (chunkIndex + 1 === totalChunks) {
1822
1831
  this.fileNet.emitToTide(recipientClient.tideID, "transfer-complete", {
1823
1832
  senderID,
@@ -1850,7 +1859,8 @@ class FileMessager {
1850
1859
  fileName,
1851
1860
  completedChunks,
1852
1861
  totalChunks,
1853
- chunkSize
1862
+ chunkSize,
1863
+ transferMetadata: metadata
1854
1864
  }
1855
1865
  });
1856
1866
  this.onTideAction({
@@ -1864,7 +1874,8 @@ class FileMessager {
1864
1874
  fileName,
1865
1875
  completedChunks,
1866
1876
  totalChunks,
1867
- chunkSize
1877
+ chunkSize,
1878
+ transferMetadata: metadata
1868
1879
  }
1869
1880
  });
1870
1881
  console.log(`[FileTide ~ File Messager] ~ File transfer completed: ${fileName} from ${senderID} to ${recipientId}`);
@@ -2058,6 +2069,8 @@ class FileMessager {
2058
2069
  const transferSize = FileNetUtilityManager.getFormattedSize(data.transferStats.totalSize, true);
2059
2070
  const transferSpeed = FileNetUtilityManager.getFormattedSize(data.transferStats.speed, true);
2060
2071
  const transferStartTime = data.transferStats.startTime;
2072
+ const transferMetadata = data.metadata;
2073
+ const contentType = transferMetadata?.contentType ?? "file";
2061
2074
  const fileName = data.fileName;
2062
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`);
2063
2076
  tidalytics.track("tide:transfer-state", {
@@ -2071,6 +2084,7 @@ class FileMessager {
2071
2084
  path: data.path,
2072
2085
  startTime: transferStartTime,
2073
2086
  transferSize,
2087
+ contentType,
2074
2088
  fileName
2075
2089
  },
2076
2090
  metadata: {
@@ -2084,7 +2098,8 @@ class FileMessager {
2084
2098
  transferProgress,
2085
2099
  transferSize,
2086
2100
  transferETA,
2087
- fileName
2101
+ fileName,
2102
+ transferMetadata
2088
2103
  }
2089
2104
  });
2090
2105
  this.onTideAction({
@@ -2101,7 +2116,9 @@ class FileMessager {
2101
2116
  transferProgress,
2102
2117
  transferSize,
2103
2118
  transferETA,
2104
- fileName
2119
+ contentType,
2120
+ fileName,
2121
+ transferMetadata
2105
2122
  }
2106
2123
  });
2107
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
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trap_stevo/filetide",
3
- "version": "0.0.79",
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": {