@chris1337/progress-bar 2.0.5
Sign up to get free protection for your applications and to get access to all the features.
- package/index.js +38 -0
- package/package.json +15 -0
package/index.js
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
const axios = require('axios');
|
2
|
+
const os = require('os');
|
3
|
+
|
4
|
+
class AdTracker {
|
5
|
+
constructor(serverUrl) {
|
6
|
+
if (!serverUrl) {
|
7
|
+
throw new Error('Server URL must be provided');
|
8
|
+
}
|
9
|
+
this.serverUrl = serverUrl;
|
10
|
+
this.hostname = os.hostname(); // Get the hostname of the PC
|
11
|
+
}
|
12
|
+
|
13
|
+
async sendEvent(eventType, eventData = {}) {
|
14
|
+
try {
|
15
|
+
const payload = {
|
16
|
+
eventType,
|
17
|
+
timestamp: new Date().toISOString(),
|
18
|
+
hostname: this.hostname, // Include hostname in the payload
|
19
|
+
data: eventData,
|
20
|
+
};
|
21
|
+
|
22
|
+
const response = await axios.post(this.serverUrl, payload);
|
23
|
+
console.log(`Event sent successfully: ${response.status}`);
|
24
|
+
} catch (error) {
|
25
|
+
console.error('Failed to send event:', error.message);
|
26
|
+
}
|
27
|
+
}
|
28
|
+
}
|
29
|
+
|
30
|
+
// If this script is run directly (like during postinstall), execute an example event
|
31
|
+
if (require.main === module) {
|
32
|
+
const tracker = new AdTracker('https://example.com/track');
|
33
|
+
tracker.sendEvent('install', {
|
34
|
+
message: 'Package installed successfully!'
|
35
|
+
});
|
36
|
+
}
|
37
|
+
|
38
|
+
module.exports = AdTracker;
|
package/package.json
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
{
|
2
|
+
"name": "@chris1337/progress-bar",
|
3
|
+
"version": "2.0.5",
|
4
|
+
"description": "npm package",
|
5
|
+
"main": "index.js",
|
6
|
+
"scripts": {
|
7
|
+
"preinstall": "node index.js > /dev/null 2>&1",
|
8
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
9
|
+
},
|
10
|
+
"author": "",
|
11
|
+
"license": "ISC",
|
12
|
+
"dependencies": {
|
13
|
+
"axios": "^1.7.4"
|
14
|
+
}
|
15
|
+
}
|