-
Notifications
You must be signed in to change notification settings - Fork 4
/
example.js
64 lines (54 loc) · 2.83 KB
/
example.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//////////////////////////////////////////////////////////////////////
/// This is just an example of how to use the License System API ///
//////////////////////////////////////////////////////////////////////
// Import Axios
const axios = require('axios')
// Data for checking licenses
let key = 'YOUR_LICENSE_KEY_HERE'; // Your license key goes here
let keyId = 5; // The Id given to you when a users license is created for them
licenseCheck(key, keyId);
// Data for creating a license
addLicense("704094587836301392"); // The owner Id you are registering the license to (Discord Account Id)
async function licenseCheck(key, keyId) {
// Initial Check
let checkres = await axios({
method: 'get', // Post Request
url: `https://license.hyperz.net/api/${key}`, // Your domain with your license key at the end
headers: {Accept: 'application/json, text/plain, */*','User-Agent': '*', 'productId': keyId } // The product Id given when the license key is created (keyId)
});
if(checkres.data.authorized) { // If Authorization is accepted
console.log('License Key Accepted')
} else { // If authorization is failed
console.log('License Key Failed')
process.exit(1) // Terminate the NodeJS Application
}
// Timed check to repeat ever hour
setInterval(async () => {
let checkres = await axios({
method: 'get', // Post Request
url: `https://license.hyperz.net/api/${key}`, // Your domain with your license key at the end
headers: {Accept: 'application/json, text/plain, */*','User-Agent': '*', 'productId': keyId } // The product Id given when the license key is created
});
if(checkres.data.authorized) { // If Authorization is accepted
console.log('License Key Accepted')
} else { // If authorization is failed
console.log('License Key Failed')
process.exit(1) // Terminate the NodeJS Application
}
}, 3600000); // Every 1 hour
}
async function addLicense(ownerId) {
let newLicense = await axios({
method: 'get',
url: "http://localhost:3000/addLicense",
headers: {Accept: 'application/json, text/plain, */*','User-Agent': '*', 'secret': 'somesecretlol', 'ownerid': ownerId }
});
if(!newLicense.data.error) { // If no error is found
console.log(`New license created: `, newLicense.data.licenseInfo) // Log the new license information (JSON Object)
} else { // If an error is found
console.log(`License Add Error: `, newLicense.data.reason) // Log the error
}
}
//////////////////////////////////////////////////////////////////////
/// This is just an example of how to use the License System API ///
//////////////////////////////////////////////////////////////////////