Skip to content

Commit

Permalink
Add POST route for extract new format BAN from multi cog
Browse files Browse the repository at this point in the history
  • Loading branch information
nkokla committed Jun 20, 2024
1 parent 1ac1b16 commit d80ed35
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions lib/api/extract/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ import {streamBanDataFromCog, testIsEnabledCog} from './models.js'

const app = new express.Router()

app.get('/cog/:cog?', async (req, res) => {
const banFormatMiddleware = async (req, res, next) => {
let response
try {
const {cog} = req.params
const cogList = cog && [cog]
const fileName = cog ? `ban_${cog}.json` : 'ban_france.json'
const {cogList} = req.params
const fileName = cogList ? `ban_${cogList.join('_')}.json` : 'ban_france.json'

const checkCog = (
await Promise.all(
Expand Down Expand Up @@ -50,6 +49,26 @@ app.get('/cog/:cog?', async (req, res) => {
}

res.send(response)
})

next()
}

app.get(
'/cog/:cog?',
(req, res, next) => {
const {cog} = req.params
req.params.cogList = cog ? [cog] : null
next()
},
banFormatMiddleware
)
app.post(
'/cog',
(req, res, next) => {
req.params.cogList = req.body.cogList.map(cog => cog.toString().padStart(5, '0'))
next()
},
banFormatMiddleware
)

export default app

0 comments on commit d80ed35

Please sign in to comment.