@trap_stevo/filetide 0.0.18 → 0.0.20
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
|
@@ -57,14 +57,14 @@ class FileMessager {
|
|
|
57
57
|
return;
|
|
58
58
|
}
|
|
59
59
|
if (chunkIndex === 0) {
|
|
60
|
-
client.
|
|
60
|
+
this.fileNet.emitToTide(client.tideID, "incoming-file", {
|
|
61
61
|
fileName,
|
|
62
62
|
totalChunks,
|
|
63
63
|
chunkIndex,
|
|
64
64
|
path: filePath
|
|
65
65
|
});
|
|
66
66
|
}
|
|
67
|
-
client.
|
|
67
|
+
this.fileNet.emitToTide(client.tideID, "transfer-progress", {
|
|
68
68
|
fileName,
|
|
69
69
|
fileChunk,
|
|
70
70
|
chunkIndex,
|
|
@@ -73,7 +73,7 @@ class FileMessager {
|
|
|
73
73
|
console.log(`[FileTide ~ File Messager] ~ Sent chunk ${chunkIndex} of ${fileName} to client ~ ${clientId}!`);
|
|
74
74
|
const senderClient = this.onlineClients.get(senderID);
|
|
75
75
|
if (senderClient) {
|
|
76
|
-
senderClient.
|
|
76
|
+
this.fileNet.emitToTide(senderClient.tideID, "transfer-status", {
|
|
77
77
|
status: `Chunk ${chunkIndex} of ${fileName} sent to client ${clientId}!`,
|
|
78
78
|
recipientID: clientId,
|
|
79
79
|
success: true
|
|
@@ -53,16 +53,15 @@ class FileMessagerClient {
|
|
|
53
53
|
*/
|
|
54
54
|
sendDirectoryFiles(clientID, recipientId, filesData, baseDirectory, destinationPath) {
|
|
55
55
|
const baseDirectoryName = path.basename(baseDirectory);
|
|
56
|
-
const adjustedDestinationPath = path.join(destinationPath, baseDirectoryName);
|
|
56
|
+
const adjustedDestinationPath = FileUtilityManager.normalizePath(path.join(destinationPath, baseDirectoryName));
|
|
57
57
|
const sendFilePromises = filesData.map(fileInfo => {
|
|
58
58
|
const relativeFilePath = path.dirname(path.relative(baseDirectory, fileInfo.filePath));
|
|
59
|
-
const fileDestinationPath = path.join(adjustedDestinationPath, relativeFilePath);
|
|
59
|
+
const fileDestinationPath = FileUtilityManager.normalizePath(path.join(adjustedDestinationPath, relativeFilePath));
|
|
60
60
|
return this.sendFile(clientID, recipientId, fileInfo.fileName, fileInfo.fileData, fileDestinationPath);
|
|
61
61
|
});
|
|
62
62
|
Promise.all(sendFilePromises).then(() => console.log("\nAll files in directory transferred successfully!")).catch(error => console.error("Did not transfer files: ", error));
|
|
63
63
|
}
|
|
64
64
|
sendFile(clientID, recipientId, fileName, file, filePath = process.cwd()) {
|
|
65
|
-
console.log(fileName, ": ", file);
|
|
66
65
|
if (!file) {
|
|
67
66
|
return;
|
|
68
67
|
}
|
|
@@ -78,7 +77,6 @@ class FileMessagerClient {
|
|
|
78
77
|
chunkIndex,
|
|
79
78
|
filePath
|
|
80
79
|
});
|
|
81
|
-
console.log(`\nChunk ${chunkIndex} sent successfully!`);
|
|
82
80
|
resolve();
|
|
83
81
|
});
|
|
84
82
|
},
|
|
@@ -94,13 +92,13 @@ class FileMessagerClient {
|
|
|
94
92
|
});
|
|
95
93
|
},
|
|
96
94
|
onProgress: progress => {
|
|
97
|
-
console.log(`\n[FileTide ~ File Messager] ~
|
|
95
|
+
console.log(`\n[FileTide ~ File Messager] ~ ${progress.toFixed(2)}% |>>| ${fileName}`);
|
|
98
96
|
},
|
|
99
97
|
fileDetails: {
|
|
100
98
|
name: fileName,
|
|
101
99
|
path: filePath
|
|
102
100
|
}
|
|
103
|
-
}).then(() => console.log(
|
|
101
|
+
}).then(() => console.log(`[FileTide ~ File Messager] ~ File ~ ${fileName} transfer complete!`)).catch(error => console.error('File transfer failed:', error));
|
|
104
102
|
}
|
|
105
103
|
onFileChunkReceived(userID) {
|
|
106
104
|
this.clientTide.onEvent(userID, "transfer-progress", data => {
|
package/dist/cjs/FileTide.js
CHANGED
|
@@ -95,13 +95,6 @@ class FileTide {
|
|
|
95
95
|
return;
|
|
96
96
|
}
|
|
97
97
|
console.log(`[FileTide] ~ Sending file to client ~ ${userID}...`);
|
|
98
|
-
console.log({
|
|
99
|
-
recipientId: userID,
|
|
100
|
-
senderID,
|
|
101
|
-
fileName,
|
|
102
|
-
filePath,
|
|
103
|
-
fileData
|
|
104
|
-
});
|
|
105
98
|
this.fileNet.transporter.sendFile(fileData, {
|
|
106
99
|
onSendChunk: (transferId, chunkIndex, chunkData, totalChunks) => {
|
|
107
100
|
return new Promise((resolve, reject) => {
|
|
@@ -251,7 +244,7 @@ function _setupFileEventListeners(userID, client, onIncomingFile) {
|
|
|
251
244
|
totalChunks: data.totalChunks,
|
|
252
245
|
fileInfo: data
|
|
253
246
|
});
|
|
254
|
-
const saveDir = data.path;
|
|
247
|
+
const saveDir = path.resolve(data.path);
|
|
255
248
|
if (!fs.existsSync(saveDir)) {
|
|
256
249
|
fs.mkdirSync(saveDir, {
|
|
257
250
|
recursive: true
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const chalk = require("chalk");
|
|
4
|
+
const readline = require("readline");
|
|
5
|
+
let progressBars = [];
|
|
6
|
+
let logs = [];
|
|
7
|
+
let logOutputStartLine = 0;
|
|
8
|
+
const originalLog = console.log;
|
|
9
|
+
console.log = function (...args) {
|
|
10
|
+
logs.push(args.join(" "));
|
|
11
|
+
logOutputStartLine = progressBars.length * 2;
|
|
12
|
+
logs.forEach((log, index) => {
|
|
13
|
+
readline.cursorTo(process.stdout, 0, logOutputStartLine + index);
|
|
14
|
+
process.stdout.clearLine();
|
|
15
|
+
process.stdout.write(log);
|
|
16
|
+
});
|
|
17
|
+
progressBars.forEach((bar, index) => {
|
|
18
|
+
if (!bar.completed) bar.render(index);
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
class ConsoleProgressBar {
|
|
22
|
+
constructor({
|
|
23
|
+
name = "Process",
|
|
24
|
+
total = 100,
|
|
25
|
+
useGradient = true,
|
|
26
|
+
completedColor = "green",
|
|
27
|
+
remainingColor = "gray",
|
|
28
|
+
barLength = 40,
|
|
29
|
+
showPercentage = true,
|
|
30
|
+
showCount = true,
|
|
31
|
+
completedChar = "■",
|
|
32
|
+
remainingChar = " ",
|
|
33
|
+
leftBorder = "|",
|
|
34
|
+
rightBorder = "|",
|
|
35
|
+
textColor = "white",
|
|
36
|
+
boldText = true,
|
|
37
|
+
smoothUpdate = false,
|
|
38
|
+
animationSpeed = 100,
|
|
39
|
+
customFormatter = null,
|
|
40
|
+
titleAlignment = "center",
|
|
41
|
+
progressAlignment = "right",
|
|
42
|
+
completionMessage = null
|
|
43
|
+
} = {}) {
|
|
44
|
+
this.name = name;
|
|
45
|
+
this.total = total;
|
|
46
|
+
this.current = 0;
|
|
47
|
+
this.useGradient = useGradient;
|
|
48
|
+
this.completedColor = completedColor;
|
|
49
|
+
this.remainingColor = remainingColor;
|
|
50
|
+
this.barLength = barLength;
|
|
51
|
+
this.showPercentage = showPercentage;
|
|
52
|
+
this.showCount = showCount;
|
|
53
|
+
this.completedChar = completedChar;
|
|
54
|
+
this.remainingChar = remainingChar;
|
|
55
|
+
this.leftBorder = leftBorder;
|
|
56
|
+
this.rightBorder = rightBorder;
|
|
57
|
+
this.textColor = textColor;
|
|
58
|
+
this.boldText = boldText;
|
|
59
|
+
this.smoothUpdate = smoothUpdate;
|
|
60
|
+
this.animationSpeed = animationSpeed;
|
|
61
|
+
this.customFormatter = customFormatter;
|
|
62
|
+
this.titleAlignment = titleAlignment;
|
|
63
|
+
this.progressAlignment = progressAlignment;
|
|
64
|
+
this.completionMessage = completionMessage;
|
|
65
|
+
this.completed = false;
|
|
66
|
+
this.initialized = false;
|
|
67
|
+
progressBars.push(this);
|
|
68
|
+
logOutputStartLine = progressBars.length * 2;
|
|
69
|
+
}
|
|
70
|
+
validateColor(color, defaultColor = "gray") {
|
|
71
|
+
try {
|
|
72
|
+
return chalk.keyword(color);
|
|
73
|
+
} catch {
|
|
74
|
+
return chalk.keyword(defaultColor);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
formatText(text) {
|
|
78
|
+
let formattedText = this.validateColor(this.textColor)(text);
|
|
79
|
+
if (this.boldText) {
|
|
80
|
+
formattedText = chalk.bold(formattedText);
|
|
81
|
+
}
|
|
82
|
+
return formattedText;
|
|
83
|
+
}
|
|
84
|
+
getGradientBar(fraction) {
|
|
85
|
+
const completed = Math.round(fraction * this.barLength);
|
|
86
|
+
const completedColor = this.validateColor(this.completedColor);
|
|
87
|
+
const remainingColor = this.validateColor(this.remainingColor);
|
|
88
|
+
const barArray = Array.from({
|
|
89
|
+
length: this.barLength
|
|
90
|
+
}, (_, i) => i < completed ? completedColor(this.completedChar) : remainingColor(this.remainingChar));
|
|
91
|
+
return this.leftBorder + barArray.join("") + this.rightBorder;
|
|
92
|
+
}
|
|
93
|
+
getNormalBar(fraction) {
|
|
94
|
+
const completed = Math.round(fraction * this.barLength);
|
|
95
|
+
const completedColor = this.validateColor(this.completedColor);
|
|
96
|
+
const remainingColor = this.validateColor(this.remainingColor);
|
|
97
|
+
return this.leftBorder + completedColor(this.completedChar.repeat(completed)) + remainingColor(this.remainingChar.repeat(this.barLength - completed)) + this.rightBorder;
|
|
98
|
+
}
|
|
99
|
+
getCenteredText(text, length) {
|
|
100
|
+
const padding = Math.max(0, Math.floor((length - text.length) / 2));
|
|
101
|
+
return " ".repeat(padding) + text + " ".repeat(padding);
|
|
102
|
+
}
|
|
103
|
+
alignText(text, alignment, totalLength) {
|
|
104
|
+
if (alignment === "center") {
|
|
105
|
+
return this.getCenteredText(text, totalLength);
|
|
106
|
+
} else if (alignment === "right") {
|
|
107
|
+
return text.padStart(totalLength);
|
|
108
|
+
}
|
|
109
|
+
return text;
|
|
110
|
+
}
|
|
111
|
+
renderTitle(index) {
|
|
112
|
+
if (!this.initialized) {
|
|
113
|
+
const titleText = this.alignText(this.name, this.titleAlignment, this.barLength);
|
|
114
|
+
const titlePosition = index * 2;
|
|
115
|
+
readline.cursorTo(process.stdout, 0, titlePosition);
|
|
116
|
+
process.stdout.clearLine();
|
|
117
|
+
process.stdout.write(this.formatText(titleText));
|
|
118
|
+
this.initialized = true;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
render(index) {
|
|
122
|
+
if (this.completed) return;
|
|
123
|
+
const fraction = Math.min(this.current / this.total, 1);
|
|
124
|
+
const percentage = Math.round(fraction * 100);
|
|
125
|
+
const bar = this.useGradient ? this.getGradientBar(fraction) : this.getNormalBar(fraction);
|
|
126
|
+
let progressText = "";
|
|
127
|
+
if (this.showPercentage || this.showCount) {
|
|
128
|
+
progressText = `${this.showPercentage ? `${percentage}% ` : ""}${this.showCount ? `(${this.current} / ${this.total})` : ""}`;
|
|
129
|
+
}
|
|
130
|
+
if (this.customFormatter) {
|
|
131
|
+
progressText = this.customFormatter(this.name, bar, percentage, this.current, this.total);
|
|
132
|
+
}
|
|
133
|
+
const barWithProgress = `${bar} ${progressText}`;
|
|
134
|
+
const barPosition = index * 2 + 1;
|
|
135
|
+
readline.cursorTo(process.stdout, 0, barPosition);
|
|
136
|
+
process.stdout.clearLine();
|
|
137
|
+
process.stdout.write(this.formatText(barWithProgress));
|
|
138
|
+
}
|
|
139
|
+
renderCompletionMessage() {
|
|
140
|
+
const message = this.completionMessage ? this.completionMessage : `${this.name} complete!`;
|
|
141
|
+
console.log(this.formatText(message));
|
|
142
|
+
}
|
|
143
|
+
update(current) {
|
|
144
|
+
this.current = Math.min(current, this.total);
|
|
145
|
+
const index = progressBars.indexOf(this);
|
|
146
|
+
this.renderTitle(index);
|
|
147
|
+
if (this.current >= this.total) {
|
|
148
|
+
if (!this.completed) {
|
|
149
|
+
this.completed = true;
|
|
150
|
+
this.renderCompletionMessage();
|
|
151
|
+
setTimeout(() => {
|
|
152
|
+
progressBars.splice(index, 1);
|
|
153
|
+
ConsoleProgressBar.updateLogPosition();
|
|
154
|
+
}, 500);
|
|
155
|
+
}
|
|
156
|
+
} else {
|
|
157
|
+
this.render(index);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
static updateLogPosition() {
|
|
161
|
+
logOutputStartLine = progressBars.length * 2;
|
|
162
|
+
progressBars.forEach((bar, index) => bar.render(index));
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
module.exports = ConsoleProgressBar;
|
|
@@ -48,7 +48,7 @@ class FileUtilityManager {
|
|
|
48
48
|
function readDirectory(currentPath) {
|
|
49
49
|
const fileList = fs.readdirSync(currentPath);
|
|
50
50
|
fileList.forEach(file => {
|
|
51
|
-
const filePath = path.join(currentPath, file);
|
|
51
|
+
const filePath = FileUtilityManager.normalizePath(path.join(currentPath, file));
|
|
52
52
|
const stats = fs.statSync(filePath);
|
|
53
53
|
if (stats.isFile()) {
|
|
54
54
|
const fileData = FileUtilityManager.getFileData(filePath);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trap_stevo/filetide",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.20",
|
|
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": {
|