✨ Add endpoint to fetch, process, and save gamemaster data server-side
This commit is contained in:
@@ -165,6 +165,63 @@ router.get('/raw', (req, res) => {
|
|||||||
res.json(data);
|
res.json(data);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* POST /api/gamemaster/process
|
||||||
|
* Fetch and process gamemaster data on the server
|
||||||
|
* This avoids sending large payloads from the frontend
|
||||||
|
*/
|
||||||
|
router.post('/process', async (req, res) => {
|
||||||
|
try {
|
||||||
|
const POKEMINERS_URL =
|
||||||
|
'https://raw.githubusercontent.com/PokeMiners/game_masters/master/latest/latest.json';
|
||||||
|
|
||||||
|
console.log('🔄 Fetching gamemaster from PokeMiners...');
|
||||||
|
const response = await fetch(POKEMINERS_URL);
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(`Failed to fetch: ${response.statusText}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const raw = await response.json();
|
||||||
|
console.log(`✅ Fetched ${raw.length} items from PokeMiners`);
|
||||||
|
|
||||||
|
// Break up the data server-side
|
||||||
|
console.log('⚙️ Processing gamemaster data...');
|
||||||
|
const processed = breakUpGamemaster(raw);
|
||||||
|
|
||||||
|
// Save all files
|
||||||
|
console.log('💾 Saving files to disk...');
|
||||||
|
const results = {
|
||||||
|
pokemon: saveFile('pokemon.json', processed.pokemon),
|
||||||
|
pokemonAllForms: saveFile(
|
||||||
|
'pokemon-allFormsCostumes.json',
|
||||||
|
processed.pokemonAllForms
|
||||||
|
),
|
||||||
|
moves: saveFile('pokemon-moves.json', processed.moves),
|
||||||
|
raw: saveFile('latest-raw.json', raw)
|
||||||
|
};
|
||||||
|
|
||||||
|
console.log('✅ All files saved successfully');
|
||||||
|
|
||||||
|
res.json({
|
||||||
|
message: 'Gamemaster processed and saved successfully',
|
||||||
|
files: results,
|
||||||
|
stats: {
|
||||||
|
pokemon: processed.pokemon.length,
|
||||||
|
pokemonAllForms: processed.pokemonAllForms.length,
|
||||||
|
moves: processed.moves.length,
|
||||||
|
raw: raw.length
|
||||||
|
},
|
||||||
|
timestamp: new Date().toISOString()
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error processing gamemaster:', error);
|
||||||
|
res.status(500).json({
|
||||||
|
error: 'Failed to process gamemaster',
|
||||||
|
details: error.message
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* POST /api/gamemaster/save
|
* POST /api/gamemaster/save
|
||||||
* Save processed gamemaster data (called by GamemasterManager)
|
* Save processed gamemaster data (called by GamemasterManager)
|
||||||
|
|||||||
Reference in New Issue
Block a user