Skip to content

Commit

Permalink
Fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
wavded committed Jan 26, 2021
1 parent aeda0ff commit b22bf0b
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const ogr2ogr = require('ogr2ogr')
const fs = require('fs')
const urlencoded = require('body-parser').urlencoded
const join = require('path').join
const tmpdir = require('os').tmpdir;
const tmpdir = require('os').tmpdir

function enableCors(req, res, next) {
res.header('Access-Control-Allow-Origin', '*')
Expand Down Expand Up @@ -144,50 +144,44 @@ exports.createServer = function (opts) {
ogr.format(format)

const sendResponse = (buf) => {

res.header('Content-Type', 'application/zip')
res.header(
'Content-Disposition',
'filename=' + (req.body.outputName || 'ogre.zip')
)
res.end(buf)

}

try {

switch (format) {
// These formats must use .destination
case 'dxf':
case 'dgn':
case 'txt':
case 'gxt':
case 'gmt':

case 'gmt': {
// Random string to prevent multiple request being overwritten
let randomId = Math.random().toString(36).substring(7);
let randomId = Math.random().toString(36).substring(7)

let tmpDestination = join(tmpdir(), `/ogre-${randomId}.${format}`)
await ogr.destination(tmpDestination).promise()

let bufD = await fs.promises.readFile(tmpDestination, 'utf8')
await fs.promises.unlink(tmpDestination)

sendResponse(bufD)

break;

default:
break
}
default: {
let buf = await ogr.promise()
sendResponse(buf)
break;
break
}
}

} catch (er) {
if (isOgreFailureError(er))
return res
.status(400)
.json({ errors: er.message.replace('\n\n', '').split('\n') })
.json({errors: er.message.replace('\n\n', '').split('\n')})
if (er) return next(er)
}
})
Expand Down

0 comments on commit b22bf0b

Please sign in to comment.