Repository navigation
Expand file tree
/
Copy pathworker.js
More file actions
55 lines (48 loc) · 2.35 KB
/
Copy pathworker.js
File metadata and controls
55 lines (48 loc) · 2.35 KB
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
import { fetch } from 'undici'
import * as fs from 'node:fs/promises';
import aliasList from './alias.js';
const langList = ['en', 'fr', 'es', 'es-mx', 'de', 'it', 'ja', 'pt-br', 'ru', 'pl', 'ko', 'zh-cht', 'zh-chs'];
const itemFilter = [1, 20, 59]; // [weapon, armor, mods]
const itemDefineList = {};
const manifestResp = await fetch('https://www.bungie.net/Platform/Destiny2/Manifest/');
const manifest = await manifestResp.json();
for (const lang of langList) {
const itemDefinePath = manifest.Response.jsonWorldComponentContentPaths[lang].DestinyInventoryItemLiteDefinition;
console.log(itemDefinePath);
const itemDefineResp = await fetch('https://www.bungie.net' + itemDefinePath);
const itemDefine = await itemDefineResp.json();
itemDefineList[lang] = itemDefine;
console.log(lang + ' done');
}
const combinedItemList = {};
for(const key in itemDefineList[langList[0]]) {
const item = itemDefineList[langList[0]][key];
// filter items, only keep weapon, armor and mods, remove uncollectible items
if(item.itemCategoryHashes && item.itemCategoryHashes.some(hash => itemFilter.includes(hash)) && (!item.equippable || item.collectibleHash)) {
// only keep items have name
if(item.displayProperties.name && item.displayProperties.name.trim()) {
const combinedItemName = {};
for (const lang of langList) {
combinedItemName[lang] = itemDefineList[lang][key].displayProperties.name;
}
if(item.displayProperties.icon) {
const iconHash = item.displayProperties.icon.match(/\/common\/destiny2_content\/icons\/(.*)/);
combinedItemName.icon = (iconHash && iconHash[1]) ? iconHash[1] : "";
}
itemFilter.some(type => {
if(item.itemCategoryHashes.includes(type)) {
combinedItemName.type = type;
return true;
}
});
combinedItemList[key] = combinedItemName;
}
}
}
for(const key in aliasList) {
combinedItemList[key].alias = aliasList[key];
}
await fs.rm('dist', { recursive: true, force: true });
await fs.mkdir('dist', { recursive: true });
await fs.writeFile('dist/item-list.json', JSON.stringify(combinedItemList));
console.log('combine done! filtered and combined ' + Object.keys(combinedItemList).length + ' items!');