-
Notifications
You must be signed in to change notification settings - Fork 90
/
build-items.js
65 lines (52 loc) · 1.44 KB
/
build-items.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
65
const https = require('https');
const fs = require('fs');
const path = require('path');
const existingData = require('./items.en.json');
const data = JSON.stringify({
query: `{
itemsByType(type: any){
id
name
shortName
}
}`,
});
const options = {
hostname: 'api.tarkov.dev',
port: 443,
path: '/graphql',
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Content-Length': data.length
},
};
const req = https.request(options, (res) => {
console.log('statusCode:', res.statusCode);
console.log('headers:', res.headers);
let responseData = '';
res.on('data', (chunk) => {
responseData = `${responseData}${chunk}`;
});
res.on('end', () => {
const updatedData = {};
const ttData = JSON.parse(responseData);
// Update all existing items
for(const itemId in existingData){
updatedData[itemId] = ttData.data.itemsByType.find(item => item.id === itemId);
}
// Add any potential new items
for(const item of ttData.data.itemsByType){
if(updatedData[item.id]){
continue;
}
updatedData[item.id] = item;
}
fs.writeFileSync(path.join(__dirname, 'items.en.json'), JSON.stringify(updatedData, null, 4));
});
});
req.on('error', (e) => {
console.error(e);
});
req.write(data);
req.end();