@trap_stevo/filetide 0.0.47 → 0.0.48

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.
@@ -325,7 +325,7 @@ class FileMessager {
325
325
  ...data,
326
326
  transferType: "send"
327
327
  });
328
- this.transferQueue.waitForData(data.transferID, () => this.currentTransferBarrierTransfers.get(data.transferID), [true, false], 100, 50000).then(accepted => {
328
+ this.transferQueue.waitForData(data.transferID, () => this.currentTransferBarrierTransfers.get(data.transferID), [true, false], 100, data.transferExpirationTime ? data.transferExpirationTime : 50000).then(accepted => {
329
329
  console.log(`[FileTide ~ Net Barrier] ~ Transfer ${accepted ? "accepted!" : "denied."}`);
330
330
  this.fileNet.emitToTide(senderClient.tideID, "transfer-barrier-response", accepted);
331
331
  this.currentTransferBarrierTransfers.delete(data.transferID);
@@ -67,8 +67,9 @@ class FileMessagerClient {
67
67
  });
68
68
  };
69
69
  }
70
- async requestTransfer(clientID, senderID, filePath, destinationPath, filterContent = []) {
71
- const transferAllowed = await this.allowedTransfer(clientID, senderID, destinationPath, "N/A", "requestSend");
70
+ async requestTransfer(clientID, senderID, filePath, destinationPath, filterContent = [], transferRequestExpirationTime = 30000) {
71
+ const transferContentType = FileUtilityManager.inferPathType(filePath);
72
+ const transferAllowed = await this.allowedTransfer(clientID, senderID, destinationPath, filePath, "N/A", transferContentType === "file" ? 1 : "N/A", transferContentType, "requestSend", transferRequestExpirationTime);
72
73
  if (!transferAllowed) {
73
74
  return;
74
75
  }
@@ -89,7 +90,7 @@ class FileMessagerClient {
89
90
  });
90
91
  return;
91
92
  }
92
- async allowedTransfer(clientID, recipientID, filePath, fileSize, transferType = "send") {
93
+ async allowedTransfer(clientID, recipientID, filePath, originPath, fileSize, fileCount = 1, transferContentType = "file", transferType = "send", transferExpirationTime = 30000) {
93
94
  try {
94
95
  const currentDate = Date.now();
95
96
  const transferID = `${clientID}_${filePath}_${currentDate}`;
@@ -97,10 +98,16 @@ class FileMessagerClient {
97
98
  clientID,
98
99
  recipientID,
99
100
  transferID,
101
+ originPath,
100
102
  path: filePath,
101
103
  date: currentDate,
104
+ transferExpirationTime,
105
+ timeUntilTransferExpiration: transferExpirationTime,
106
+ itemCount: fileCount,
107
+ itemSize: fileSize,
108
+ transferContentType,
102
109
  transferType
103
- }, 30000);
110
+ }, transferExpirationTime);
104
111
  if (!transferAccepted) {
105
112
  FileNetUtilityManager.outputGradient(`[FileTide ~ File Messager] ${recipientID} denied your transfer.`, errorMessageColors);
106
113
  return false;
@@ -124,12 +131,13 @@ class FileMessagerClient {
124
131
  * @param {string} recipientId - The ID of the recipient.
125
132
  * @param {Array} filesData - Array of file data objects from the directory.
126
133
  * @param {string} baseDirectory - The base directory path that contains the files.
127
- * @param {string} destinationPath - The path to which the files should be sent.
128
- * @param {Number} tideSize - The tide size in sending files (500)
129
- * @param {Number} minTideSize - The minimum tide size in sending files (10)
130
- * @param {Number} maxTideSize - The maximum tide size in sending files (2000)
134
+ * @param {string} destinationPath - The path to which the files should get sent.
135
+ * @param {Number} tideSize - The tide size in sending files (500).
136
+ * @param {Number} minTideSize - The minimum tide size in sending files (10).
137
+ * @param {Number} maxTideSize - The maximum tide size in sending files (2000).
138
+ * @param {Number} transferRequestExpirationTime - The maximum time until the transfer barrier times out the transfer request.
131
139
  */
132
- async sendDirectoryFiles(clientID, recipientId, filesData, baseDirectory, destinationPath, tideSize = 500, minTideSize = 10, maxTideSize = 2000) {
140
+ async sendDirectoryFiles(clientID, recipientId, filesData, baseDirectory, destinationPath, tideSize = 500, minTideSize = 10, maxTideSize = 2000, transferRequestExpirationTime = 30000) {
133
141
  try {
134
142
  const baseDirectoryName = path.basename(baseDirectory);
135
143
  const adjustedDestinationPath = FileUtilityManager.normalizePath(path.join(destinationPath, baseDirectoryName));
@@ -138,7 +146,7 @@ class FileMessagerClient {
138
146
  totalSize += fileInfo.size;
139
147
  });
140
148
  const incomingType = this.activeTransferTypes.get(destinationPath);
141
- const transferAllowed = incomingType && incomingType === "requestedTransfer" ? true : await this.allowedTransfer(clientID, recipientId, adjustedDestinationPath, totalSize, "send");
149
+ const transferAllowed = incomingType && incomingType === "requestedTransfer" ? true : await this.allowedTransfer(clientID, recipientId, adjustedDestinationPath, baseDirectory, totalSize, filesData.length, "directory", "send", transferRequestExpirationTime);
142
150
  if (incomingType) {
143
151
  this.activeTransferTypes.delete(destinationPath);
144
152
  }
@@ -149,23 +157,23 @@ class FileMessagerClient {
149
157
  const relativeFilePath = path.dirname(path.relative(baseDirectory, fileInfo.filePath));
150
158
  const fileDestinationPath = FileUtilityManager.normalizePath(path.join(adjustedDestinationPath, relativeFilePath));
151
159
  if (fileInfo.largeFile) {
152
- return await this.sendDirectoryLargeFile(clientID, recipientId, fileInfo.fileName, fileInfo.filePath, fileDestinationPath, fileInfo.fileSize, index, tideSize, minTideSize, maxTideSize);
160
+ return await this.sendDirectoryLargeFile(clientID, recipientId, fileInfo.fileName, fileInfo.filePath, fileDestinationPath, fileInfo.fileSize, index, tideSize, minTideSize, maxTideSize, transferRequestExpirationTime);
153
161
  }
154
- return await this.sendDirectoryFile(clientID, recipientId, fileInfo.fileName, fileInfo.filePath, fileInfo.size, fileDestinationPath, index, tideSize, minTideSize, maxTideSize);
162
+ return await this.sendDirectoryFile(clientID, recipientId, fileInfo.fileName, fileInfo.filePath, fileInfo.size, fileDestinationPath, index, tideSize, minTideSize, maxTideSize, transferRequestExpirationTime);
155
163
  });
156
164
  Promise.all(sendFilePromises).then(() => console.log("\nAll files in directory transferred successfully!")).catch(error => console.error("Did not transfer directory: ", error));
157
165
  } catch (error) {
158
166
  FileNetUtilityManager.outputGradient(`[FileTide ~ File Messager] ~ Refused directory transfer: ${error}`, errorMessageColors);
159
167
  }
160
168
  }
161
- async sendDirectoryLargeFile(clientID, recipientId, fileName, filePath = process.cwd(), destinationPath = null, fileSize, index = 0, tideSize = 500, minTideSize = 10, maxTideSize = 2000) {
169
+ async sendDirectoryLargeFile(clientID, recipientId, fileName, filePath = process.cwd(), destinationPath = null, fileSize, index = 0, tideSize = 500, minTideSize = 10, maxTideSize = 2000, transferRequestExpirationTime = 30000) {
162
170
  let initiatingTransfer = false;
163
171
  if (index === 0) {
164
172
  initiatingTransfer = true;
165
173
  }
166
- return await this.sendFile(clientID, recipientId, fileName, filePath, destinationPath, fileSize, tideSize, minTideSize, maxTideSize, initiatingTransfer, true, true, true);
174
+ return await this.sendFile(clientID, recipientId, fileName, filePath, destinationPath, fileSize, tideSize, minTideSize, maxTideSize, initiatingTransfer, true, true, true, transferRequestExpirationTime);
167
175
  }
168
- async sendDirectoryFile(clientID, recipientId, fileName, filePath = process.cwd(), fileSize, directoryPath = null, index = 0, tideSize = 200, minTideSize = 10, maxTideSize = 2000) {
176
+ async sendDirectoryFile(clientID, recipientId, fileName, filePath = process.cwd(), fileSize, directoryPath = null, index = 0, tideSize = 200, minTideSize = 10, maxTideSize = 2000, transferRequestExpirationTime = 30000) {
169
177
  if (!filePath) {
170
178
  return;
171
179
  }
@@ -180,14 +188,14 @@ class FileMessagerClient {
180
188
  });
181
189
  initiatingTransfer = true;
182
190
  }
183
- return await this.sendFile(clientID, recipientId, fileName, filePath, directoryPath, fileSize, tideSize, minTideSize, maxTideSize, initiatingTransfer, true, true, false);
191
+ return await this.sendFile(clientID, recipientId, fileName, filePath, directoryPath, fileSize, tideSize, minTideSize, maxTideSize, initiatingTransfer, true, true, false, transferRequestExpirationTime);
184
192
  }
185
- async sendFile(clientID, recipientId, fileName, filePath = process.cwd(), destination = process.cwd(), fileSize, tideSize = 500, minTideSize = 10, maxTideSize = 2000, initiatingTransfer = true, inDirectory = false, largeFile = false) {
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) {
186
194
  const destinationPath = FileUtilityManager.normalizePath(path.join(destination, fileName));
187
195
  FileNetUtilityManager.outputGradient(largeFile ? `[FileTide ~ File Messager] ~ Requesting to transfer large file ~ ${destinationPath} to ${recipientId}!` : `[FileTide ~ File Messager] ~ Requesting to transfer ~ ${destinationPath} to ${recipientId}!`, significantMessageColors);
188
196
  const incomingType = this.activeTransferTypes.get(filePath);
189
197
  if (!inDirectory && initiatingTransfer) {
190
- const transferAllowed = incomingType && incomingType === "requestedTransfer" ? true : await this.allowedTransfer(clientID, recipientId, destinationPath, fileSize, "send");
198
+ const transferAllowed = incomingType && incomingType === "requestedTransfer" ? true : await this.allowedTransfer(clientID, recipientId, destinationPath, filePath, fileSize, 1, "file", "send", transferRequestExpirationTime);
191
199
  if (incomingType) {
192
200
  this.activeTransferTypes.delete(filePath);
193
201
  }
@@ -176,16 +176,17 @@ class FileTide {
176
176
 
177
177
  /**
178
178
  * Send files / directories directly to a device.
179
- * @param {String} recipientID - The ID of the client device to send the data to
180
- * @param {Buffer} fileData - The path of the data to send
181
- * @param {String} destinationPath - The destination path on the device
182
- * @param {Array} filterDirectoryContent - List of paths to filter
183
- * @param {Number} tideSize - The tide size in sending smaller to medium files (200)
184
- * @param {Number} tidalSize - The tide size in sending large files (500)
185
- * @param {Number} minTideSize - The minimum tide size in sending files (10)
186
- * @param {Number} maxTideSize - The maximum tide size in sending files (2000)
179
+ * @param {String} recipientID - The ID of the client device to send the data to.
180
+ * @param {Buffer} fileData - The path of the data to send.
181
+ * @param {String} destinationPath - The destination path on the device.
182
+ * @param {Array} filterDirectoryContent - List of paths to filter.
183
+ * @param {Number} tideSize - The tide size in sending smaller to medium files (200).
184
+ * @param {Number} tidalSize - The tide size in sending large files (500).
185
+ * @param {Number} minTideSize - The minimum tide size in sending files (10).
186
+ * @param {Number} maxTideSize - The maximum tide size in sending files (2000).
187
+ * @param {Number} transferRequestExpirationTime - The maximum time until the transfer barrier times out the transfer request.
187
188
  */
188
- async sendToDevice(recipientID, filePath, destinationPath, filterDirectoryContent = [], tideSize = 200, tidalSize = 500, minTideSize = 10, maxTideSize = 2000) {
189
+ async sendToDevice(recipientID, filePath, destinationPath, filterDirectoryContent = [], tideSize = 200, tidalSize = 500, minTideSize = 10, maxTideSize = 2000, transferRequestExpirationTime = 30000) {
189
190
  const clientID = this.currentUserID;
190
191
  const clientMessager = this.clients.get(clientID);
191
192
  if (!clientMessager) {
@@ -207,16 +208,16 @@ class FileTide {
207
208
  if (fileDetails.type === "file") {
208
209
  if (fileDetails.largeFile) {
209
210
  FileTide.outputGradient(`[${clientID}] Sending large file ~ ${fileDetails.fileName} to client ~ ${recipientID}...`, ["#00C897", "#00E0FF"]);
210
- await clientMessager.sendFile(clientID, recipientID, fileDetails.fileName, fileDetails.filePath, destinationPath, fileDetails.fileSize, tidalSize, minTideSize, maxTideSize, true, false, true);
211
+ await clientMessager.sendFile(clientID, recipientID, fileDetails.fileName, fileDetails.filePath, destinationPath, fileDetails.fileSize, tidalSize, minTideSize, maxTideSize, true, false, true, transferRequestExpirationTime);
211
212
  return true;
212
213
  }
213
214
  FileTide.outputGradient(`[${clientID}] Sending file ~ ${fileDetails.content.fileName} to client ~ ${recipientID}...`, ["#00C897", "#00E0FF"]);
214
- await clientMessager.sendFile(clientID, recipientID, fileDetails.content.fileName, fileDetails.content.filePath, destinationPath, fileDetails.content.size, tideSize, minTideSize, maxTideSize);
215
+ await clientMessager.sendFile(clientID, recipientID, fileDetails.content.fileName, fileDetails.content.filePath, destinationPath, fileDetails.content.size, tideSize, minTideSize, maxTideSize, transferRequestExpirationTime);
215
216
  return true;
216
217
  }
217
218
  if (fileDetails.type === "directory") {
218
219
  FileTide.outputGradient(`[${clientID}] Sending ${fileDetails.content.length} files in directory ~ ${path.basename(filePath)} to client ~ ${recipientID}...`, ["#00C897", "#00E0FF"]);
219
- await clientMessager.sendDirectoryFiles(clientID, recipientID, fileDetails.content, this.getTidePath(filePath), destinationPath, tideSize, minTideSize, maxTideSize);
220
+ await clientMessager.sendDirectoryFiles(clientID, recipientID, fileDetails.content, this.getTidePath(filePath), destinationPath, tideSize, minTideSize, maxTideSize, transferRequestExpirationTime);
220
221
  return true;
221
222
  }
222
223
  FileTide.outputGradient(`[FileTide] ~ No active client ~ ${recipientID} found.`, errorMessageColors);
@@ -211,6 +211,19 @@ class FileUtilityManager {
211
211
  return stats.isDirectory();
212
212
  }
213
213
 
214
+ /**
215
+ * Determines the type of a given path (directory or file) based on conventions.
216
+ * @param {string} inputPath - The path to infer.
217
+ * @returns {string} - Returns "directory" if the path has no extension, "file" if it contains an extension.
218
+ */
219
+ static inferPathType(inputPath) {
220
+ const parsedPath = path.parse(inputPath);
221
+ if (parsedPath.ext) {
222
+ return "file";
223
+ }
224
+ return "directory";
225
+ }
226
+
214
227
  /**
215
228
  * Helper function to check if a path exists.
216
229
  * @param {string} inputPath - The path to check.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trap_stevo/filetide",
3
- "version": "0.0.47",
3
+ "version": "0.0.48",
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": {