Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix broken windows #102

Merged
merged 2 commits into from
Jan 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions .github/release-drafter.yml
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
name-template: 'v$RESOLVED_VERSION'
tag-template: 'v$RESOLVED_VERSION'
name-template: "v$RESOLVED_VERSION"
tag-template: "v$RESOLVED_VERSION"
template: |
$CHANGES
category-template: '#### $TITLE'
change-template: '* #$NUMBER - $TITLE (@$AUTHOR)'
category-template: "#### $TITLE"
change-template: "* #$NUMBER - $TITLE (@$AUTHOR)"
categories:
- title: 'Breaking changes'
label: 'breaking'
- title: 'Enhancements'
label: 'enhancement'
- title: 'Bug fixes'
label: 'bug'
- title: 'Maintenance'
label: 'chore'
- title: "Breaking changes"
label: "breaking"
- title: "Enhancements"
label: "enhancement"
- title: "Bug fixes"
label: "bug"
- title: "Maintenance"
label: "chore"

version-resolver:
major:
labels:
- 'breaking'
- "breaking"
minor:
labels:
- 'enhancement'
- "enhancement"
patch:
labels:
- 'bug'
- 'chore'
- "bug"
- "chore"

exclude-labels:
- 'skip-changelog'
- "skip-changelog"
3 changes: 2 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ jobs:
runs-on: ubuntu-latest
container:
image: osgeo/gdal:ubuntu-small-latest
options: --user 1001
strategy:
matrix:
node: ['12', '14']
node: ["12", "14", "16"]
name: Node v${{ matrix.node }}
steps:
- uses: actions/checkout@v2
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/stale.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ name: stale-issues-prs
on:
workflow_dispatch:
schedule:
- cron: '0 0 * * *'
- cron: "0 0 * * *"

jobs:
stale:
runs-on: ubuntu-latest
steps:
- uses: actions/stale@v3
with:
stale-issue-message: 'This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.'
stale-pr-message: 'This PR is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.'
close-issue-message: 'This issue was closed because it has been stalled for 5 days with no activity.'
stale-issue-message: "This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days."
stale-pr-message: "This PR is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days."
close-issue-message: "This issue was closed because it has been stalled for 5 days with no activity."
days-before-stale: 30
days-before-close: 5
stale-issue-label: stale
1 change: 0 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"semi": false,
"singleQuote": true,
"bracketSpacing": false
}
46 changes: 23 additions & 23 deletions cli.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
#!/usr/bin/env node
import Ogre from './'
import {version} from './package.json'
import Ogre from "./"
import {version} from "./package.json"

let args = process.argv.slice(2)

let usage =
'' +
'\n\x1b[1mUsage\x1b[0m: ogre [options]\n' +
'\n' +
'\x1b[1mOptions:\x1b[0m\n' +
' -h, --help help\n' +
' -p, --port port number (default 3000)\n' +
' -v, --version version number\n' +
' -t, --timeout timeout before ogre kills a job in ms (default 15000)\n' +
' -l, --limit byte limit for uploads (default 50000000)\n'
"" +
"\n\x1b[1mUsage\x1b[0m: ogre [options]\n" +
"\n" +
"\x1b[1mOptions:\x1b[0m\n" +
" -h, --help help\n" +
" -p, --port port number (default 3000)\n" +
" -v, --version version number\n" +
" -t, --timeout timeout before ogre kills a job in ms (default 15000)\n" +
" -l, --limit byte limit for uploads (default 50000000)\n"

