Updated createIlvlFilter to include xivApiKey
This commit is contained in:
parent
2023697686
commit
e304b70e08
3 changed files with 37 additions and 36 deletions
|
@ -1,14 +1,8 @@
|
|||
const fetch = require("node-fetch");
|
||||
const path = require("path");
|
||||
const { createCanvas, loadImage, registerFont } = require("canvas");
|
||||
const createilvlfilter = require('./createilvlfilter')
|
||||
|
||||
let ilvlarray;
|
||||
console.log('Generating ilvl filter')
|
||||
createilvlfilter().then((ilvlfilter) => {
|
||||
ilvlarray = ilvlfilter;
|
||||
console.log("ilvl filter generated!")
|
||||
})
|
||||
const createIlvlFilter = require('./create-ilvl-filter');
|
||||
|
||||
function absolute(relativePath) {
|
||||
return path.join(__dirname, relativePath);
|
||||
|
@ -192,6 +186,8 @@ class CardCreator {
|
|||
this.imgJobBg[i] = await loadImage(absolute(`./resources/class-jobs-backgrounds/${i}.png`));
|
||||
}
|
||||
|
||||
this.ilvlFilterIds = await createIlvlFilter(this.xivApiKey);
|
||||
|
||||
await this.countMountsMinions();
|
||||
}
|
||||
|
||||
|
@ -251,7 +247,6 @@ class CardCreator {
|
|||
var mainHandLvl = 0;
|
||||
var hasOffHand = false;
|
||||
|
||||
console.log(ilvlarray)
|
||||
for (var key in gearset) {
|
||||
var piece = gearset[key];
|
||||
|
||||
|
@ -264,7 +259,7 @@ class CardCreator {
|
|||
if (key == 'OffHand')
|
||||
hasOffHand = true;
|
||||
|
||||
if(ilvlarray.includes(piece.Item.ID) == true) {
|
||||
if (this.ilvlFilterIds.includes(piece.Item.ID) == true) {
|
||||
ilvl += 1;
|
||||
} else {
|
||||
ilvl += piece.Item.LevelItem;
|
||||
|
|
33
create-ilvl-filter.js
Normal file
33
create-ilvl-filter.js
Normal file
|
@ -0,0 +1,33 @@
|
|||
const fetch = require('node-fetch');
|
||||
|
||||
const itemUICategory = [
|
||||
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, 84, 87, 88, 89, 96, 97, 98, 99, 105, 106, 107,
|
||||
];
|
||||
|
||||
// Returns a list of item IDs that, when equipped, increase the iLvl by 1
|
||||
async function createIlvlFilter(xivApiKey = undefined) {
|
||||
const itemIds = [];
|
||||
|
||||
// Fetch for each category one after another to prevent rate limiting
|
||||
// This should only by needed on startup, so a longer caching time is ok
|
||||
for (const category of itemUICategory) {
|
||||
const url = new URL('https://xivapi.com/search');
|
||||
url.searchParams.set('indexes', 'item');
|
||||
url.searchParams.set('filters', `IsIndisposable=1,ItemUICategoryTargetID=${category}`);
|
||||
if (typeof xivApiKey === 'string' && xivApiKey !== '') url.searchParams.set('private_key', xivApiKey);
|
||||
|
||||
const response = await fetch(url.toString());
|
||||
const data = await response.json();
|
||||
|
||||
if (data != null && Array.isArray(data.Results)) {
|
||||
for (const item of data.Results) {
|
||||
itemIds.push(item.ID);
|
||||
}
|
||||
}
|
||||
}
|
||||
return itemIds;
|
||||
}
|
||||
|
||||
module.exports = createIlvlFilter
|
|
@ -1,27 +0,0 @@
|
|||
const fetch = require("node-fetch");
|
||||
|
||||
const itemUICategory = [
|
||||
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, 84, 87, 88, 89, 96, 97, 98, 99,
|
||||
105, 106, 107,
|
||||
];
|
||||
|
||||
async function createilvlfilter() {
|
||||
let results = [];
|
||||
for (const category of itemUICategory) {
|
||||
let url = `https://xivapi.com/search?indexes=item&filters=IsIndisposable=1,ItemUICategoryTargetID=${category}`;
|
||||
const response = await fetch(url);
|
||||
const data = response.json();
|
||||
data.then((payload) => {
|
||||
if (payload.Pagination.Results === 0) {
|
||||
return;
|
||||
}
|
||||
for (const item of payload.Results) {
|
||||
let part = item.ID
|
||||
results.push(part);
|
||||
}
|
||||
});
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
module.exports = createilvlfilter
|
Loading…
Reference in a new issue