-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
33 lines (28 loc) · 1.2 KB
/
Copy pathindex.js
File metadata and controls
33 lines (28 loc) · 1.2 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
const BASE_URL = "https://ddragon.leagueoflegends.com/cdn";
const VERSION = "14.18.1";
function championSquare(name) { // recuperer l'image carrée d'un champion
return `${BASE_URL}/${VERSION}/img/champion/${name}.png`;
}
function championSplash(name, skin = 0) { // recuperer l'image splash d'un champion
return `${BASE_URL}/img/champion/splash/${name}_${skin}.jpg`; // skin par défaut à 0
}
async function fetchChampionData() { // Récupérer les données de tous les champions
const res = await fetch(`${BASE_URL}/${VERSION}/data/fr_FR/champion.json`);
if (!res.ok) throw new Error("Erreur lors du chargement des données");
const data = await res.json();
return Object.values(data.data);
}
// Récupérer les données détaillées d'un champion spécifique
async function getChampionData(name) {
const res = await fetch(`${BASE_URL}/${VERSION}/data/fr_FR/champion/${name}.json`);
if (!res.ok) throw new Error(`Erreur lors du chargement des données pour ${name}`);
const data = await res.json();
// La clé du champion est le nom exact (sensible à la casse donc à vérifier)
return data.data[name];
}
module.exports = {
championSquare,
championSplash,
fetchChampionData,
getChampionData
};