Added Geo game.
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
'use strict';
|
||||
|
||||
const fs = require('fs').promises;
|
||||
const bhttp = require('bhttp');
|
||||
|
||||
async function init() {
|
||||
const countryImgs = await fs.readdir('./assets/countries');
|
||||
const res = await bhttp.get('http://localhost:3000/api/countries');
|
||||
|
||||
const countries = res.body;
|
||||
const countriesByCode = Object.fromEntries(countries.map((country) => [country.alpha2, country]));
|
||||
|
||||
const imgCountries = await Promise.all(countryImgs.filter((file) => file !== 'encoded').map(async (file) => {
|
||||
const code = file.match(/(\w+).png/)[1];
|
||||
const filename = `${Buffer.from(code).toString('base64')}.png`;
|
||||
|
||||
await fs.copyFile(`./assets/countries/${file}`, `./assets/countries/encoded/${filename}`);
|
||||
|
||||
return {
|
||||
file: filename,
|
||||
code,
|
||||
...countriesByCode[code],
|
||||
};
|
||||
}));
|
||||
|
||||
await fs.writeFile('./assets/countries.json', JSON.stringify(imgCountries, null, 4));
|
||||
|
||||
console.log('Done!');
|
||||
}
|
||||
|
||||
init();
|
||||
Reference in New Issue
Block a user