@trap_stevo/filetide 0.0.81 → 0.0.83

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.
@@ -30,9 +30,6 @@ const {
30
30
  FileTransferReceiverManager
31
31
  } = require("./HUDManagers/FileTransferReceiverManager.js");
32
32
  const TideTokenEnforcer = require("./HUDManagers/TideTokenEnforcementManager.js");
33
- const {
34
- FileNetConfigManager
35
- } = require("./HUDManagers/FileNetConfigManager.js");
36
33
  const {
37
34
  FileUtilityManager
38
35
  } = require("./HUDManagers/FileUtilityManager.js");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trap_stevo/filetide",
3
- "version": "0.0.81",
3
+ "version": "0.0.83",
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": {
@@ -1,8 +0,0 @@
1
- "use strict";
2
-
3
- const LogicTide = require("@trap_stevo/logictide");
4
-
5
- // ~ Universal FileTide Environment Mode ~
6
-
7
- const productionMode = true;
8
- LogicTide.setMode(productionMode ? "production" : "development");
@@ -1,165 +0,0 @@
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;
@@ -1,32 +0,0 @@
1
- "use strict";
2
-
3
- const currentOnlineClients = new Map();
4
- class FileNetConfigManager {
5
- static addOnlineClient(clientID, pClientID, tideID) {
6
- if (currentOnlineClients.get(pClientID)) {
7
- currentOnlineClients.delete(pClientID);
8
- }
9
- currentOnlineClients.set(clientID, {
10
- pClientID: pClientID || "",
11
- clientID,
12
- tideID
13
- });
14
- return currentOnlineClients;
15
- }
16
- static clearOnlineClient(clientID, tideID) {
17
- if (!currentOnlineClients.get(clientID)) {
18
- return currentOnlineClients;
19
- }
20
- currentOnlineClients.delete(clientID);
21
- return currentOnlineClients;
22
- }
23
- static getOnlineClient(clientID) {
24
- if (!currentOnlineClients.get(clientID)) {
25
- return null;
26
- }
27
- return currentOnlineClients.get(clientID);
28
- }
29
- }
30
- module.exports = {
31
- FileNetConfigManager
32
- };
@@ -1,93 +0,0 @@
1
- "use strict";
2
-
3
- const path = require("path");
4
- const fs = require("fs");
5
- class FileTransferRecoveryManager {
6
- constructor(storagePath = `${process.cwd()}/transfer_states`) {
7
- if (FileTransferRecoveryManager.instance) {
8
- return FileTransferRecoveryManager.instance;
9
- }
10
- this.storagePath = storagePath;
11
- this.memoryStorage = new Map();
12
- this.ensureStorageDirectory();
13
- FileTransferRecoveryManager.instance = this;
14
- }
15
- ensureStorageDirectory() {
16
- if (!fs.existsSync(this.storagePath)) {
17
- fs.mkdirSync(this.storagePath, {
18
- recursive: true
19
- });
20
- }
21
- }
22
- sanitizeFileName(fileName) {
23
- return fileName.replace(/[^a-zA-Z0-9-_\.]/g, "-").replace(/-+/g, "-").trim();
24
- }
25
- generateKey(clientName, senderName, filePath) {
26
- const normalizedPath = this.sanitizeFileName(filePath);
27
- return `${clientName}_${senderName}_${normalizedPath}.json`;
28
- }
29
- getStorageFilePath(clientName, senderName, filePath) {
30
- return path.join(this.storagePath, this.generateKey(clientName, senderName, filePath));
31
- }
32
- saveTransferState(clientName, senderName, filePath, chunkIndex, transferredSize) {
33
- const key = this.generateKey(clientName, senderName, filePath);
34
- const transferState = {
35
- transferredSize,
36
- senderName,
37
- clientName,
38
- filePath,
39
- lastChunkSent: chunkIndex
40
- };
41
- this.memoryStorage.set(key, transferState);
42
- }
43
- saveToDisk(clientName, senderName, filePath) {
44
- const key = this.generateKey(clientName, senderName, filePath);
45
- const storageFile = this.getStorageFilePath(clientName, senderName, filePath);
46
- const transferState = this.memoryStorage.get(key);
47
- if (transferState) {
48
- try {
49
- fs.writeFileSync(storageFile, JSON.stringify(transferState, null, 2));
50
- console.log(`Saved transfer state to disk ~ ${storageFile}`);
51
- } catch (error) {
52
- console.error(`Error saving transfer state for ${key} ~ ${error.message}`);
53
- }
54
- }
55
- }
56
- getTransferState(clientName, senderName, filePath) {
57
- const key = this.generateKey(clientName, senderName, filePath);
58
- if (this.memoryStorage.has(key)) {
59
- return this.memoryStorage.get(key);
60
- }
61
- const storageFile = this.getStorageFilePath(clientName, senderName, filePath);
62
- if (fs.existsSync(storageFile)) {
63
- const transferState = JSON.parse(fs.readFileSync(storageFile, "utf-8"));
64
- return transferState;
65
- }
66
- return null;
67
- }
68
- getLastChunk(clientName, senderName, filePath) {
69
- const transferState = this.getTransferState(clientName, senderName, filePath);
70
- return transferState ? transferState.lastChunkSent : null;
71
- }
72
- clearTransferState(clientName, senderName, filePath) {
73
- const key = this.generateKey(clientName, senderName, filePath);
74
- this.memoryStorage.delete(key);
75
- const storageFile = this.getStorageFilePath(clientName, senderName, filePath);
76
- if (fs.existsSync(storageFile)) {
77
- fs.unlinkSync(storageFile);
78
- }
79
- }
80
- flushToDisk() {
81
- for (const [key, state] of this.memoryStorage.entries()) {
82
- const {
83
- clientName,
84
- senderName,
85
- filePath
86
- } = state;
87
- console.log("Saving current state ~ ", key);
88
- this.saveToDisk(clientName, senderName, filePath);
89
- }
90
- ;
91
- }
92
- }
93
- module.exports = new FileTransferRecoveryManager();