@opengis/gis 0.2.97 → 0.2.99

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,32 +1,32 @@
1
- [
2
- {
3
- "id": "1",
4
- "text": "Діючий",
5
- "color": "#1ab394"
6
- },
7
- {
8
- "id": "2",
9
- "text": "Зупинений",
10
- "color": "#ed82c8"
11
- },
12
- {
13
- "id": "3",
14
- "text": "Скасований",
15
- "color": "#4a4a4a"
16
- },
17
- {
18
- "id": "5",
19
- "text": "Проектний",
20
- "color": "#6495ed"
21
- },
22
- {
23
- "id": "7",
24
- "text": "Очікує розгляду",
25
- "color": "#92b8ef"
26
- },
27
- {
28
- "id": "10",
29
- "text": "Архівний",
30
- "color": "#d48428"
31
- }
1
+ [
2
+ {
3
+ "id": "1",
4
+ "text": "Діючий",
5
+ "color": "#1ab394"
6
+ },
7
+ {
8
+ "id": "2",
9
+ "text": "Зупинений",
10
+ "color": "#ed82c8"
11
+ },
12
+ {
13
+ "id": "3",
14
+ "text": "Скасований",
15
+ "color": "#4a4a4a"
16
+ },
17
+ {
18
+ "id": "5",
19
+ "text": "Проектний",
20
+ "color": "#6495ed"
21
+ },
22
+ {
23
+ "id": "7",
24
+ "text": "Очікує розгляду",
25
+ "color": "#92b8ef"
26
+ },
27
+ {
28
+ "id": "10",
29
+ "text": "Архівний",
30
+ "color": "#d48428"
31
+ }
32
32
  ]
@@ -31,6 +31,7 @@
31
31
  "home",
32
32
  "geolocation",
33
33
  "length",
34
+ "ruler",
34
35
  "area",
35
36
  "print"
36
37
  ]
@@ -85,6 +85,7 @@
85
85
  "home",
86
86
  "geolocation",
87
87
  "length",
88
+ "ruler",
88
89
  "area",
89
90
  "print"
90
91
  ]
@@ -46,6 +46,7 @@
46
46
  "home",
47
47
  "geolocation",
48
48
  "length",
49
+ "ruler",
49
50
  "area",
50
51
  "print"
51
52
  ]
@@ -1 +1 @@
1
- select uid, coalesce(coalesce(sur_name,'')||coalesce(' '||user_name,'') ||coalesce(' '||father_name,''),login) as text from admin.users
1
+ select uid, coalesce(coalesce(sur_name,'')||coalesce(' '||user_name,'') ||coalesce(' '||father_name,''),login) as text from admin.users
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengis/gis",
3
- "version": "0.2.97",
3
+ "version": "0.2.99",
4
4
  "type": "module",
5
5
  "author": "Softpro",
6
6
  "main": "./dist/index.js",
@@ -2,7 +2,9 @@ import { createHash } from 'node:crypto';
2
2
 
3
3
  import Sphericalmercator from '@mapbox/sphericalmercator';
4
4
 
5
- import { config, logger, pgClients } from '@opengis/fastify-table/utils.js';
5
+ import {
6
+ config, logger, pgClients, dataUpdate,
7
+ } from '@opengis/fastify-table/utils.js';
6
8
 
7
9
  import mapnik from '../../../plugins/mapnik/funcs/mapnik.js';
8
10
 
@@ -26,7 +28,7 @@ const mercator = new Sphericalmercator({ size: 256 });
26
28
  */
27
29
 
