mirror of
https://github.com/arabine/open-story-teller.git
synced 2025-12-06 17:09:06 +01:00
44 lines
1.4 KiB
TypeScript
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(); |