Commit 8e37e015 authored by Michael Auer's avatar Michael Auer
Browse files

Merge branch '11-set-proper-user-agent' into 'master'

Resolve "Set proper User-Agent"

Closes #11

See merge request !10
parents de886bd1 e60b94ea
......@@ -14,7 +14,8 @@
"watch": "watch 'npm run build' src",
"test": "echo \"Error: no test specified\" && exit 1",
"build": "tsc --build ./tsconfig.json",
"prepare": "npm run build"
"prepare": "npm run build",
"version": "node -p \"'//This is updated automatically during npm version <major|minor|pacth|...>\\nexport const OHSOME2X_VERSION = ' + JSON.stringify(require('./package.json').version) + ';'\" > src/version.ts"
},
"repository": {
"type": "git",
......
......@@ -22,6 +22,7 @@ import {PgColumnTypes} from './PgColumnTypes';
import {reproject} from 'reproject';
import * as proj4 from 'proj4';
import {OHSOME2X_VERSION} from './version';
let OHSOME_API_URL = normalizeUrl(defaultConfig.OHSOME_API_URL); //remove trailing slash and other things
class Ohsome2X extends EventEmitter {
......@@ -47,19 +48,28 @@ class Ohsome2X extends EventEmitter {
private shouldCreateGeometry: boolean;
private transformToWebmercator: boolean;
private shouldWriteHorizontalTimestamps: boolean;
private userAgentHeader: string;
constructor(config: Ohsome2XConfig) {
super(); //EventEmitter
this.config = Object.assign({}, config);
let {
ohsomeApiUrl = OHSOME_API_URL,
userAgentHeader: customUserAgentHeader = '',
source: {
keepColumns = []
}
} = this.config;
this.cursor = ('cursor' in this.config.source)? this.config.source.cursor : null;
// @ts-ignore fetchSize only available for PostgisStoreConfig
this.fetchSize = (!!this.config.source.fetchSize) ? parseInt(this.config.source.fetchSize) : null;
this.storeZeroValues = (!('storeZeroValues' in this.config.target)) ? true : !!this.config.target.storeZeroValues;
this.computeValuePerArea = this.config.target.computeValuePerArea;
this.keepColumns = this.config.source.keepColumns || [];
this.keepColumns = keepColumns;
this.sourceFeatureType = null;
this.targetFeatureType = null;
//createGeometryOnTarget? default is true
......@@ -69,9 +79,11 @@ class Ohsome2X extends EventEmitter {
// write timestamp values in one or many columns? default is vertical (one column or two columns for contribution view queries)
this.shouldWriteHorizontalTimestamps = !!this.config.target.horizontalTimestampColumns;
this.ohsomeApiUrl = config.ohsomeApiUrl || OHSOME_API_URL;
// let customUserAgentHeader = config.userAgentHeader || '';
let defaultUserAgentHeader = `ohsome2x/${OHSOME2X_VERSION}`;
this.userAgentHeader = [customUserAgentHeader, defaultUserAgentHeader].filter(userAgent => userAgent.trim() !== '').join(" ");
console.log(this.userAgentHeader);
this.ohsomeApiUrl = ohsomeApiUrl; //config.ohsomeApiUrl || OHSOME_API_URL;
//default use csv because its way faster than parsing json
this.config.ohsomeQuery.format = (this.config.ohsomeQuery.format == null || this.config.ohsomeQuery.format.trim() === '')? 'csv' : this.config.ohsomeQuery.format.trim() as 'csv' | 'json';
......@@ -565,7 +577,7 @@ class Ohsome2X extends EventEmitter {
.forEach((feature: Feature<Geometry | GeometryCollection, Properties>) => {
if (feature?.properties) {
let keptProps: { [props: string]: any } = {};
Object.keys(feature.properties)
keptProps = Object.keys(feature.properties)
.filter(property => keepColumnsNames.has(property))
.reduce((obj, property) => {
obj[property] = feature.properties![property];
......@@ -655,7 +667,10 @@ class Ohsome2X extends EventEmitter {
const stats = await axios(<AxiosRequestConfig>{
url: `${this.ohsomeApiUrl}/${queryType}`,
method: 'post',
header: {'content-type': 'application/x-www-form-urlencoded'},
header: {
'content-type': 'application/x-www-form-urlencoded',
'User-Agent': this.userAgentHeader
},
maxContentLength: Infinity,
maxBodyLength: Infinity,
data: dataString
......
......@@ -22,7 +22,7 @@ export interface PostgisStore extends Store {
export interface FeatureTypeConfig<T extends GeoJSONStore | PostgisStore> {
name? : string;
store: T;// GeoJSONStore | PostgisStore;
store: T; // can be GeoJSONStore | PostgisStore;
keepColumns?: { name: string; as?: string }[];
}
......@@ -91,6 +91,7 @@ export interface OhsomeQueryGroupByTagConfig extends OhsomeQueryConfig{
export interface Ohsome2XConfig {
ohsomeApiUrl?: string;
userAgentHeader?: string;
source: SourceGeoJSONFeatureTypeConfig | SourcePostgisFeatureTypeConfig;
target: TargetGeoJSONFeatureTypeConfig | TargetPostgisFeatureTypeConfig;
ohsomeQuery: OhsomeQueryConfig | OhsomeQueryRatioConfig;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment