Added duplicate weapon stories checks
This commit is contained in:
parent
72d642ed13
commit
c00531c7d2
|
@ -1,2 +1,3 @@
|
|||
STRAPI_BASE_API_URL=https://strapi.accords-library.com|http://localhost:1337/api
|
||||
STRAPI_GRAPHQL=https://strapi.accords-library.com/graphql|http://localhost:1337/graphql
|
||||
STRAPI_API_TOKEN=
|
|
@ -15,4 +15,10 @@ Usage:
|
|||
|
||||
```sh
|
||||
npm run import:weapon-stories
|
||||
```
|
||||
|
||||
Related checks:
|
||||
|
||||
```sh
|
||||
npm run check:weapon-stories-duplicates
|
||||
```
|
|
@ -0,0 +1,53 @@
|
|||
import "dotenv/config";
|
||||
|
||||
const response = await fetch(`${process.env.STRAPI_GRAPHQL}`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `bearer ${process.env.STRAPI_API_TOKEN}`,
|
||||
},
|
||||
body: JSON.stringify({
|
||||
query: `{
|
||||
weaponStories(pagination: { limit: -1 }) {
|
||||
data {
|
||||
id
|
||||
attributes {
|
||||
slug
|
||||
name { name }
|
||||
}
|
||||
}
|
||||
}
|
||||
}`,
|
||||
}),
|
||||
});
|
||||
|
||||
const normalizeName = (name) => {
|
||||
return name
|
||||
.toLowerCase()
|
||||
.normalize("NFD")
|
||||
.replace(/[\u0300-\u036f]/g, "")
|
||||
.replace(/['’]/g, "'");
|
||||
};
|
||||
|
||||
const weapons = (await response.json()).data.weaponStories.data;
|
||||
|
||||
const nameMap = new Map();
|
||||
|
||||
for (const weapon of weapons) {
|
||||
for (const { name } of weapon.attributes.name) {
|
||||
if (name === undefined || name === null) {
|
||||
console.warn(name, "is nullable", weapon);
|
||||
}
|
||||
|
||||
const normalizedName = normalizeName(name);
|
||||
|
||||
if (nameMap.has(normalizedName))
|
||||
console.warn(`
|
||||
Duplicate names ${normalizedName} in:
|
||||
1. ${nameMap.get(normalizedName).attributes.slug}
|
||||
2. ${weapon.attributes.slug}`);
|
||||
else {
|
||||
nameMap.set(normalizedName, weapon);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -6,6 +6,18 @@ let currentIndex = 1;
|
|||
|
||||
let weapons = [];
|
||||
|
||||
const slugSpecialCases = new Map([
|
||||
["phoenix-lance", "phoenix-spear"],
|
||||
["iron-will", "hymir-finger"],
|
||||
["the-devil-queen", "widow-death"],
|
||||
["kains-sword", "kaines-sword"],
|
||||
["spear-of-the-usurper", "robber-king"],
|
||||
["ancient-overlord", "kingsblood"],
|
||||
["fang-of-the-twins", "twins-fang"],
|
||||
["dragoon-lance", "knight-vow"],
|
||||
["faith", "nobuyoshi"],
|
||||
]);
|
||||
|
||||
try {
|
||||
console.log('Fetching NieR Re[in]carnation weapons...')
|
||||
weapons = await fetch(`${NIERREIN_GUIDE_API_URL}/weapons`)
|
||||
|
@ -30,6 +42,11 @@ for (const weapon of weapons) {
|
|||
(response) => response.blob()
|
||||
);
|
||||
|
||||
// Change slug if the weapon is known with a different name in accords-library
|
||||
if (slugSpecialCases.has(weapon.slug)) {
|
||||
weapon.slug = slugSpecialCases.get(weapon.slug);
|
||||
}
|
||||
|
||||
const body = new FormData();
|
||||
|
||||
// Create the weapon-stories entry
|
||||
|
|
|
@ -11,6 +11,9 @@
|
|||
"dependencies": {
|
||||
"dotenv": "^16.0.3",
|
||||
"envsafe": "^2.0.3"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=18.13.0"
|
||||
}
|
||||
},
|
||||
"node_modules/dotenv": {
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
"description": "",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"check:weapon-stories-duplicates": "node ./nier-reincarnation/weapon-stories/find-duplicates.mjs",
|
||||
"import:weapon-stories": "node ./nier-reincarnation/weapon-stories/index.mjs"
|
||||
},
|
||||
"dependencies": {
|
||||
|
|
Loading…
Reference in New Issue