let port = 3000
let timeout = 15000
Expand All @@ -23,30 +23,30 @@ let arg
while (args.length) {
arg = args.shift()
switch (arg) {
case '-h':
case '--help':
case "-h":
case "--help":
console.log(usage)
process.exit(0)
break

case '-v':
case '--version':
console.log('ogre ' + version)
case "-v":
case "--version":
console.log("ogre " + version)
process.exit(0)
break

case '-p':
case '--port':
case "-p":
case "--port":
port = Number(args.shift())
break

case '-t':
case '--timeout':
case "-t":
case "--timeout":
timeout = Number(args.shift())
break

case '-l':
case '--limit':
case "-l":
case "--limit":
limit = Number(args.shift())
break

Expand All @@ -56,4 +56,4 @@ while (args.length) {

let ogre = new Ogre({port, timeout, limit})
ogre.start()
console.log('Ogre (%s) ready. Port %d', version, port)
console.log("Ogre (%s) ready. Port %d", version, port)
70 changes: 35 additions & 35 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import {urlencoded} from 'body-parser'
import cors from 'cors'
import {randomBytes} from 'crypto'
import {urlencoded} from "body-parser"
import cors from "cors"
import {randomBytes} from "crypto"
import express, {
Application,
ErrorRequestHandler,
RequestHandler,
Router,
} from 'express'
import PromiseRouter from 'express-promise-router'
import {unlink} from 'fs'
import multer, {diskStorage} from 'multer'
import ogr2ogr from 'ogr2ogr'
import {join} from 'path'
} from "express"
import PromiseRouter from "express-promise-router"
import {unlink} from "fs"
import multer, {diskStorage} from "multer"
import ogr2ogr from "ogr2ogr"
import {join} from "path"

export interface OgreOpts {
port?: number
Expand All @@ -35,7 +35,7 @@ class Ogre {
this.limit = limit

this.app = express()
this.app.use(express.static(join(__dirname, '/public')))
this.app.use(express.static(join(__dirname, "/public")))
this.app.use(this.router())
}

Expand All @@ -45,18 +45,18 @@ class Ogre {
storage: diskStorage({
filename(req, file, cb) {
randomBytes(16, (err, raw) =>
cb(err, raw.toString('hex') + file.originalname)
cb(err, raw.toString("hex") + file.originalname)
)
},
}),
limits: {fileSize: this.limit},
})
let encoded = urlencoded({extended: false, limit: this.limit})

router.options('/', this.heartbeat())
router.options("/", this.heartbeat())
router.use(cors())
router.post('/convert', upload.single('upload'), this.convert())
router.post('/convertJson', encoded, this.convertJson())
router.post("/convert", upload.single("upload"), this.convert())
router.post("/convertJson", encoded, this.convertJson())
router.use(this.notFound())
router.use(this.serverError())

Expand All @@ -70,16 +70,16 @@ class Ogre {
server.close(() => process.exit())
setTimeout(process.exit, 30 * 1000)
}
process.on('SIGINT', handler)
process.on('SIGTERM', handler)
process.on("SIGINT", handler)
process.on("SIGTERM", handler)
}

private heartbeat = (): RequestHandler => (_req, res) => {
res.sendStatus(200)
}

private notFound = (): RequestHandler => (_req, res) => {
res.status(404).send({error: 'Not found'})
res.status(404).send({error: "Not found"})
}

private serverError = (): ErrorRequestHandler => (er, _req, res, _next) => {
Expand All @@ -89,7 +89,7 @@ class Ogre {

private convert = (): RequestHandler => async (req, res) => {
if (!req.file) {
res.status(400).json({error: true, msg: 'No file provided'})
res.status(400).json({error: true, msg: "No file provided"})
return
}

Expand All @@ -99,35 +99,35 @@ class Ogre {
options: [] as string[],
}

if (b.targetSrs) opts.options.push('-t_srs', b.targetSrs)
if (b.sourceSrs) opts.options.push('-s_srs', b.sourceSrs)
if ('rfc7946' in b) opts.options.push('-lco', 'RFC7946=YES')
if (b.targetSrs) opts.options.push("-t_srs", b.targetSrs)
if (b.sourceSrs) opts.options.push("-s_srs", b.sourceSrs)
if ("rfc7946" in b) opts.options.push("-lco", "RFC7946=YES")

res.header(
'Content-Type',
'forcePlainText' in b
? 'text/plain; charset=utf-8'
: 'application/json; charset=utf-8'
"Content-Type",
"forcePlainText" in b
? "text/plain; charset=utf-8"
: "application/json; charset=utf-8"
)
if ('forceDownload' in b) res.attachment()
if ("forceDownload" in b) res.attachment()

try {
let {data} = await ogr2ogr(req.file.path, opts)
if (b.callback) res.write(b.callback + '(')
if (b.callback) res.write(b.callback + "(")
res.write(JSON.stringify(data))
if (b.callback) res.write(')')
if (b.callback) res.write(")")
res.end()
} finally {
unlink(req.file.path, (er) => {
if (er) console.error('unlink file error', er.message)
if (er) console.error("unlink file error", er.message)
})
}
}

private convertJson = (): RequestHandler => async (req, res) => {
let b = req.body
if (!b.jsonUrl && !b.json) {
res.status(400).json({error: true, msg: 'No json provided'})
res.status(400).json({error: true, msg: "No json provided"})
return
}

Expand All @@ -136,22 +136,22 @@ class Ogre {
try {
data = JSON.parse(b.json)
} catch (er) {
res.status(400).json({error: true, msg: 'Invalid json provided'})
res.status(400).json({error: true, msg: "Invalid json provided"})
return
}
}

let input = b.jsonUrl || data
let output = b.outputName || 'ogre'
let output = b.outputName || "ogre"

let opts = {
format: (b.format || 'ESRI Shapefile').toLowerCase(),
format: (b.format || "ESRI Shapefile").toLowerCase(),
timeout: this.timeout,
options: [] as string[],
}

if (b.outputName) opts.options.push('-nln', b.outputName)
if ('forceUTF8' in b) opts.options.push('-lco', 'ENCODING=UTF-8')
if (b.outputName) opts.options.push("-nln", b.outputName)
if ("forceUTF8" in b) opts.options.push("-lco", "ENCODING=UTF-8")

let out = await ogr2ogr(input, opts)
res.attachment(output + out.extname)
Expand Down
Loading