open-story-teller/story-editor/tools/get_official_db.ts
anthony@rabine.fr fe920f4b15
Some checks failed
build-story-editor / build_linux (push) Has been cancelled
build-story-editor / build_win32 (push) Has been cancelled
Deploy / deploy (push) Has been cancelled
(WIP) new Download manager, download of commercial DB
2025-01-03 13:21:47 +01:00

44 lines
1.4 KiB
TypeScript

// A lancer avec Bun !
async function getCommercialStoreDb() {
console.log("Fetching db from commercial store");
try {
// Première requête pour obtenir le token
const authResponse = await fetch('https://server-auth-prod.lunii.com/guest/create');
if (!authResponse.ok) {
throw new Error(`Failed to fetch auth token: ${authResponse.statusText}`);
}
const authData = await authResponse.json();
const token = authData?.response?.token?.server;
if (!token) {
throw new Error('Token not found in response');
}
// Deuxième requête pour récupérer les données
const dataResponse = await fetch('https://server-data-prod.lunii.com/v2/packs', {
headers: {
'X-AUTH-TOKEN': token,
},
});
if (!dataResponse.ok) {
throw new Error(`Failed to fetch packs: ${dataResponse.statusText}`);
}
const jsonData = await dataResponse.json(); // Récupérer les données en JSON
// Enregistrer les données dans un fichier local
const filePath = "./commercial_store_db.json";
await Bun.write(filePath, JSON.stringify(jsonData, null, 2));
console.log(`Data saved to ${filePath}`);
return jsonData;
} catch (error) {
console.error(error);
throw error;
}
}
await getCommercialStoreDb();