@trap_stevo/filetide 0.0.19 → 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
|
package/dist/cjs/FileTide.js
CHANGED
|
@@ -244,7 +244,7 @@ function _setupFileEventListeners(userID, client, onIncomingFile) {
|
|
|
244
244
|
totalChunks: data.totalChunks,
|
|
245
245
|
fileInfo: data
|
|
246
246
|
});
|
|
247
|
-
const saveDir = data.path;
|
|
247
|
+
const saveDir = path.resolve(data.path);
|
|
248
248
|
if (!fs.existsSync(saveDir)) {
|
|
249
249
|
fs.mkdirSync(saveDir, {
|
|
250
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;
|
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": {
|