@trap_stevo/filetide 0.0.47 → 0.0.49
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
|
@@ -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
|
|
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
|
-
},
|
|
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
|
|
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
|
}
|
package/dist/cjs/FileTide.js
CHANGED
|
@@ -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);
|
|
@@ -434,7 +435,11 @@ function _setupFileEventListeners(userID, client, onTransferProgress, onIncoming
|
|
|
434
435
|
});
|
|
435
436
|
}
|
|
436
437
|
if (onIncomingFile) {
|
|
437
|
-
|
|
438
|
+
const taskBarStats = this.progressBarManager.getTaskBar(data.fileName);
|
|
439
|
+
onIncomingFile(verifiedSender, {
|
|
440
|
+
...data,
|
|
441
|
+
stats: taskBarStats
|
|
442
|
+
}, fileTransferReceiver.activeTransfers);
|
|
438
443
|
}
|
|
439
444
|
if (verifiedSender && !fs.existsSync(saveDir)) {
|
|
440
445
|
fs.mkdirSync(saveDir, {
|
|
@@ -470,7 +475,11 @@ function _setupFileEventListeners(userID, client, onTransferProgress, onIncoming
|
|
|
470
475
|
currentTransferState.transferredSize += data.chunkSize || 512 * 1024;
|
|
471
476
|
FileTransferRecoveryManager.saveTransferState(userID, data.senderName, `${data.path}-${data.fileName}`, data.chunkIndex, currentTransferState.transferredSize);
|
|
472
477
|
if (onTransferProgress) {
|
|
473
|
-
|
|
478
|
+
const taskBarStats = this.progressBarManager.getTaskBar(data.fileName);
|
|
479
|
+
onTransferProgress({
|
|
480
|
+
...data,
|
|
481
|
+
stats: taskBarStats
|
|
482
|
+
});
|
|
474
483
|
}
|
|
475
484
|
});
|
|
476
485
|
client.clientTide.onEvent(userID, "transfer-status", data => {
|
|
@@ -488,7 +497,11 @@ function _setupFileEventListeners(userID, client, onTransferProgress, onIncoming
|
|
|
488
497
|
}
|
|
489
498
|
this.progressBarManager.updateTaskProgress(fileName, chunkSize);
|
|
490
499
|
if (onTransferStatus) {
|
|
491
|
-
|
|
500
|
+
const taskBarStats = this.progressBarManager.getTaskBar(fileName);
|
|
501
|
+
onTransferStatus({
|
|
502
|
+
...data,
|
|
503
|
+
stats: taskBarStats
|
|
504
|
+
});
|
|
492
505
|
}
|
|
493
506
|
return;
|
|
494
507
|
});
|
|
@@ -508,13 +521,21 @@ function _setupFileEventListeners(userID, client, onTransferProgress, onIncoming
|
|
|
508
521
|
_FileTide.outputGradient(`[${userID}] Did not save file at : ${savePath}\n\t${error}\n`, errorMessageColors);
|
|
509
522
|
}
|
|
510
523
|
if (onTransferComplete) {
|
|
511
|
-
|
|
524
|
+
const taskBarStats = this.progressBarManager.getTaskBar(data.fileName);
|
|
525
|
+
onTransferComplete({
|
|
526
|
+
...data,
|
|
527
|
+
stats: taskBarStats
|
|
528
|
+
}, fileTransferReceiver.activeTransfers, success);
|
|
512
529
|
}
|
|
513
530
|
});
|
|
514
531
|
} catch (error) {
|
|
515
532
|
_FileTide.outputGradient(`[${userID}] Did not save file at : ${savePath}\n${error}`, errorMessageColors);
|
|
516
533
|
if (onTransferComplete) {
|
|
517
|
-
|
|
534
|
+
const taskBarStats = this.progressBarManager.getTaskBar(data.fileName);
|
|
535
|
+
onTransferComplete({
|
|
536
|
+
...data,
|
|
537
|
+
stats: taskBarStats
|
|
538
|
+
}, fileTransferReceiver.activeTransfers, false);
|
|
518
539
|
}
|
|
519
540
|
}
|
|
520
541
|
});
|
|
@@ -4,7 +4,8 @@ const readline = require("readline");
|
|
|
4
4
|
const chalk = require("chalk");
|
|
5
5
|
class ConsoleProgressBarManager {
|
|
6
6
|
constructor(tasks = [], options = {}) {
|
|
7
|
-
|
|
7
|
+
const rows = process.stdout.rows || 24;
|
|
8
|
+
this.visibleBars = rows - 3;
|
|
8
9
|
this.currentPage = 0;
|
|
9
10
|
this.barsPerPage = this.visibleBars;
|
|
10
11
|
this.maxCompletionFeedSize = 5;
|
|
@@ -107,8 +108,10 @@ class ConsoleProgressBarManager {
|
|
|
107
108
|
};
|
|
108
109
|
},
|
|
109
110
|
redraw: () => {
|
|
110
|
-
|
|
111
|
-
|
|
111
|
+
if (!isNaN(newBar.taskIndex) && !isNaN(this.barsPerPage)) {
|
|
112
|
+
readline.cursorTo(process.stdout, 0, newBar.taskIndex % this.barsPerPage);
|
|
113
|
+
process.stdout.clearLine();
|
|
114
|
+
}
|
|
112
115
|
if (newBar.completed) {
|
|
113
116
|
process.stdout.write(settings.taskCompletedColor(`${newBar.taskName}: Completed!`));
|
|
114
117
|
return;
|
|
@@ -167,6 +170,9 @@ class ConsoleProgressBarManager {
|
|
|
167
170
|
this.exitInputListener();
|
|
168
171
|
this.displayPage();
|
|
169
172
|
this.displayCompletionMessage();
|
|
173
|
+
setTimeout(() => {
|
|
174
|
+
this.clearTaskBars();
|
|
175
|
+
}, this.completionTimeout);
|
|
170
176
|
}
|
|
171
177
|
}
|
|
172
178
|
};
|
|
@@ -202,6 +208,55 @@ class ConsoleProgressBarManager {
|
|
|
202
208
|
console.log(chalk.red(`Task ${taskName} not found.`));
|
|
203
209
|
}
|
|
204
210
|
}
|
|
211
|
+
getCurrentStats() {
|
|
212
|
+
const completedTasks = this.taskBars.filter(bar => bar.completed).length;
|
|
213
|
+
const totalTasks = this.taskBars.length;
|
|
214
|
+
const overallProgress = this.taskBars.reduce((acc, bar) => acc + bar.current / bar.totalSize * 100, 0) / totalTasks;
|
|
215
|
+
const stats = {
|
|
216
|
+
completedTasks,
|
|
217
|
+
totalTasks,
|
|
218
|
+
overallProgress: `${overallProgress.toFixed(2)}%`,
|
|
219
|
+
taskDetails: this.taskBars.map(bar => ({
|
|
220
|
+
taskName: bar.taskName,
|
|
221
|
+
progress: `${(bar.current / bar.totalSize * 100).toFixed(2)}%`,
|
|
222
|
+
completed: bar.completed,
|
|
223
|
+
currentSize: bar.getFormattedSize(bar.current),
|
|
224
|
+
totalSize: bar.getFormattedSize(bar.totalSize),
|
|
225
|
+
speed: `${bar.getUnitData(bar.speed).current} ${bar.getUnitData(bar.speed).unit}/s`,
|
|
226
|
+
timeLeft: this.convertSeconds(bar.timeLeft.toFixed(2))
|
|
227
|
+
}))
|
|
228
|
+
};
|
|
229
|
+
return stats;
|
|
230
|
+
}
|
|
231
|
+
getTaskBar(taskID) {
|
|
232
|
+
if (typeof taskID === "string") {
|
|
233
|
+
return this.taskBars.find(bar => bar.taskName === taskID) || null;
|
|
234
|
+
} else if (typeof taskID === "number") {
|
|
235
|
+
return this.taskBars[taskID] || null;
|
|
236
|
+
}
|
|
237
|
+
return null;
|
|
238
|
+
}
|
|
239
|
+
clearTaskBars() {
|
|
240
|
+
this.taskBars = [];
|
|
241
|
+
this.totalTasks = 0;
|
|
242
|
+
this.completedTasksCount = 0;
|
|
243
|
+
this.completionFeed = [];
|
|
244
|
+
this.allTasksCompleted = false;
|
|
245
|
+
}
|
|
246
|
+
clearTaskBar(taskID) {
|
|
247
|
+
let taskIndex = null;
|
|
248
|
+
if (typeof taskID === "string") {
|
|
249
|
+
taskIndex = this.taskBars.findIndex(bar => bar.taskName === taskID);
|
|
250
|
+
} else if (typeof taskID === "number") {
|
|
251
|
+
taskIndex = identifier;
|
|
252
|
+
}
|
|
253
|
+
if (taskIndex !== null && taskIndex >= 0 && taskIndex < this.taskBars.length) {
|
|
254
|
+
this.taskBars.splice(taskIndex, 1);
|
|
255
|
+
this.totalTasks--;
|
|
256
|
+
return true;
|
|
257
|
+
}
|
|
258
|
+
return false;
|
|
259
|
+
}
|
|
205
260
|
clearPage() {
|
|
206
261
|
for (let i = 0; i < this.barsPerPage + 2; i++) {
|
|
207
262
|
readline.cursorTo(process.stdout, 0, i);
|
|
@@ -221,21 +276,27 @@ class ConsoleProgressBarManager {
|
|
|
221
276
|
}
|
|
222
277
|
redrawCompletionFeed(customPagePrefix = "Page", bottomMessage, pageFooterMessageColor = chalk.blue, bottomMessageColor = chalk.gray, recentlyCompletedColor = chalk.green) {
|
|
223
278
|
const bottomPosition = this.barsPerPage;
|
|
224
|
-
|
|
225
|
-
|
|
279
|
+
if (!isNaN(bottomPosition)) {
|
|
280
|
+
readline.cursorTo(process.stdout, 0, bottomPosition);
|
|
281
|
+
process.stdout.clearLine();
|
|
282
|
+
}
|
|
226
283
|
process.stdout.write(pageFooterMessageColor(`${customPagePrefix} ${this.currentPage + 1}/${Math.max(1, Math.ceil(this.taskBars.length / this.barsPerPage))} | Completed: ${this.completedTasksCount}/${this.totalTasks}`));
|
|
227
284
|
if (this.completionFeed.length > 0) {
|
|
228
285
|
process.stdout.write(recentlyCompletedColor(` | Recently completed: ${this.completionFeed.join(", ")}`));
|
|
229
286
|
}
|
|
230
|
-
|
|
231
|
-
|
|
287
|
+
if (!isNaN(bottomPosition)) {
|
|
288
|
+
readline.cursorTo(process.stdout, 0, bottomPosition + 1);
|
|
289
|
+
process.stdout.clearLine();
|
|
290
|
+
}
|
|
232
291
|
if (bottomMessage) {
|
|
233
292
|
process.stdout.write(bottomMessageColor(bottomMessage));
|
|
234
293
|
}
|
|
235
294
|
}
|
|
236
295
|
listenForInput(customPagePrefix = "Page", bottomMessage, bottomMessageColor = chalk.gray, recentlyCompletedColor = chalk.green) {
|
|
237
|
-
|
|
238
|
-
|
|
296
|
+
if (!isNaN(this.barsPerPage)) {
|
|
297
|
+
process.stdin.setRawMode(true);
|
|
298
|
+
process.stdin.resume();
|
|
299
|
+
}
|
|
239
300
|
process.stdin.setEncoding("utf-8");
|
|
240
301
|
this.inputListener = key => {
|
|
241
302
|
if (key === "\u0003") {
|
|
@@ -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.
|
|
3
|
+
"version": "0.0.49",
|
|
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": {
|
|
@@ -10,6 +10,10 @@
|
|
|
10
10
|
"start": "node dist/cjs/FileTide.js"
|
|
11
11
|
},
|
|
12
12
|
"keywords": [
|
|
13
|
+
"Legendary",
|
|
14
|
+
"Enlightened",
|
|
15
|
+
"Steven Compton",
|
|
16
|
+
"Magical",
|
|
13
17
|
"real-time",
|
|
14
18
|
"nodejs",
|
|
15
19
|
"ota",
|