@opengis/gis 0.2.55 → 0.2.56

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengis/gis",
3
- "version": "0.2.55",
3
+ "version": "0.2.56",
4
4
  "type": "module",
5
5
  "author": "Softpro",
6
6
  "main": "./dist/index.js",
@@ -20,7 +20,7 @@ function sequence(arr, fn) {
20
20
 
21
21
  const unsafe = true;
22
22
 
23
- export default async function checkRasterFile({ arr, reply }) {
23
+ export default async function checkRasterFile({ arr, reply, nocache }) {
24
24
  const callback = reply ? eventStream(reply) : () => { };
25
25
 
26
26
  let
@@ -46,7 +46,7 @@ export default async function checkRasterFile({ arr, reply }) {
46
46
  }
47
47
 
48
48
  // create at xml/:id with name only, always - by path
49
- const resp = await CreateXML({ path: relpath }, (msg) => {
49
+ const resp = await CreateXML({ path: relpath, nocache }, (msg) => {
50
50
  if (typeof msg === 'string' && msg === 'XML creation complete') {
51
51
  createdCount += 1;
52
52
  }
@@ -12,7 +12,7 @@ const dirname = path.dirname(filepath);
12
12
  const PROTO_PATH = path.join(dirname, '../', 'map.proto');
13
13
  // const PROTO_PATH = config.mapServerAddress && config.mapServerAddress.startsWith('127.0.0.1') ? path.join(dirname, '../../../../../../service/mapnikp/map.proto') : path.join(dirname, '../', 'map.proto');
14
14
 
15
- const { mapServerAddress, ready } = config;
15
+ const { mapServerAddress } = config;
16
16
 
17
17
  if (!mapServerAddress) {
18
18
  throw new Error("Map server address is not defined in the configuration.");
@@ -38,11 +38,11 @@ const mapClient = new proto.map.MapService(
38
38
 
39
39
  mapClient.waitForReady(Date.now() + 5000, (err) => {
40
40
  if (err) {
41
- ready.mapnik = false;
41
+ config.ready.mapnik = false;
42
42
  console.error("Mapnik client connection timeout or failure:", err);
43
43
  }
44
44
  else {
45
- ready.mapnik = true;
45
+ config.ready.mapnik = true;
46
46
  console.log("Mapnik client connected successfully.");
47
47
  }
48
48
  });
@@ -131,12 +131,13 @@ message GetRenderOut {
131
131
  }
132
132
 
133
133
  message GetLogsRequest {
134
- string period = 1; // "5m", "1h", "1d"
135
- string type = 2; // optional filter
134
+ string path = 1; // "info", "info/2026-01-01.log" etc.
136
135
  }
137
136
 
138
137
  message GetLogsOut {
139
- repeated string result = 1;
138
+ string data = 1;
139
+ string links = 2;
140
+ string err = 3;
140
141
  }
141
142
 
142
143
  message GetRasterInfoRequest {
@@ -85,7 +85,13 @@ export default async function vtile({
85
85
  const select = data.popup?.find(el => el.name === key);
86
86
  // console.log(select);
87
87
  const clsData = select?.data || col.data;
88
- const cls = clsData ? await getSelect(clsData).then(el => ({ name: clsData, type: el.arr ? 'cls' : 'select', sql: el.sql })) : null;
88
+ const cls = clsData ? await getSelect(clsData).then(el => {
89
+ if (!el) {
90
+ console.error('gis vtile: cls not found', clsData);
91
+ return null;
92
+ }
93
+ return { name: clsData, type: el.arr ? 'cls' : 'select', sql: el.sql };
94
+ }) : null;
89
95
  const { name, type: type1, sql: sql1 } = cls || getColumnCLS(table, col.data || key) || {};
90
96
  // console.log({ name, type, sql });
91
97
  if (name && type1 === 'cls') {
@@ -0,0 +1,75 @@
1
+ import {
2
+ applyHookSync, config, pgClients,
3
+ } from '@opengis/fastify-table/utils.js';
4
+
5
+ import checkRasterFile from '../../../plugins/mapnik/funcs/checkRasterFile.js';
6
+
7
+ // todo: add to kamianske, remove custom api and test
8
+ // addHook('beforeCreateXmlMulti', ({ list = [], id }) => {
9
+ // list.push({
10
+ // id: 'mbd_existent_detail_id',
11
+ // table: 'data_mbd.mbd_existent_detail',
12
+ // relpath: 'upfile',
13
+ // q: `select mbd_existent_detail_id, upfile
14
+ // from data_mbd.mbd_existent_detail a
15
+ // left join data_mbd.mbd b on a.mbd_id=b.mbd_id
16
+ // where material_type_id = '3245363247443870877'
17
+ // and upfile is not null
18
+ // and upfile ~ '.tif'
19
+ // and left(upfile,7) != '/files/'
20
+ // ${id ? ` and mbd_existent_detail_id = '${id}'` : ''}`,
21
+ // });
22
+ // });
23
+
24
+ export default async function createXmlMulti({
25
+ pg = pgClients.client, params, query,
26
+ }, reply) {
27
+ if (!config.mapServerAddress) {
28
+ return reply.code(400).send({
29
+ error: 'mapnik grpc service address not set',
30
+ code: 400,
31
+ });
32
+ }
33
+
34
+ if (config.ready?.mapnik !== true) {
35
+ return reply.code(400).send({
36
+ error: 'mapnik grpc service not ready',
37
+ code: 400,
38
+ });
39
+ }
40
+
41
+ const list = [{
42
+ id: 'raster_id',
43
+ relpath: 'source_path',
44
+ table: 'gis.rasters',
45
+ query: `source_path is not null ${params.id ? ` and raster_id = '${params.id}'` : ''}`,
46
+ }];
47
+
48
+ applyHookSync('beforeCreateXmlMulti', { list, id: params.id });
49
+
50
+ const rows = await Promise.all(list.filter(el => el.id && el.table && el.relpath).map(async el => pg.query(el.q ? `select ${el.id} as id, ${el.relpath} as relpath, '${el.table}' as table from (${el.q})q` : `select ${el.id} as id, ${el.relpath} as relpath, '${el.table}' as table from ${el.table} where ${el.query || 'true'}`).then(e => e.rows || []))).then(e => e.flat());
51
+
52
+ if (!rows.length) {
53
+ return reply.status(404).send({ error: 'empty rows', code: 404 });
54
+ }
55
+
56
+ const results = await checkRasterFile({ arr: rows.map(row => row.relpath), reply, nocache: query.nocache });
57
+
58
+ const q = Object.keys(results || {}).filter(key => results[key] && results[key].extent).map(key => {
59
+ const { extent } = results[key];
60
+ const extentString = `ST_MakeEnvelope(${extent[0]}, ${extent[1]}, ${extent[2]}, ${extent[3]}, 4326)`;
61
+
62
+ const { id, table } = rows.find(row => row.relpath === key) || {};
63
+ const pk = pg.pk?.[table];
64
+ return id && pk ? `update ${table} set geom=${extentString} where ${pk}='${id}'` : null;
65
+ })
66
+ .filter(Boolean);
67
+
68
+ if (config.trace) {
69
+ console.log('createXmlMulti: update bounds of', q.length, 'rows');
70
+ }
71
+
72
+ if (q.length) await pg.query(q.join(';\n'));
73
+
74
+ return reply.status(200).send('all finished');
75
+ }
@@ -11,13 +11,19 @@ export default async function mapnikLogger({
11
11
  return reply.status(400).send({ error: 'mapnik server address needed', code: 400 });
12
12
  }
13
13
 
14
- if (params.type && !['render', 'error', 'info', 'critical'].includes(params.type)) {
15
- return reply.status(400).send({ error: 'invalid params: type', code: 400 });
14
+ const { data, links, err } = await GetLogs({ path: params['*'] });
15
+
16
+ if (err) {
17
+ return reply.status(400).send(err);
18
+ }
19
+
20
+ if (links) {
21
+ return reply.headers({
22
+ "Content-Type": "text/html; charset=UTF-8",
23
+ "Content-Security-Policy": "default-src 'none'",
24
+ "X-Content-Type-Options": "nosniff",
25
+ }).send(links);
16
26
  }
17
27
 
18
- const { result } = await GetLogs({
19
- period: query.period,
20
- type: params.type,
21
- });
22
- return reply.status(200).send(result.join('\n'));
28
+ return reply.headers({ "Content-type": "text/plain; charset=UTF-8" }).send(data);
23
29
  }
@@ -5,6 +5,7 @@ import rasterInfo from './controllers/rasterInfo.js';
5
5
  import mapnikStat from './controllers/mapnikStat.js';
6
6
  import mapnikLogger from './controllers/mapnikLogger.js';
7
7
  import checkCarto from './controllers/checkCarto.js';
8
+ import createXmlMulti from './controllers/createXmlMulti.js';
8
9
 
9
10
  const publicParams = { config: { policy: 'L0' }, package: 'gis' }; // L0 === public
10
11
  const adminParams = { config: { policy: 'L1', role: 'admin' }, package: 'gis' };
@@ -16,6 +17,7 @@ export default async function route(app) {
16
17
  app.get('/gis-rtile/:id/:z/:y/:x', publicParams, rtile);
17
18
  app.get('/gis-raster/:id', publicParams, rasterInfo);
18
19
  app.get('/gis-stat/:period?', adminParams, mapnikStat);
19
- app.get('/gis-logger/:type?', adminParams, mapnikLogger);
20
+ app.get('/gis-logger/*', adminParams, mapnikLogger);
20
21
  app.get('/gis-css/:id', params, checkCarto);
22
+ app.get('/gis-create-xml/:id?', adminParams, createXmlMulti);
21
23
  }