Skip to content

Commit

Permalink
utils
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanocudini committed Sep 7, 2023
1 parent 615b56b commit 90970c3
Show file tree
Hide file tree
Showing 13 changed files with 21 additions and 31 deletions.
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -258,15 +258,14 @@ for details see the descriptions in the [Roadmap issues](https://github.com/open

|Status| Goal |
|------|-------------|
| ✔️ | Swagger Documentation Interface |
| | manage multiple datasets |
| ✔️ | Swagger Documentation Interface |
| 🚧 | manage multiple datasets |
| 🚧 | ES6 modules |
| 🚧 | extend benchmarks for any endpoints |
| ✔️ | enable densify function |
| 🚧 | enable simply function |
|| unit testing |
|| support vector format in datasets, such as shapefile |
|| supports complex geometries in input |
|| support vector format in datasets, such as shapefile |
|| limit access by api key |
|| caching responses |
|| interfaces: websocket, jsonrpc |
Expand Down
2 changes: 2 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
const gdal = require('gdal-async')
, turf = require('@turf/turf')
, package = require(`${__dirname}/../package.json`)
, utils = require('./utils')
, { datasetInfo, parseLocations } = utils

Expand Down Expand Up @@ -93,6 +94,7 @@ function setValue(data, fileData, opts = {}) {
}

module.exports = {
package,
gdal,
turf,
utils,
Expand Down
3 changes: 1 addition & 2 deletions server/formats/geojson.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

module.exports = fastify => {;

const {utils: {parseLocations}} = fastify.gpicker
//TODO Response set schema
const {utils: {parseLocations}} = fastify;

return {
geojsonRead: (data, req) => {
Expand Down
3 changes: 1 addition & 2 deletions server/formats/gpx.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ const togpx = require('togpx');

module.exports = fastify => {
const {package} = fastify
, {version, homepage} = package
, creator = `Geopicker ${version} - ${homepage}`;
, creator = `Geopicker v${package.version} - ${package.homepage}`;

return {
gpxRead: (data, req) => {
Expand Down
14 changes: 7 additions & 7 deletions server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@
* https://opengeo.tech
*/
const basepath = __dirname
, {resolve} = require('path')
, configYml = require('@stefcud/configyml')
, config = require('@stefcud/configyml')({basepath})
, Fastify = require('fastify')
, gpicker = require('../lib')
, package = require(resolve(`${basepath}/../package.json`))
, config = configYml({basepath})
, {utils, package} = gpicker
, {fastifyConf, port, host, prefix} = config
, {cors, compress, swagger, demopage, isDev} = config;

Expand All @@ -19,13 +17,14 @@ const fastify = Fastify(fastifyConf);
/**
* Decorators
*/
fastify.decorate('package', package);
fastify.decorate('gpicker', gpicker);
fastify.decorate('config', config);
fastify.decorate('gpicker', gpicker);
fastify.decorate('package', package);
fastify.decorate('utils', utils);
fastify.decorate('status', 'OK');

/**
* Base Plugins configs and utils
* Base Plugins
*/
fastify.register(require('./plugins/errors'));
fastify.register(require('./plugins/datasets'));
Expand Down Expand Up @@ -55,6 +54,7 @@ if (demopage.enabled) {
if (isDev) {
fastify.register(require('./plugins/debug'));
}

/**
* Routes
*/
Expand Down
3 changes: 1 addition & 2 deletions server/plugins/densify.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ const fp = require('fastify-plugin');

module.exports = fp(async fastify => {

const {config, gpicker} = fastify
, {utils: {densifyLocations}} = gpicker;
const {config, utils: {densifyLocations}} = fastify;

fastify.addHook('preHandler', (req, res, done) => {

Expand Down
3 changes: 1 addition & 2 deletions server/plugins/precision.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ const fp = require('fastify-plugin');

module.exports = fp(async fastify => {

const {config, gpicker} = fastify
, {utils: {setPrecision}} = gpicker;
const {config, utils: {setPrecision}} = fastify;

fastify.addHook('preHandler', (req, res, done) => {

Expand Down
3 changes: 1 addition & 2 deletions server/plugins/simplify.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ const fp = require('fastify-plugin');

module.exports = fp(async fastify => {

const {config, gpicker} = fastify
, {utils: {simplifyLocations}} = gpicker;
const {config, utils: {simplifyLocations}} = fastify;

fastify.addHook('preHandler', (req, res, done) => {

Expand Down
2 changes: 0 additions & 2 deletions server/plugins/swagger.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ module.exports = fp(async fastify => {
url: homepage,
description: attribution
}
//servers: [ Object ],
//components: Object,
}
});

Expand Down
3 changes: 1 addition & 2 deletions server/routes/datasets.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@

module.exports = async fastify => {

const {gpicker, datasets, schemas, errors} = fastify
, {utils: {bboxContains} } = gpicker
const {datasets, schemas, errors, utils: {bboxContains}} = fastify
, datasetsList = Object.entries(datasets).map(d => d[1])

fastify.get('/datasets', {schema: schemas.datasetsList}, async req => {
Expand Down
1 change: 0 additions & 1 deletion server/routes/geometry.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module.exports = async fastify => {

const {config, /*schemas,*/ datasetDefault, gpicker} = fastify
, {setValue} = gpicker
// eslint-disable-next-line
, {compress} = config;

fastify.post('/:datasetId/geometry', {/*schema: schemas.geometryPost, */compress}, async req => {
Expand Down
3 changes: 1 addition & 2 deletions server/routes/metadata.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@

module.exports = async fastify => {

const {schemas, gpicker} = fastify
, {utils: {getMetadata} } = gpicker;
const {schemas, utils: {getMetadata}} = fastify;

fastify.get('/metadata/:locations', {schema: schemas.metadataLocations}, async req => {

Expand Down
5 changes: 2 additions & 3 deletions server/routes/status.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ const {resolve} = require('path');

module.exports = async fastify => {

const {config, status, gpicker, package, schemas, datasetsIds} = fastify
, {utils: {humanSize} } = gpicker
, {version, homepage} = package
const {config, status, gpicker, package, utils: {humanSize}, schemas, datasetsIds} = fastify
, {fastifyConf, attribution, swagger, compress, cors, demopage, formats} = config
, {validation, maxLocations, precision} = config
, {maxParamLength, bodyLimit} = fastifyConf || {}
Expand All @@ -14,6 +12,7 @@ module.exports = async fastify => {
, crossorigin = cors.enabled ? cors.origin : false
, compression = compress.enabled ? compress.encodings : false
, frontend = demopage ? demopage.path : false
, {version, homepage} = package
, documentation = swagger.enabled ? resolve(swagger.routePrefix) : homepage;

// eslint-disable-next-line
Expand Down

0 comments on commit 90970c3

Please sign in to comment.