mirror of
https://github.com/Pax1601/DCSOlympus.git
synced 2025-10-29 16:56:34 +00:00
Moved airfields database to public/database folder
This commit is contained in:
@@ -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;
|
||||
Reference in New Issue
Block a user