Moved airfields database to public/database folder

This commit is contained in:
Pax1601
2023-08-15 12:26:05 +02:00
parent 3055378b86
commit e96cb2716d
24 changed files with 2462 additions and 2509 deletions

View File

@@ -15,68 +15,46 @@ const allowedTheatres = [
"syria"
];
function getAirbasesData( theatreName ) {
if ( !isValidTheatre( theatreName ) ) {
return false;
}
return JSON.parse( fs.readFileSync( `src/airfields/${theatreName}.json` ) ).airfields
return JSON.parse( fs.readFileSync( `public/databases/airbases/${theatreName}.json` ) ).airfields
}
function isValidTheatre( theatre ) {
return ( allowedTheatres.indexOf( theatre ) > -1 )
}
function sendInvalidTheatre( res ) {
res.status( 400 ).send( "Missing/invalid theatre name; must be one of:\n\t" + allowedTheatres.join( "\n\t" ) );
}
/**************************************************************************************************************/
// Endpoints
/**************************************************************************************************************/
app.get( "/", ( req, res ) => {
sendInvalidTheatre( res );
});
app.get( "/:theatreName/:airbaseName", ( req, res ) => {
const airbases = getAirbasesData( req.params.theatreName );
if ( !airbases ) {
sendInvalidTheatre( res );
return;
}
const airbaseName = req.params.airbaseName;
if ( !airbases.hasOwnProperty( airbaseName ) ) {
res.status( 404 ).send( `Unknown airbase name "${airbaseName}". Available options are:\n\t` + Object.keys( airbases ).join( "\n\t" ) );
} else {
res.status( 200 ).json( airbases[ airbaseName ] );
}
});
app.get( "/:theatreName", ( req, res ) => {
const theatreName = req.params.theatreName.toLowerCase().replace( /\s*/g, "" );
const airbases = getAirbasesData( theatreName );
@@ -86,9 +64,6 @@ app.get( "/:theatreName", ( req, res ) => {
}
res.status( 200 ).json( airbases );
});
module.exports = app;