@trap_stevo/filetide 0.0.79 → 0.0.81
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.
package/dist/cjs/FileMessager.js
CHANGED
|
@@ -80,11 +80,9 @@ class FileMessager {
|
|
|
80
80
|
}
|
|
81
81
|
start() {
|
|
82
82
|
this.fileNet.on("get-client-transfer-barrier-response", this.handleClientTransferBarrierResponse.bind(this));
|
|
83
|
-
this.fileNet.on("get-client-transfer-state", this.handleGetClientTransferState.bind(this));
|
|
84
83
|
this.fileNet.on("get-client", this.handleGetClient.bind(this));
|
|
85
84
|
this.fileNet.on("acknowledge-transfer-tide", this.handleAcknowledgeTransferTide.bind(this));
|
|
86
85
|
this.fileNet.on("notify-transfer-barrier", this.handleNotifyTransferBarrier.bind(this));
|
|
87
|
-
this.fileNet.on("send-current-transfer-state", this.handleSendCurrentTransferState.bind(this));
|
|
88
86
|
this.fileNet.on("sent-file-list-to-client", this.handleSentFileListToClient.bind(this));
|
|
89
87
|
this.fileNet.on("send-file-list-to-client", this.handleSendFileListToClient.bind(this));
|
|
90
88
|
this.fileNet.on("list-client-files", this.handleListClientFiles.bind(this));
|
|
@@ -1476,8 +1474,9 @@ class FileMessager {
|
|
|
1476
1474
|
* @param {Buffer} fileChunk - The file chunk to send
|
|
1477
1475
|
* @param {String} fileName - The name of the file
|
|
1478
1476
|
* @param {Number} chunkIndex - The index of the current chunk
|
|
1477
|
+
* @param {Object} metadata - Any additional identifying data attached to the transfer
|
|
1479
1478
|
*/
|
|
1480
|
-
sendFileChunkToClient(senderData, clientData, fileChunk, fileName, chunkIndex, chunkSize, totalChunks, filePath = process.cwd(), fileSize = 100) {
|
|
1479
|
+
sendFileChunkToClient(senderData, clientData, fileChunk, fileName, chunkIndex, chunkSize, totalChunks, filePath = process.cwd(), fileSize = 100, metadata = {}) {
|
|
1481
1480
|
const senderClient = this.getClientFromID(senderData.id);
|
|
1482
1481
|
const client = this.getClientFromID(clientData.id);
|
|
1483
1482
|
if (!client) {
|
|
@@ -1511,7 +1510,8 @@ class FileMessager {
|
|
|
1511
1510
|
fileSize,
|
|
1512
1511
|
fileName,
|
|
1513
1512
|
totalChunks,
|
|
1514
|
-
chunkSize
|
|
1513
|
+
chunkSize,
|
|
1514
|
+
transferMetadata: metadata
|
|
1515
1515
|
}
|
|
1516
1516
|
});
|
|
1517
1517
|
this.onTideAction({
|
|
@@ -1524,7 +1524,8 @@ class FileMessager {
|
|
|
1524
1524
|
fileSize,
|
|
1525
1525
|
fileName,
|
|
1526
1526
|
totalChunks,
|
|
1527
|
-
chunkSize
|
|
1527
|
+
chunkSize,
|
|
1528
|
+
transferMetadata: metadata
|
|
1528
1529
|
}
|
|
1529
1530
|
});
|
|
1530
1531
|
}
|
|
@@ -1536,7 +1537,8 @@ class FileMessager {
|
|
|
1536
1537
|
chunkIndex,
|
|
1537
1538
|
chunkSize,
|
|
1538
1539
|
path: filePath,
|
|
1539
|
-
fileSize
|
|
1540
|
+
fileSize,
|
|
1541
|
+
metadata
|
|
1540
1542
|
});
|
|
1541
1543
|
_assertClassBrand(_FileMessager_brand, this, _log).call(this, `[FileTide ~ File Messager] ~ Sent chunk ${chunkIndex} of ${fileName} to client ~ ${clientData.userID}!`);
|
|
1542
1544
|
if (senderClient) {
|
|
@@ -1551,25 +1553,11 @@ class FileMessager {
|
|
|
1551
1553
|
totalChunks,
|
|
1552
1554
|
chunkSize,
|
|
1553
1555
|
path: filePath,
|
|
1554
|
-
fileSize
|
|
1556
|
+
fileSize,
|
|
1557
|
+
metadata
|
|
1555
1558
|
});
|
|
1556
1559
|
}
|
|
1557
1560
|
}
|
|
1558
|
-
saveClientTransferStates(data) {
|
|
1559
|
-
const tidingTransfers = this.currentTidingTransfers.get(data.clientID);
|
|
1560
|
-
if (tidingTransfers && tidingTransfers.size > 0) {
|
|
1561
|
-
for (let recipientID of tidingTransfers.keys()) {
|
|
1562
|
-
const recipientConnectionID = FileNetClientManager.getOnlineClient(data.recipientID ?? recipientID).id;
|
|
1563
|
-
const client = this.getClientFromID(recipientConnectionID);
|
|
1564
|
-
if (client) {
|
|
1565
|
-
this.fileNet.emitToTide(client.tideID, "save-current-transfer-states", {
|
|
1566
|
-
clientID: recipientID
|
|
1567
|
-
});
|
|
1568
|
-
}
|
|
1569
|
-
}
|
|
1570
|
-
this.currentTidingTransfers.delete(data.clientID);
|
|
1571
|
-
}
|
|
1572
|
-
}
|
|
1573
1561
|
|
|
1574
1562
|
// --- File Messager Event Management ---
|
|
1575
1563
|
|
|
@@ -1726,7 +1714,8 @@ class FileMessager {
|
|
|
1726
1714
|
chunkIndex,
|
|
1727
1715
|
chunkSize,
|
|
1728
1716
|
completedChunks,
|
|
1729
|
-
totalChunks
|
|
1717
|
+
totalChunks,
|
|
1718
|
+
metadata = {}
|
|
1730
1719
|
} = chunkData;
|
|
1731
1720
|
_assertClassBrand(_FileMessager_brand, this, _log).call(this, `[FileTide ~ File Messager] ~ Transferring file ~ ${fileName} | chunk ${chunkIndex + 1} >> ${completedChunks} of ${totalChunks} to client (${recipientId})`);
|
|
1732
1721
|
const recipientClient = FileNetClientManager.getOnlineClient(recipientId);
|
|
@@ -1737,7 +1726,7 @@ class FileMessager {
|
|
|
1737
1726
|
}, {
|
|
1738
1727
|
userID: recipientId,
|
|
1739
1728
|
id: recipientClient.id
|
|
1740
|
-
}, fileChunk, fileName, chunkIndex, chunkSize, totalChunks, filePath, fileSize);
|
|
1729
|
+
}, fileChunk, fileName, chunkIndex, chunkSize, totalChunks, filePath, fileSize, metadata);
|
|
1741
1730
|
if (completedChunks === totalChunks) {
|
|
1742
1731
|
this.fileNet.emitToTide(recipientClient.tideID, "transfer-complete", {
|
|
1743
1732
|
senderID,
|
|
@@ -1770,7 +1759,8 @@ class FileMessager {
|
|
|
1770
1759
|
fileName,
|
|
1771
1760
|
completedChunks,
|
|
1772
1761
|
totalChunks,
|
|
1773
|
-
chunkSize
|
|
1762
|
+
chunkSize,
|
|
1763
|
+
transferMetadata: metadata
|
|
1774
1764
|
}
|
|
1775
1765
|
});
|
|
1776
1766
|
this.onTideAction({
|
|
@@ -1784,7 +1774,8 @@ class FileMessager {
|
|
|
1784
1774
|
fileName,
|
|
1785
1775
|
completedChunks,
|
|
1786
1776
|
totalChunks,
|
|
1787
|
-
chunkSize
|
|
1777
|
+
chunkSize,
|
|
1778
|
+
transferMetadata: metadata
|
|
1788
1779
|
}
|
|
1789
1780
|
});
|
|
1790
1781
|
console.log(`[FileTide ~ File Messager] ~ File transfer completed: ${fileName} from ${senderID} to ${recipientId}`);
|
|
@@ -1806,7 +1797,8 @@ class FileMessager {
|
|
|
1806
1797
|
chunkIndex,
|
|
1807
1798
|
chunkSize,
|
|
1808
1799
|
completedChunks,
|
|
1809
|
-
totalChunks
|
|
1800
|
+
totalChunks,
|
|
1801
|
+
metadata = {}
|
|
1810
1802
|
} = transferData;
|
|
1811
1803
|
_assertClassBrand(_FileMessager_brand, this, _log).call(this, `[FileTide ~ File Messager] ~ Transferring file ~ ${fileName} | chunk ${chunkIndex + 1} >> ${completedChunks} of ${totalChunks} to client (${recipientId})`);
|
|
1812
1804
|
const recipientClient = FileNetClientManager.getOnlineClient(recipientId);
|
|
@@ -1817,7 +1809,7 @@ class FileMessager {
|
|
|
1817
1809
|
}, {
|
|
1818
1810
|
userID: recipientId,
|
|
1819
1811
|
id: recipientClient.id
|
|
1820
|
-
}, fileChunk, fileName, chunkIndex, chunkSize, totalChunks, filePath, fileSize);
|
|
1812
|
+
}, fileChunk, fileName, chunkIndex, chunkSize, totalChunks, filePath, fileSize, metadata);
|
|
1821
1813
|
if (chunkIndex + 1 === totalChunks) {
|
|
1822
1814
|
this.fileNet.emitToTide(recipientClient.tideID, "transfer-complete", {
|
|
1823
1815
|
senderID,
|
|
@@ -1850,7 +1842,8 @@ class FileMessager {
|
|
|
1850
1842
|
fileName,
|
|
1851
1843
|
completedChunks,
|
|
1852
1844
|
totalChunks,
|
|
1853
|
-
chunkSize
|
|
1845
|
+
chunkSize,
|
|
1846
|
+
transferMetadata: metadata
|
|
1854
1847
|
}
|
|
1855
1848
|
});
|
|
1856
1849
|
this.onTideAction({
|
|
@@ -1864,7 +1857,8 @@ class FileMessager {
|
|
|
1864
1857
|
fileName,
|
|
1865
1858
|
completedChunks,
|
|
1866
1859
|
totalChunks,
|
|
1867
|
-
chunkSize
|
|
1860
|
+
chunkSize,
|
|
1861
|
+
transferMetadata: metadata
|
|
1868
1862
|
}
|
|
1869
1863
|
});
|
|
1870
1864
|
console.log(`[FileTide ~ File Messager] ~ File transfer completed: ${fileName} from ${senderID} to ${recipientId}`);
|
|
@@ -1997,42 +1991,6 @@ class FileMessager {
|
|
|
1997
1991
|
return;
|
|
1998
1992
|
}
|
|
1999
1993
|
}
|
|
2000
|
-
handleSendCurrentTransferState(senderTide, data) {
|
|
2001
|
-
try {
|
|
2002
|
-
const senderConnectionID = FileNetClientManager.getOnlineClient(data.senderID).id;
|
|
2003
|
-
const senderClient = this.getClientFromID(senderConnectionID);
|
|
2004
|
-
if (!senderClient) {
|
|
2005
|
-
console.log(`[FileTide ~ Net Transfers] ~ Sender ~ ${senderConnectionID.truncate(0, senderConnectionID.length / 2)}... not found.`);
|
|
2006
|
-
return;
|
|
2007
|
-
}
|
|
2008
|
-
this.fileNet.emitToTide(senderClient.tideID, "sent-current-transfer-state", data.transferState || {
|
|
2009
|
-
transferredSize: 0,
|
|
2010
|
-
lastChunkSent: 0
|
|
2011
|
-
});
|
|
2012
|
-
} catch (error) {
|
|
2013
|
-
console.error(`[FileTide ~ Net Transfers] ~ `, error);
|
|
2014
|
-
return;
|
|
2015
|
-
}
|
|
2016
|
-
}
|
|
2017
|
-
handleGetClientTransferState(senderTide, data) {
|
|
2018
|
-
const filePath = data.filePath || data.path;
|
|
2019
|
-
console.log(`[FileTide ~ Net] ~ Getting ${data.recipientID}'s transfer state for ~ ${filePath}...`);
|
|
2020
|
-
try {
|
|
2021
|
-
const recipientConnectionID = FileNetClientManager.getOnlineClient(data.recipientID).id;
|
|
2022
|
-
const client = this.getClientFromID(recipientConnectionID);
|
|
2023
|
-
if (!client) {
|
|
2024
|
-
return;
|
|
2025
|
-
}
|
|
2026
|
-
this.fileNet.emitToTide(client.tideID, "current-transfer-state", {
|
|
2027
|
-
senderID: data.senderID,
|
|
2028
|
-
fileName: data.fileName,
|
|
2029
|
-
filePath
|
|
2030
|
-
});
|
|
2031
|
-
} catch (error) {
|
|
2032
|
-
console.error(`[FileTide ~ Net Transfers] ~ `, error);
|
|
2033
|
-
return;
|
|
2034
|
-
}
|
|
2035
|
-
}
|
|
2036
1994
|
handleGetClient(senderTide, data) {
|
|
2037
1995
|
console.log(`[FileTide ~ Net] ~ Getting client ~ ${data.clientID}...`);
|
|
2038
1996
|
try {
|
|
@@ -2058,6 +2016,8 @@ class FileMessager {
|
|
|
2058
2016
|
const transferSize = FileNetUtilityManager.getFormattedSize(data.transferStats.totalSize, true);
|
|
2059
2017
|
const transferSpeed = FileNetUtilityManager.getFormattedSize(data.transferStats.speed, true);
|
|
2060
2018
|
const transferStartTime = data.transferStats.startTime;
|
|
2019
|
+
const transferMetadata = data.metadata;
|
|
2020
|
+
const contentType = transferMetadata?.contentType ?? "file";
|
|
2061
2021
|
const fileName = data.fileName;
|
|
2062
2022
|
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
2023
|
tidalytics.track("tide:transfer-state", {
|
|
@@ -2071,6 +2031,7 @@ class FileMessager {
|
|
|
2071
2031
|
path: data.path,
|
|
2072
2032
|
startTime: transferStartTime,
|
|
2073
2033
|
transferSize,
|
|
2034
|
+
contentType,
|
|
2074
2035
|
fileName
|
|
2075
2036
|
},
|
|
2076
2037
|
metadata: {
|
|
@@ -2084,7 +2045,8 @@ class FileMessager {
|
|
|
2084
2045
|
transferProgress,
|
|
2085
2046
|
transferSize,
|
|
2086
2047
|
transferETA,
|
|
2087
|
-
fileName
|
|
2048
|
+
fileName,
|
|
2049
|
+
transferMetadata
|
|
2088
2050
|
}
|
|
2089
2051
|
});
|
|
2090
2052
|
this.onTideAction({
|
|
@@ -2101,7 +2063,9 @@ class FileMessager {
|
|
|
2101
2063
|
transferProgress,
|
|
2102
2064
|
transferSize,
|
|
2103
2065
|
transferETA,
|
|
2104
|
-
|
|
2066
|
+
contentType,
|
|
2067
|
+
fileName,
|
|
2068
|
+
transferMetadata
|
|
2105
2069
|
}
|
|
2106
2070
|
});
|
|
2107
2071
|
} catch (error) {
|
|
@@ -2406,11 +2370,6 @@ class FileMessager {
|
|
|
2406
2370
|
const currentOnlineClients = Object.fromEntries(FileNetClientManager.getOnlineClients());
|
|
2407
2371
|
this.fileNet.emit("current-online-clients", currentOnlineClients);
|
|
2408
2372
|
this.fileNet.emit("current-clients", currentOnlineClients);
|
|
2409
|
-
const senderClient = this.getClientFromID(clientDetails.id);
|
|
2410
|
-
this.fileNet.emitToTide(senderClient.tideID, "save-current-transfer-states", {
|
|
2411
|
-
clientID: clientData.clientID
|
|
2412
|
-
});
|
|
2413
|
-
this.saveClientTransferStates(clientData);
|
|
2414
2373
|
} catch (error) {
|
|
2415
2374
|
console.log(`[FileTide ~ Net Activity] ~ Did not process client ~ ${clientData} offline signal ~ ${error}`);
|
|
2416
2375
|
}
|
|
@@ -17,7 +17,6 @@ const {
|
|
|
17
17
|
const {
|
|
18
18
|
FileTransferTrackingManager
|
|
19
19
|
} = require("./HUDManagers/FileTransferTrackingManager.js");
|
|
20
|
-
const FileTransferRecoveryManager = require("./HUDManagers/FileTransferRecoveryManager");
|
|
21
20
|
const {
|
|
22
21
|
FileMessagerConfigManager
|
|
23
22
|
} = require("./HUDManagers/FileMessagerConfigManager");
|
|
@@ -136,8 +135,9 @@ class FileMessagerClient {
|
|
|
136
135
|
* @param {Number} minTideSize - The minimum tide size in sending files (10).
|
|
137
136
|
* @param {Number} maxTideSize - The maximum tide size in sending files (2000).
|
|
138
137
|
* @param {Number} transferRequestExpirationTime - The maximum time until the transfer barrier times out the transfer request.
|
|
138
|
+
* @param {Object} metadata - Any additional identifying data attached to the transfer.
|
|
139
139
|
*/
|
|
140
|
-
async sendDirectoryFiles(clientID, recipientId, filesData, baseDirectory, destinationPath, tideSize = 500, minTideSize = 10, maxTideSize = 2000, transferRequestExpirationTime = 30000) {
|
|
140
|
+
async sendDirectoryFiles(clientID, recipientId, filesData, baseDirectory, destinationPath, tideSize = 500, minTideSize = 10, maxTideSize = 2000, transferRequestExpirationTime = 30000, metadata = {}) {
|
|
141
141
|
try {
|
|
142
142
|
const baseDirectoryName = path.basename(baseDirectory);
|
|
143
143
|
const adjustedDestinationPath = FileUtilityManager.normalizePath(path.join(destinationPath, baseDirectoryName));
|
|
@@ -157,23 +157,23 @@ class FileMessagerClient {
|
|
|
157
157
|
const relativeFilePath = path.dirname(path.relative(baseDirectory, fileInfo.filePath));
|
|
158
158
|
const fileDestinationPath = FileUtilityManager.normalizePath(path.join(adjustedDestinationPath, relativeFilePath));
|
|
159
159
|
if (fileInfo.largeFile) {
|
|
160
|
-
return await this.sendDirectoryLargeFile(clientID, recipientId, fileInfo.fileName, fileInfo.filePath, fileDestinationPath, fileInfo.fileSize, index, tideSize, minTideSize, maxTideSize, transferRequestExpirationTime);
|
|
160
|
+
return await this.sendDirectoryLargeFile(clientID, recipientId, fileInfo.fileName, fileInfo.filePath, fileDestinationPath, fileInfo.fileSize, index, tideSize, minTideSize, maxTideSize, transferRequestExpirationTime, metadata);
|
|
161
161
|
}
|
|
162
|
-
return await this.sendDirectoryFile(clientID, recipientId, fileInfo.fileName, fileInfo.filePath, fileInfo.size, fileDestinationPath, index, tideSize, minTideSize, maxTideSize, transferRequestExpirationTime);
|
|
162
|
+
return await this.sendDirectoryFile(clientID, recipientId, fileInfo.fileName, fileInfo.filePath, fileInfo.size, fileDestinationPath, index, tideSize, minTideSize, maxTideSize, transferRequestExpirationTime, metadata);
|
|
163
163
|
});
|
|
164
164
|
Promise.all(sendFilePromises).then(() => console.log("\nAll files in directory transferred successfully!")).catch(error => console.error("Did not transfer directory: ", error));
|
|
165
165
|
} catch (error) {
|
|
166
166
|
FileTideDebugUtilityManager.outputGradient(`[FileTide ~ File Messager] ~ Refused directory transfer: ${error}`, errorMessageColors);
|
|
167
167
|
}
|
|
168
168
|
}
|
|
169
|
-
async sendDirectoryLargeFile(clientID, recipientId, fileName, filePath = process.cwd(), destinationPath = null, fileSize, index = 0, tideSize = 500, minTideSize = 10, maxTideSize = 2000, transferRequestExpirationTime = 30000) {
|
|
169
|
+
async sendDirectoryLargeFile(clientID, recipientId, fileName, filePath = process.cwd(), destinationPath = null, fileSize, index = 0, tideSize = 500, minTideSize = 10, maxTideSize = 2000, transferRequestExpirationTime = 30000, metadata = {}) {
|
|
170
170
|
let initiatingTransfer = false;
|
|
171
171
|
if (index === 0) {
|
|
172
172
|
initiatingTransfer = true;
|
|
173
173
|
}
|
|
174
|
-
return await this.sendFile(clientID, recipientId, fileName, filePath, destinationPath, fileSize, tideSize, minTideSize, maxTideSize, initiatingTransfer, true, true, true, transferRequestExpirationTime);
|
|
174
|
+
return await this.sendFile(clientID, recipientId, fileName, filePath, destinationPath, fileSize, tideSize, minTideSize, maxTideSize, initiatingTransfer, true, true, true, transferRequestExpirationTime, metadata);
|
|
175
175
|
}
|
|
176
|
-
async sendDirectoryFile(clientID, recipientId, fileName, filePath = process.cwd(), fileSize, directoryPath = null, index = 0, tideSize = 200, minTideSize = 10, maxTideSize = 2000, transferRequestExpirationTime = 30000) {
|
|
176
|
+
async sendDirectoryFile(clientID, recipientId, fileName, filePath = process.cwd(), fileSize, directoryPath = null, index = 0, tideSize = 200, minTideSize = 10, maxTideSize = 2000, transferRequestExpirationTime = 30000, metadata = {}) {
|
|
177
177
|
if (!filePath) {
|
|
178
178
|
return;
|
|
179
179
|
}
|
|
@@ -184,13 +184,14 @@ class FileMessagerClient {
|
|
|
184
184
|
senderID: clientID,
|
|
185
185
|
recipientID: recipientId,
|
|
186
186
|
path: directoryPath || filePath,
|
|
187
|
-
fileSize
|
|
187
|
+
fileSize,
|
|
188
|
+
metadata
|
|
188
189
|
});
|
|
189
190
|
initiatingTransfer = true;
|
|
190
191
|
}
|
|
191
|
-
return await this.sendFile(clientID, recipientId, fileName, filePath, directoryPath, fileSize, tideSize, minTideSize, maxTideSize, initiatingTransfer, true, true, false, transferRequestExpirationTime);
|
|
192
|
+
return await this.sendFile(clientID, recipientId, fileName, filePath, directoryPath, fileSize, tideSize, minTideSize, maxTideSize, initiatingTransfer, true, true, false, transferRequestExpirationTime, metadata);
|
|
192
193
|
}
|
|
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) {
|
|
194
|
+
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
195
|
const destinationPath = FileUtilityManager.normalizePath(path.join(destination, fileName));
|
|
195
196
|
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
197
|
const incomingType = this.activeTransferTypes.get(filePath);
|
|
@@ -207,7 +208,8 @@ class FileMessagerClient {
|
|
|
207
208
|
senderID: clientID,
|
|
208
209
|
recipientID: recipientId,
|
|
209
210
|
path: destination,
|
|
210
|
-
fileSize
|
|
211
|
+
fileSize,
|
|
212
|
+
metadata
|
|
211
213
|
});
|
|
212
214
|
} else if (inDirectory && !initiatingTransfer) {
|
|
213
215
|
if (incomingType) {
|
|
@@ -247,7 +249,8 @@ class FileMessagerClient {
|
|
|
247
249
|
chunkIndex,
|
|
248
250
|
chunkSize,
|
|
249
251
|
filePath: destination,
|
|
250
|
-
fileSize
|
|
252
|
+
fileSize,
|
|
253
|
+
metadata
|
|
251
254
|
});
|
|
252
255
|
if (!transferInitiated) {
|
|
253
256
|
this.clientTide.emitEvent(clientID, "client-to-client-transfer", {
|
|
@@ -281,12 +284,12 @@ class FileMessagerClient {
|
|
|
281
284
|
});
|
|
282
285
|
chunkBatch.length = 0;
|
|
283
286
|
}
|
|
284
|
-
FileTransferRecoveryManager.clearTransferState(clientID, recipientId, `${filePath}-${fileName}`);
|
|
285
287
|
this.clientTide.emitEvent(clientID, "transfer-complete", {
|
|
286
288
|
senderID: clientID,
|
|
287
289
|
recipientId,
|
|
288
290
|
fileName,
|
|
289
|
-
filePath: destination
|
|
291
|
+
filePath: destination,
|
|
292
|
+
metadata
|
|
290
293
|
});
|
|
291
294
|
resolve();
|
|
292
295
|
});
|
|
@@ -312,7 +315,6 @@ function _createClientInstance(clientID, clientOptions, options = {}, headers =
|
|
|
312
315
|
...options
|
|
313
316
|
}, headers, authURL, authHeaders, useAuthentication, queryAuthToken, onConnect, async () => {
|
|
314
317
|
FileTransferTrackingManager.outputCurrentTransfers();
|
|
315
|
-
FileTransferRecoveryManager.flushToDisk();
|
|
316
318
|
if (onDisconnect) {
|
|
317
319
|
await onDisconnect();
|
|
318
320
|
}
|
package/dist/cjs/FileTide.js
CHANGED
|
@@ -29,7 +29,6 @@ const {
|
|
|
29
29
|
const {
|
|
30
30
|
FileTransferReceiverManager
|
|
31
31
|
} = require("./HUDManagers/FileTransferReceiverManager.js");
|
|
32
|
-
const FileTransferRecoveryManager = require("./HUDManagers/FileTransferRecoveryManager.js");
|
|
33
32
|
const TideTokenEnforcer = require("./HUDManagers/TideTokenEnforcementManager.js");
|
|
34
33
|
const {
|
|
35
34
|
FileNetConfigManager
|
|
@@ -198,15 +197,6 @@ class FileTide {
|
|
|
198
197
|
|
|
199
198
|
// --- FileTide Transfer State Management ---
|
|
200
199
|
|
|
201
|
-
async getTidingTransferStates() {
|
|
202
|
-
return await TideTokenEnforcer.protect(() => FileTransferRecoveryManager.memoryStorage, "default")();
|
|
203
|
-
}
|
|
204
|
-
saveTransferStates() {
|
|
205
|
-
TideTokenEnforcer.protect(() => {
|
|
206
|
-
FileTransferRecoveryManager.flushToDisk();
|
|
207
|
-
}, "default")();
|
|
208
|
-
}
|
|
209
|
-
|
|
210
200
|
// --- FileTide Remote Files Management ---
|
|
211
201
|
|
|
212
202
|
listFilesFromClient(recipientID, depth = 1) {
|
|
@@ -270,8 +260,9 @@ class FileTide {
|
|
|
270
260
|
* @param {Number} minTideSize - The minimum tide size in sending files (10).
|
|
271
261
|
* @param {Number} maxTideSize - The maximum tide size in sending files (2000).
|
|
272
262
|
* @param {Number} transferRequestExpirationTime - The maximum time until the transfer barrier times out the transfer request.
|
|
263
|
+
* @param {Object} metadata - Any additional identifying data attached to the transfer.
|
|
273
264
|
*/
|
|
274
|
-
async sendToDevice(recipientID, filePath, destinationPath, filterDirectoryContent = [], tideSize = 200, tidalSize = 500, minTideSize = 10, maxTideSize = 2000, transferRequestExpirationTime = 30000) {
|
|
265
|
+
async sendToDevice(recipientID, filePath, destinationPath, filterDirectoryContent = [], tideSize = 200, tidalSize = 500, minTideSize = 10, maxTideSize = 2000, transferRequestExpirationTime = 30000, metadata = {}) {
|
|
275
266
|
return await TideTokenEnforcer.protect(async () => {
|
|
276
267
|
const clientID = this.currentUserID;
|
|
277
268
|
const clientMessager = this.clients.get(clientID);
|
|
@@ -295,19 +286,23 @@ class FileTide {
|
|
|
295
286
|
FileTide.outputGradient(`[${clientID}] File at path ${filePath} not found.`, errorMessageColors);
|
|
296
287
|
return false;
|
|
297
288
|
}
|
|
289
|
+
const transferMetadata = {
|
|
290
|
+
...(metadata ?? {}),
|
|
291
|
+
contentType: fileDetails.type
|
|
292
|
+
};
|
|
298
293
|
if (fileDetails.type === "file") {
|
|
299
294
|
if (fileDetails.largeFile) {
|
|
300
295
|
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);
|
|
296
|
+
await clientMessager.sendFile(clientID, recipientID, fileDetails.fileName, fileDetails.filePath, destinationPath, fileDetails.fileSize, tidalSize, minTideSize, maxTideSize, true, false, true, transferRequestExpirationTime, transferMetadata);
|
|
302
297
|
return true;
|
|
303
298
|
}
|
|
304
299
|
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);
|
|
300
|
+
await clientMessager.sendFile(clientID, recipientID, fileDetails.content.fileName, fileDetails.content.filePath, destinationPath, fileDetails.content.size, tideSize, minTideSize, maxTideSize, true, false, false, transferRequestExpirationTime, transferMetadata);
|
|
306
301
|
return true;
|
|
307
302
|
}
|
|
308
303
|
if (fileDetails.type === "directory") {
|
|
309
304
|
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);
|
|
305
|
+
await clientMessager.sendDirectoryFiles(clientID, recipientID, fileDetails.content, this.getTidePath(filePath), destinationPath, tideSize, minTideSize, maxTideSize, true, true, false, transferRequestExpirationTime, transferMetadata);
|
|
311
306
|
return true;
|
|
312
307
|
}
|
|
313
308
|
FileTide.outputGradient(`[FileTide] ~ No active client ~ ${recipientID} found.`, errorMessageColors);
|
|
@@ -567,24 +562,6 @@ function _setupFileEventListeners(userID, client, onTransferProgress, onIncoming
|
|
|
567
562
|
});
|
|
568
563
|
return;
|
|
569
564
|
});
|
|
570
|
-
client.clientTide.onEvent(userID, "save-current-transfer-states", async data => {
|
|
571
|
-
this.saveTransferStates();
|
|
572
|
-
return;
|
|
573
|
-
});
|
|
574
|
-
client.clientTide.onEvent(userID, "current-transfer-state", async data => {
|
|
575
|
-
const {
|
|
576
|
-
senderID,
|
|
577
|
-
fileName,
|
|
578
|
-
filePath
|
|
579
|
-
} = data;
|
|
580
|
-
const currentTransferState = FileTransferRecoveryManager.getTransferState(userID, senderID, `${filePath}-${fileName}`);
|
|
581
|
-
client.clientTide.emitEvent(userID, "send-current-transfer-state", {
|
|
582
|
-
recipientID: userID,
|
|
583
|
-
senderID,
|
|
584
|
-
transferState: currentTransferState
|
|
585
|
-
});
|
|
586
|
-
return;
|
|
587
|
-
});
|
|
588
565
|
client.clientTide.onEvent(userID, "queue-incoming-transfer", async data => {
|
|
589
566
|
if (this.transferBarrier && onIncomingTransfer) {
|
|
590
567
|
onIncomingTransfer(data, status => {
|
|
@@ -670,11 +647,6 @@ function _setupFileEventListeners(userID, client, onTransferProgress, onIncoming
|
|
|
670
647
|
}
|
|
671
648
|
await fileTransferReceiver.handleTransferProgress(data);
|
|
672
649
|
this.progressBarManager.updateTaskProgress(data.fileName, data.chunkSize || 512 * 1024);
|
|
673
|
-
const currentTransferState = FileTransferRecoveryManager.getTransferState(userID, data.senderName, `${data.path}-${data.fileName}`) || {
|
|
674
|
-
transferredSize: 0
|
|
675
|
-
};
|
|
676
|
-
currentTransferState.transferredSize += data.chunkSize || 512 * 1024;
|
|
677
|
-
FileTransferRecoveryManager.saveTransferState(userID, data.senderName, `${data.path}-${data.fileName}`, data.chunkIndex, currentTransferState.transferredSize);
|
|
678
650
|
const taskBarStats = this.progressBarManager.getTaskBar(data.fileName);
|
|
679
651
|
client.clientTide.emitEvent(userID, "acknowledge-transfer-tide", {
|
|
680
652
|
fileName: data.fileName,
|
|
@@ -682,12 +654,14 @@ function _setupFileEventListeners(userID, client, onTransferProgress, onIncoming
|
|
|
682
654
|
recipientName: userID,
|
|
683
655
|
transferStateID: `${data.path}-${data.fileName}`,
|
|
684
656
|
path: data.path,
|
|
685
|
-
transferStats: taskBarStats
|
|
657
|
+
transferStats: taskBarStats,
|
|
658
|
+
metadata: data.metadata
|
|
686
659
|
});
|
|
687
660
|
if (onTransferProgress) {
|
|
688
661
|
onTransferProgress({
|
|
689
662
|
...data,
|
|
690
|
-
stats: taskBarStats
|
|
663
|
+
stats: taskBarStats,
|
|
664
|
+
metadata: data.metadata
|
|
691
665
|
});
|
|
692
666
|
}
|
|
693
667
|
});
|
|
@@ -729,7 +703,6 @@ function _setupFileEventListeners(userID, client, onTransferProgress, onIncoming
|
|
|
729
703
|
if (transferState.fileStream) {
|
|
730
704
|
fileTransferReceiver.completeTransfer(data, (transferData, transfers, success, error) => {
|
|
731
705
|
if (success) {
|
|
732
|
-
FileTransferRecoveryManager.clearTransferState(userID, data.senderID, `${data.filePath}-${data.fileName}`);
|
|
733
706
|
_FileTide.outputGradient(`[${userID}] File saved at ~ ${savePath}\n`, significantMessageColors);
|
|
734
707
|
} else if (!success) {
|
|
735
708
|
_FileTide.outputGradient(`[${userID}] Did not save file at ~ ${savePath}\n\t${error}\n`, errorMessageColors);
|
|
@@ -748,7 +721,6 @@ function _setupFileEventListeners(userID, client, onTransferProgress, onIncoming
|
|
|
748
721
|
});
|
|
749
722
|
return;
|
|
750
723
|
}
|
|
751
|
-
FileTransferRecoveryManager.clearTransferState(userID, data.senderID, `${data.filePath}-${data.fileName}`);
|
|
752
724
|
FileTransferTrackingManager.untrackTransfer(data.fileName);
|
|
753
725
|
_FileTide.outputGradient(`[${userID}] Transfer successfully sent to ~ ${data.recipientId} and saved at ~ ${path.join(data.filePath, data.fileName)}\n`, significantMessageColors);
|
|
754
726
|
if (onTransferComplete) {
|
|
@@ -4,7 +4,6 @@ function _classPrivateMethodInitSpec(e, a) { _checkPrivateRedeclaration(e, a), a
|
|
|
4
4
|
function _checkPrivateRedeclaration(e, t) { if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object"); }
|
|
5
5
|
function _assertClassBrand(e, t, n) { if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n; throw new TypeError("Private element is not present on this object"); }
|
|
6
6
|
const fs = require("fs");
|
|
7
|
-
const FileTransferRecoveryManager = require("./FileTransferRecoveryManager.js");
|
|
8
7
|
var _FileTransferManager_brand = /*#__PURE__*/new WeakSet();
|
|
9
8
|
class FileTransferManager {
|
|
10
9
|
constructor({
|
|
@@ -41,23 +40,14 @@ class FileTransferManager {
|
|
|
41
40
|
onTiding
|
|
42
41
|
}, clientTide) {
|
|
43
42
|
const transferId = _assertClassBrand(_FileTransferManager_brand, this, _generateTransferId).call(this, fileDetails);
|
|
44
|
-
const recoveredTransferState = (await clientTide.emitEventWithResponse(originDetails.senderID, "get-client-transfer-state", "sent-current-transfer-state", {
|
|
45
|
-
recipientID,
|
|
46
|
-
senderID: originDetails.senderID,
|
|
47
|
-
filePath: fileDetails.destinationPath,
|
|
48
|
-
fileName: fileDetails.name
|
|
49
|
-
}, 30000)) || {
|
|
50
|
-
transferredSize: 0,
|
|
51
|
-
lastChunkSent: 0
|
|
52
|
-
};
|
|
53
43
|
const totalChunks = Math.ceil(fileDetails.size / this.chunkSize);
|
|
54
44
|
this.activeTransfers.set(transferId, {
|
|
55
45
|
totalChunks,
|
|
56
|
-
transferredSize:
|
|
57
|
-
completedChunks:
|
|
46
|
+
transferredSize: 0,
|
|
47
|
+
completedChunks: 0,
|
|
58
48
|
activeChunks: 0,
|
|
59
49
|
failedChunks: new Map(),
|
|
60
|
-
currentChunk:
|
|
50
|
+
currentChunk: 0,
|
|
61
51
|
size: fileDetails.size
|
|
62
52
|
});
|
|
63
53
|
const updateProgress = () => {
|
|
@@ -67,7 +57,7 @@ class FileTransferManager {
|
|
|
67
57
|
}
|
|
68
58
|
};
|
|
69
59
|
const exponentialBackoff = retryCount => Math.min(1000 * 2 ** retryCount, 10000);
|
|
70
|
-
let nextExpectedChunk =
|
|
60
|
+
let nextExpectedChunk = 0;
|
|
71
61
|
const chunkBuffer = new Map();
|
|
72
62
|
const sendChunk = async chunkIndex => {
|
|
73
63
|
const start = chunkIndex * this.chunkSize;
|
|
@@ -145,25 +135,16 @@ class FileTransferManager {
|
|
|
145
135
|
}
|
|
146
136
|
}
|
|
147
137
|
async function _startTransfer(file, transferId, fileDetails, originDetails, onSendChunk, onComplete, onProgress, onStart, onTiding, clientTide) {
|
|
148
|
-
const recoveredTransferState = (await clientTide.emitEventWithResponse(originDetails.senderID, "get-client-transfer-state", "sent-current-transfer-state", {
|
|
149
|
-
recipientID: originDetails.recipientID,
|
|
150
|
-
senderID: originDetails.senderID,
|
|
151
|
-
filePath: fileDetails.destinationPath,
|
|
152
|
-
fileName: fileDetails.name
|
|
153
|
-
}, 30000)) || {
|
|
154
|
-
transferredSize: 0,
|
|
155
|
-
lastChunkSent: 0
|
|
156
|
-
};
|
|
157
138
|
const totalChunks = Math.ceil(file.length / this.chunkSize);
|
|
158
|
-
let nextExpectedChunk =
|
|
139
|
+
let nextExpectedChunk = 0;
|
|
159
140
|
const chunkBuffer = new Map();
|
|
160
141
|
this.activeTransfers.set(transferId, {
|
|
161
142
|
totalChunks,
|
|
162
|
-
transferredSize:
|
|
163
|
-
completedChunks:
|
|
143
|
+
transferredSize: 0,
|
|
144
|
+
completedChunks: 0,
|
|
164
145
|
activeChunks: 0,
|
|
165
146
|
failedChunks: new Map(),
|
|
166
|
-
currentChunk:
|
|
147
|
+
currentChunk: 0,
|
|
167
148
|
size: fileDetails.size
|
|
168
149
|
});
|
|
169
150
|
const transferState = this.activeTransfers.get(transferId);
|
|
@@ -235,17 +216,15 @@ async function _startTransfer(file, transferId, fileDetails, originDetails, onSe
|
|
|
235
216
|
}
|
|
236
217
|
/*async #startTransfer(file, transferId, fileDetails, originDetails, onSendChunk, onComplete, onProgress, onStart, onTiding, clientTide)
|
|
237
218
|
{
|
|
238
|
-
const recoveredTransferState = await clientTide.emitEventWithResponse(originDetails.senderID, "get-client-transfer-state", "sent-current-transfer-state", { recipientID : originDetails.recipientID, senderID : originDetails.senderID, filePath : fileDetails.destinationPath, fileName : fileDetails.name }, 30000) || { transferredSize : 0, lastChunkSent : 0 };
|
|
239
|
-
|
|
240
219
|
const totalChunks = Math.ceil(file.length / this.chunkSize);
|
|
241
220
|
|
|
242
221
|
this.activeTransfers.set(transferId, {
|
|
243
222
|
totalChunks,
|
|
244
|
-
transferredSize :
|
|
245
|
-
completedChunks :
|
|
223
|
+
transferredSize : 0,
|
|
224
|
+
completedChunks : 0,
|
|
246
225
|
activeChunks : 0,
|
|
247
226
|
failedChunks : new Map(),
|
|
248
|
-
currentChunk :
|
|
227
|
+
currentChunk : 0,
|
|
249
228
|
size : fileDetails.size
|
|
250
229
|
});
|
|
251
230
|
const updateProgress = () => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trap_stevo/filetide",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.81",
|
|
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": {
|
|
@@ -36,11 +36,11 @@
|
|
|
36
36
|
"license": "See License in LICENSE.md",
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"@trap_stevo/iotide": "^0.0.46",
|
|
39
|
-
"@trap_stevo/iotide-client": "^0.0.
|
|
40
|
-
"@trap_stevo/legendarybuilderpronodejs-utilities": "^1.0.
|
|
39
|
+
"@trap_stevo/iotide-client": "^0.0.27",
|
|
40
|
+
"@trap_stevo/legendarybuilderpronodejs-utilities": "^1.0.51",
|
|
41
41
|
"@trap_stevo/lockline": "^0.0.11",
|
|
42
|
-
"@trap_stevo/logictide": "^0.0.
|
|
43
|
-
"@trap_stevo/metrictide": "^0.0.
|
|
42
|
+
"@trap_stevo/logictide": "^0.0.2",
|
|
43
|
+
"@trap_stevo/metrictide": "^0.0.10",
|
|
44
44
|
"@trap_stevo/timelyst": "^0.0.7",
|
|
45
45
|
"chalk": "^4.1.2",
|
|
46
46
|
"readline": "^1.3.0"
|