28
30
  export default async function rtile({
29
- pg = pgClients.client, params, query,
31
+ pg = pgClients.client, params, query, user,
30
32
  }, reply) {
31
33
  if (!RenderTile) {
32
34
  return reply.status(400).send({ error: 'mapnik server address needed', code: 400 });
@@ -44,26 +46,35 @@ export default async function rtile({
44
46
  return reply.status(400).send({ error: 'not enough params: xyz', code: 400 });
45
47
  }
46
48
 
47
- const raster = pg.pk?.['gis.rasters']
48
- ? await pg.query('select raster_id, source_path from gis.rasters where raster_id=$1::text', [id])
49
+ const decodedPath = Buffer.from(id, 'base64url').toString('utf-8');
50
+
51
+ const data = pg.pk?.['gis.rasters']
52
+ ? await pg.queryCache(`select raster_id as id, source_path, is_public, 'raster' as type from gis.rasters where raster_id=$1::text or source_path=$2::text`, { args: [id, decodedPath], table: 'gis.rasters' })
49
53
  .then(el => el.rows?.[0] || {})
50
54
  : {};
51
55
 
52
- // const relpath = raster ? `/map/raster/${raster.source_path}` : null;
53
-
54
56
  const carto = pg.pk?.['gis.cartocss']
55
- ? await pg.query('select cartocss_id, source_path from gis.cartocss where cartocss_id=$1::text', [id])
56
- .then(el => el.rows?.[0] || {})
57
+ ? await pg.queryCache('select cartocss_id, source_path, is_public from gis.cartocss where cartocss_id=$1::text', { args: [id], table: 'gis.cartocss' }).then(el => el.rows?.[0] || {})
57
58
  : {};
58
59
 
59
- const cartoExists = !!carto.cartocss_id;
60
+ if (carto.cartocss_id) {
61
+ Object.assign(data, {
62
+ id: carto.cartocss_id,
63
+ source_path: carto.source_path,
64
+ is_public: carto.is_public,
65
+ type: 'css',
66
+ });
67
+ }
68
+
69
+ if (!user?.uid && data.is_public === false) {
70
+ return reply.status(403).send({ error: 'access restricted', code: 403 });
71
+ }
60
72
 
61
- if (!raster.raster_id && !cartoExists) {
62
- const decodedPath = Buffer.from(id, 'base64url').toString('utf-8');
63
- Object.assign(raster, { source_path: decodedPath });
73
+ if (!data.id && data.type !== 'css') {
74
+ Object.assign(data, { source_path: decodedPath });
64
75
  }
65
76
 
66
- if (!raster.source_path && !cartoExists) {
77
+ if (!data.source_path && data.type !== 'css') {
67
78
  return reply.status(404).send({ error: 'raster / cartocss not found', code: 404 });
68
79
  }
69
80
 
@@ -71,51 +82,51 @@ export default async function rtile({
71
82
 
72
83
  try {
73
84
  const ttl = (query.nocache ? '0' : null)
74
- || (cartoExists ? '1h' : null);
85
+ || (data.type === 'css' ? '1h' : null);
75
86
 
76
- const md5 = raster.source_path
77
- ? createHash('md5').update(raster.source_path).digest('hex')
87
+ const md5 = data.source_path
88
+ ? createHash('md5').update(data.source_path).digest('hex')
78
89
  : undefined;
79
- const base64 = raster.source_path
80
- ? Buffer.from(raster.source_path).toString('base64url')
90
+ const base64 = data.source_path
91
+ ? Buffer.from(data.source_path).toString('base64url')
81
92
  : undefined;
82
93
 
83
94
  const param = {
84
- path: cartoExists ? null : raster.source_path, // for rasters only
85
- name: cartoExists && carto.source_path ? `vector/${carto.source_path}` : id, // required for cartocss
95
+ path: data.type === 'css' ? null : data.source_path, // for rasters only
96
+ name: data.type === 'css' && data.source_path ? `vector/${data.source_path}` : id, // required for cartocss
86
97
  width: 256,
87
98
  bbox,
88
99
  ttl,
89
100
  debug: query.debug,
90
101
  };
91
102
  // console.log(param);
92
- const data = await RenderTile(param);
103
+ const result = await RenderTile(param);
93
104
 
94
105
  if (query.debug) {
95
106
  return {
96
- ...data,
107
+ ...result,
97
108
  ttl,
98
109
  md5_path: md5,
99
110
  base64_path: base64,
100
- raster: !!raster.raster_id,
101
- carto: cartoExists,
111
+ raster: !!data.id,
112
+ carto: data.type === 'css',
102
113
  };
103
114
  }
104
115
 
105
- if (data.err) {
116
+ if (result.err) {
106
117
  logger.file('rtile/error', {
107
- error: data.err, x, y, z, id: cartoExists ? carto.cartocss_id : raster.raster_id, type: cartoExists ? 'css' : 'raster',
118
+ error: result.err, x, y, z, id: data.id, type: data.type,
108
119
  });
109
- return reply.status(500).send({ error: config.local ? data.err : 'render error', code: 500 });
120
+ return reply.status(500).send({ error: config.local ? result.err : 'render error', code: 500 });
110
121
  }
111
122
 
112
- const buffer = Buffer.from(data.base64, 'base64');
123
+ const buffer = Buffer.from(result.base64, 'base64');
113
124
 
114
125
  return reply.headers({ 'Content-Type': 'image/png', 'Cache-Control': query.nocache || query.nottl ? 'no-store, no-cache, must-revalidate' : 'public, max-age=2592000' }).send(buffer);
115
126
  }
116
127
  catch (err) {
117
128
  logger.file('rtile/error', {
118
- error: err.toString(), stack: err.stack, x, y, z, id: cartoExists ? carto.cartocss_id : raster.raster_id, type: cartoExists ? 'css' : 'raster',
129
+ error: err.toString(), stack: err.stack, x, y, z, id: data.id, type: data.type,
119
130
  });
120
131
  return reply.status(500).send({ error: config.local ? err.toString() : 'rtile error', code: 500 });
121
132
  }