1 | var collect = require('collect-stream')
|
2 | var osm2Obj = require('osm2json')
|
3 |
|
4 | var errors = require('../errors')
|
5 | var isValidContentType = require('../lib/util').isValidContentType
|
6 |
|
7 | module.exports = function (req, res, api, params, next) {
|
8 | if (!isValidContentType(req)) {
|
9 | return next(new errors.UnsupportedContentType())
|
10 | }
|
11 |
|
12 | var r = req.pipe(osm2Obj({types: [params.type], coerceIds: false}))
|
13 | collect(r, function (err, ops) {
|
14 | if (err) return next(new errors.XmlParseError(err))
|
15 | if (!ops.length) return next(new errors.XmlMissingElement(params.type))
|
16 |
|
17 |
|
18 |
|
19 | api.createElement(ops[0], function (err, id, node) {
|
20 | if (err) return next(err)
|
21 | res.setHeader('content-type', 'text/plain; charset=utf-8')
|
22 | res.end(id + '\n')
|
23 | })
|
24 | })
|
25 | }
|