Skip to content

Commit c77566f

Browse files
committed
Update 1.5.3 - Removed force refresh feature and improve rate limit handling
- Remove forceRefreshCivilizations function and related UI button as the feature is no longer needed - Update rate limit handling in update-default-data.js to dynamically adjust based on API response - Increase page size limit from 250 to 500 items per request
1 parent 5c05703 commit c77566f

File tree

3 files changed

+30
-75
lines changed

3 files changed

+30
-75
lines changed

.github/scripts/update-default-data.js

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const __filename = fileURLToPath(import.meta.url);
66
const __dirname = path.dirname(__filename);
77

88
const apiPath = 'https://nomanssky.fandom.com/api.php';
9-
const MIN_REQUEST_INTERVAL = 35000; // 35 seconds between fetchs
9+
let MIN_REQUEST_INTERVAL = 35000; // default, it will be changed if the rate limit is modified
1010

1111
const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));
1212

@@ -20,6 +20,29 @@ const filterValidData = (data) => {
2020
);
2121
};
2222

23+
const getRateLimit = async () => {
24+
const url = `${apiPath}?action=query&meta=userinfo&uiprop=ratelimits&format=json&origin=*`;
25+
const res = await fetch(url);
26+
if (!res.ok) throw new Error(`HTTP error getting rate limit: ${res.status}`);
27+
const data = await res.json();
28+
29+
const cargoLimits = data?.query?.userinfo?.ratelimits?.["cargo-query"];
30+
if (!cargoLimits) return MIN_REQUEST_INTERVAL;
31+
32+
let maxInterval = 0;
33+
for (const key in cargoLimits) {
34+
const limit = cargoLimits[key]; // { hits, seconds }
35+
if (limit.hits && limit.seconds) {
36+
const interval = limit.seconds / limit.hits;
37+
if (interval > maxInterval) maxInterval = interval;
38+
}
39+
}
40+
41+
const intervalMs = Math.ceil(maxInterval * 1000) + 5000;
42+
console.log(`Cargo-query rate limits: ${JSON.stringify(cargoLimits)}, using interval ${intervalMs}ms`);
43+
return intervalMs;
44+
};
45+
2346
const fetchCivilizationsPage = async (offset = 0) => {
2447
const params = new URLSearchParams();
2548
params.append('action', 'cargoquery');
@@ -38,10 +61,7 @@ const fetchCivilizationsPage = async (offset = 0) => {
3861
console.log(`Fetching page with offset: ${offset}`);
3962

4063
const response = await fetch(url);
41-
if (!response.ok) {
42-
throw new Error(`HTTP error! status: ${response.status}`);
43-
}
44-
64+
if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
4565
const data = await response.json();
4666
return data.cargoquery || [];
4767
};
@@ -69,16 +89,13 @@ const fetchAllCivilizationsAndRegions = async () => {
6989

7090
console.log(`Total valid items so far: ${allData.length}`);
7191

72-
if (pageData.length < 250) {
92+
if (pageData.length < 500) {
7393
hasMore = false;
7494
console.log('Last page reached');
7595
} else {
7696
offset += 500;
77-
78-
if (hasMore) {
79-
console.log(`Waiting ${MIN_REQUEST_INTERVAL}ms before next request...`);
80-
await sleep(MIN_REQUEST_INTERVAL);
81-
}
97+
console.log(`Waiting ${MIN_REQUEST_INTERVAL}ms before next request...`);
98+
await sleep(MIN_REQUEST_INTERVAL);
8299
}
83100
}
84101
} catch (error) {
@@ -129,6 +146,8 @@ const fetchAllCivilizationsAndRegions = async () => {
129146
const main = async () => {
130147
try {
131148
console.log('=== Starting defaultData.json update ===');
149+
150+
MIN_REQUEST_INTERVAL = await getRateLimit();
132151

133152
const result = await fetchAllCivilizationsAndRegions();
134153

JS/glyphgeneratorV3.js

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -519,68 +519,6 @@ const showNotification = (message, type) => {
519519
}, 3000);
520520
};
521521

522-
function mergeCivilizationData(oldData, newData) {
523-
const merged = JSON.parse(JSON.stringify(oldData));
524-
525-
for (const galaxy of newData.galaxies) {
526-
if (!merged.galaxies.includes(galaxy)) {
527-
merged.galaxies.push(galaxy);
528-
}
529-
}
530-
531-
for (const [galaxyName, galaxyInfo] of Object.entries(newData.data)) {
532-
if (!merged.data[galaxyName]) {
533-
merged.data[galaxyName] = galaxyInfo;
534-
continue;
535-
}
536-
537-
const oldGalaxy = merged.data[galaxyName];
538-
539-
for (const civ of galaxyInfo.civilizations) {
540-
if (!oldGalaxy.civilizations.includes(civ)) {
541-
oldGalaxy.civilizations.push(civ);
542-
}
543-
}
544-
545-
for (const civ of galaxyInfo.civilizations) {
546-
if (!oldGalaxy.regions[civ]) {
547-
oldGalaxy.regions[civ] = galaxyInfo.regions[civ];
548-
continue;
549-
}
550-
551-
const oldRegions = oldGalaxy.regions[civ];
552-
const newRegions = galaxyInfo.regions[civ];
553-
554-
for (const r of newRegions) {
555-
if (!oldRegions.some(or => or.name === r.name)) {
556-
oldRegions.push(r);
557-
}
558-
}
559-
}
560-
}
561-
562-
return merged;
563-
}
564-
565-
const forceRefreshCivilizations = async () => {
566-
console.log("🔄 Forzando actualización y merge de datos…");
567-
showNotification(i18next.t("updatingInfo"), "info");
568-
569-
const defaultData = await loadDefaultData();
570-
571-
const freshData = await fetchAllCivilizationsAndRegions(true);
572-
const merged = mergeCivilizationData(defaultData, freshData);
573-
574-
setCachedData(CIVILIZATIONS_CACHE_KEY, merged);
575-
576-
console.log("✅ Merge completado. JSON actualizado sin borrar datos.");
577-
showNotification(i18next.t("updatingFinish"), "success");
578-
579-
return merged;
580-
};
581-
582-
window.forceRefreshCivilizations = forceRefreshCivilizations;
583-
584522
const populateGalaxySelect = async () => {
585523
const select = document.getElementById("galaxySelect");
586524
const loadingOption = document.createElement("option");

index.html

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,6 @@ <h1 data-i18n="header">Generador de Glifos NMS</h1>
7474
<button id="generateButton" class="primary" onclick="displayRandomGlyphs()" data-i18n="button">Generar
7575
Glifos</button>
7676
<button id="copyButton" onclick="copyToClipboard()" disabled data-i18n="copyButton">Copiar Código</button>
77-
<button id="refreshCivilizationsButton" onclick="forceRefreshCivilizations()"
78-
data-i18n="refreshCivilizations">Actualizar Regiones</button>
7977
</div>
8078

8179
<div class="glyph-output" id="glyphOutputContainer">

0 commit comments

Comments
 (0)