@opengis/gis 0.2.175 → 0.2.176
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/README.md +181 -181
- package/dist/{CardIcon-Cg8bUM4G.js → CardIcon-c1Q2M3wQ.js} +1 -1
- package/dist/{EntityTablePage-DHQGlLRk.js → EntityTablePage-B5gpkH4S.js} +2 -2
- package/dist/{ExtentOutlineLayer.vue_vue_type_script_setup_true_lang-BIL1ocLY.js → ExtentOutlineLayer.vue_vue_type_script_setup_true_lang-DnGSvmMU.js} +1 -1
- package/dist/{HeaderActions.vue_vue_type_script_setup_true_lang-Buff9gTO.js → HeaderActions.vue_vue_type_script_setup_true_lang-C2B61JP6.js} +1 -1
- package/dist/{MapSettings-De-z7r5t.js → MapSettings-6-Xru5Q8.js} +2 -2
- package/dist/{RastersTablePage-Cdgkri9K.js → RastersTablePage-CXNOcTy-.js} +2 -2
- package/dist/{cartocss-BT50SVhy.js → cartocss-BFVqWvfP.js} +6 -6
- package/dist/{import-utils-CMWiuRPp.js → import-utils-uxk4LdUJ.js} +1 -1
- package/dist/{index-CHFLgCGW.js → index-CahlV-Xs.js} +39 -39
- package/dist/index.css +1 -1
- package/dist/index.js +1 -1
- package/dist/index.umd.cjs +19 -19
- package/dist/{raster-dSEb1SIG.js → raster-CEi56f0P.js} +3 -3
- package/dist/{register-D7Puupgo.js → register-NFAGBNa3.js} +3 -3
- package/dist/{service-Cz6T0O3Z.js → service-BYspag8U.js} +829 -832
- package/dist/{vs-datatable-DqVncrSg.js → vs-datatable-CHcBr6zy.js} +2 -2
- package/module/gis/cls/service_type.json +42 -42
- package/module/gis/form/gis.registers.form.json +127 -127
- package/module/test/map/addr.json +302 -302
- package/module/test/map/addr1.yml +23 -23
- package/module/test/select/address.str_id.sql +3 -3
- package/package.json +77 -77
- package/plugin.js +64 -64
- package/server/migrations/array_intersect.sql +13 -13
- package/server/migrations/cartocss.sql +27 -27
- package/server/migrations/group_list.sql +74 -74
- package/server/migrations/maps.sql +30 -30
- package/server/migrations/metadata.sql +415 -415
- package/server/migrations/ogc.sql +106 -106
- package/server/migrations/rasters.sql +265 -265
- package/server/migrations/services.sql +247 -247
- package/server/migrations/services_users_rel.sql +22 -22
- package/server/migrations/widgets.sql +20 -20
- package/server/plugins/crons.js +21 -21
- package/server/plugins/mapnik/funcs/checkRasterFile.js +107 -107
- package/server/plugins/mapnik/funcs/mapnik.js +151 -151
- package/server/plugins/mapnik/funcs/rootFolder.mjs +8 -8
- package/server/plugins/mapnik/map.proto +437 -437
- package/server/plugins/vite.js +74 -74
- package/server/routes/cartocss/cartocss.route.js +31 -31
- package/server/routes/cartocss/cartocss.route.test.js +78 -78
- package/server/routes/cartocss/cartocss.schema.js +73 -73
- package/server/routes/cartocss/functions/add.cartocss.js +39 -39
- package/server/routes/cartocss/functions/get.cartocss.js +57 -57
- package/server/routes/gis/functions/checkXML.js +107 -107
- package/server/routes/gis/functions/dashboard.js +24 -24
- package/server/routes/gis/gis.route.js +26 -26
- package/server/routes/gis/gis.route.test.js +33 -33
- package/server/routes/map/functions/clearTiles.js +35 -35
- package/server/routes/map/functions/geojson.js +187 -187
- package/server/routes/map/functions/gis.convert.js +65 -65
- package/server/routes/map/functions/gis.icon.js +220 -220
- package/server/routes/map/functions/jsonData.js +206 -206
- package/server/routes/map/functions/layerList.js +102 -102
- package/server/routes/map/functions/map.js +122 -122
- package/server/routes/map/functions/mapCatalog.js +72 -72
- package/server/routes/map/functions/mapCatalogAttribute.js +53 -53
- package/server/routes/map/functions/mapFeatures.js +133 -133
- package/server/routes/map/functions/mapFormat.js +232 -231
- package/server/routes/map/functions/mapTiles.js +162 -162
- package/server/routes/map/functions/maps.js +15 -15
- package/server/routes/map/functions/marker_icon.js +43 -43
- package/server/routes/map/functions/parseGeoFile.js +85 -85
- package/server/routes/map/functions/pointHeight.js +51 -51
- package/server/routes/map/functions/vtile.js +174 -174
- package/server/routes/map/functions/vtile1.js +185 -185
- package/server/routes/map/map.route.js +280 -280
- package/server/routes/map/map.route.test.js +503 -503
- package/server/routes/map/map.schema.js +356 -356
- package/server/routes/map/pin/circle1.svg +76 -76
- package/server/routes/map/pin/circle2.svg +18 -18
- package/server/routes/map/pin/none.svg +12 -12
- package/server/routes/map/pin/pin.svg +14 -14
- package/server/routes/map/pin/pin1.svg +16 -16
- package/server/routes/map/pin/pin2.svg +7 -7
- package/server/routes/map/pin/pin3.svg +34 -34
- package/server/routes/map/pin/pin4.svg +14 -14
- package/server/routes/map/pin/pin5.svg +7 -7
- package/server/routes/map/pin/pin6.svg +12 -12
- package/server/routes/map/pin/pin7.svg +12 -12
- package/server/routes/mapnik/functions/cartoBounds.js +32 -32
- package/server/routes/mapnik/functions/clearTiles.js +103 -103
- package/server/routes/mapnik/functions/convertBoundToTile.js +27 -27
- package/server/routes/mapnik/functions/createXml.js +76 -76
- package/server/routes/mapnik/functions/createXmlMulti.js +72 -72
- package/server/routes/mapnik/functions/fileSearch.js +35 -35
- package/server/routes/mapnik/functions/fileStat.js +28 -28
- package/server/routes/mapnik/functions/pretile.js +138 -138
- package/server/routes/mapnik/functions/rasterInfo.js +66 -66
- package/server/routes/mapnik/functions/readDir.js +22 -22
- package/server/routes/mapnik/functions/rtile.js +164 -164
- package/server/routes/mapnik/functions/uploadRaster.js +152 -152
- package/server/routes/mapnik/functions/uploadXML.js +140 -140
- package/server/routes/mapnik/mapnik.route.js +102 -102
- package/server/routes/mapnik/mapnik.route.test.js +370 -370
- package/server/routes/mapnik/mapnik.schema.mjs +195 -195
- package/server/routes/mapnik.prefixless/functions/mapnikLogger.js +31 -31
- package/server/routes/mapnik.prefixless/functions/mapnikStat.js +21 -21
- package/server/routes/mapnik.prefixless/mapnik.prefixless.route.js +20 -20
- package/server/routes/mapnik.prefixless/mapnik.prefixless.route.test.js +91 -91
- package/server/routes/mapnik.prefixless/mapnik.prefixless.schema.mjs +27 -27
- package/server/routes/maps/functions/add.map.js +42 -42
- package/server/routes/maps/functions/del.map.js +17 -17
- package/server/routes/maps/functions/get.map.js +119 -119
- package/server/routes/maps/maps.route.js +58 -58
- package/server/routes/maps/maps.route.test.js +231 -231
- package/server/routes/maps/maps.schema.js +9 -9
- package/server/routes/metadata/functions/editMetadata.js +35 -35
- package/server/routes/metadata/functions/metadataXML.js +19 -19
- package/server/routes/metadata/metadata.route.js +26 -26
- package/server/routes/metadata/metadata.route.test.js +46 -46
- package/server/routes/metadata/metadata.schema.js +53 -53
- package/server/routes/ogc/functions/map.info.point.js +117 -117
- package/server/routes/ogc/ogc.route.js +21 -21
- package/server/routes/ogc/ogc.route.test.js +53 -53
- package/server/routes/ogc/ogc.schema.js +16 -16
- package/server/routes/permissions/functions/catalog.permissions.edit.js +20 -20
- package/server/routes/permissions/functions/catalog.permissions.js +12 -12
- package/server/routes/permissions/functions/get.permissions.js +59 -59
- package/server/routes/permissions/functions/gis.catalog.js +80 -80
- package/server/routes/permissions/permissions.route.js +35 -35
- package/server/routes/permissions/permissions.route.test.js +35 -35
- package/server/routes/permissions/permissions.schema.js +43 -43
- package/server/routes/registers/functions/add.registry.js +37 -37
- package/server/routes/registers/functions/classifiers.js +100 -100
- package/server/routes/registers/functions/columns.js +3 -3
- package/server/routes/registers/functions/content.type.js +9 -9
- package/server/routes/registers/functions/del.registry.js +14 -14
- package/server/routes/registers/functions/get.info.js +93 -93
- package/server/routes/registers/functions/gis.export.js +159 -159
- package/server/routes/registers/functions/gis.registry.js +71 -71
- package/server/routes/registers/functions/gis.registry.list.js +61 -61
- package/server/routes/registers/functions/handleRegistryRequest.js +147 -147
- package/server/routes/registers/functions/map.registry.js +87 -87
- package/server/routes/registers/registers.route.js +80 -80
- package/server/routes/registers/registers.route.test.js +144 -144
- package/server/routes/registers/registers.schema.js +246 -246
- package/server/routes/root.mjs +3 -3
- package/server/routes/services/functions/add.service.js +62 -62
- package/server/routes/services/functions/create.route.js +93 -93
- package/server/routes/services/functions/del.service.js +12 -12
- package/server/routes/services/functions/get.layer.geom.js +27 -27
- package/server/routes/services/functions/get.service.users.js +76 -76
- package/server/routes/services/functions/get.services.col.js +34 -34
- package/server/routes/services/functions/get.services.js +89 -89
- package/server/routes/services/functions/legend.auto.js +77 -77
- package/server/routes/services/services.route.js +76 -76
- package/server/routes/services/services.route.test.js +167 -167
- package/server/routes/services/services.schema.js +278 -278
- package/server/routes/widgets/functions/add.widget.js +38 -38
- package/server/routes/widgets/functions/del.widget.js +17 -17
- package/server/routes/widgets/functions/get.widget.js +41 -41
- package/server/routes/widgets/widgets.route.js +61 -61
- package/server/routes/widgets/widgets.route.test.js +144 -144
- package/server/routes/widgets/widgets.schema.js +24 -24
- package/server/shared/listFiles.js +15 -0
- package/utils.js +13 -13
|
@@ -1,164 +1,164 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
|
-
import { createHash } from 'node:crypto';
|
|
3
|
-
|
|
4
|
-
import { SphericalMercator } from '@mapbox/sphericalmercator';
|
|
5
|
-
|
|
6
|
-
const mercator = new SphericalMercator({ size: 256 });
|
|
7
|
-
|
|
8
|
-
import {
|
|
9
|
-
config, logger, pgClients,
|
|
10
|
-
} from '@opengis/fastify-table/utils.js';
|
|
11
|
-
|
|
12
|
-
import { BadRequestError, ForbiddenError, NotFoundError } from '@opengis/fastify-table/errors.js';
|
|
13
|
-
|
|
14
|
-
import mapnik from '../../../plugins/mapnik/funcs/mapnik.js';
|
|
15
|
-
|
|
16
|
-
const { RenderTile } = mapnik();
|
|
17
|
-
|
|
18
|
-
const meta = !!config?.mapnik?.meta;
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Формування растрового tile cartoCss
|
|
22
|
-
*
|
|
23
|
-
* @method GET
|
|
24
|
-
* @alias rtile
|
|
25
|
-
* @param {String} bbox - bbox
|
|
26
|
-
* @param {Number} height - висота по координатам
|
|
27
|
-
* @param {Number} width - ширина по координатам
|
|
28
|
-
* @param {String} data - стилізація
|
|
29
|
-
* @param {String} lang - мова
|
|
30
|
-
* @param {String} z - координата z
|
|
31
|
-
* @param {String} x - координата y
|
|
32
|
-
* @param {String} y - координата x
|
|
33
|
-
*/
|
|
34
|
-
|
|
35
|
-
export default async function gisRtile({
|
|
36
|
-
id, z, y, x, debug, nocache, nottl, uid,
|
|
37
|
-
}, pg = pgClients.client) {
|
|
38
|
-
if (!RenderTile) {
|
|
39
|
-
throw BadRequestError('mapnik server address needed');
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
if (!id) {
|
|
43
|
-
throw BadRequestError('not enough params: id');
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
if (!x || !y || !z) {
|
|
47
|
-
throw BadRequestError('not enough params: xyz');
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const decodedPath = Buffer.from(id, 'base64url').toString('utf-8');
|
|
51
|
-
|
|
52
|
-
const data = pg.pk?.['gis.rasters']
|
|
53
|
-
? 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' })
|
|
54
|
-
.then(r => r.rows?.[0] || {})
|
|
55
|
-
: {};
|
|
56
|
-
|
|
57
|
-
const carto = pg.pk?.['gis.cartocss']
|
|
58
|
-
? await pg.queryCache('select cartocss_id, source_path, is_public, is_static from gis.cartocss where cartocss_id=$1::text', { args: [id], table: 'gis.cartocss' }).then(r => r.rows?.[0] || {})
|
|
59
|
-
: {};
|
|
60
|
-
|
|
61
|
-
if (carto.cartocss_id) {
|
|
62
|
-
Object.assign(data, {
|
|
63
|
-
id: carto.cartocss_id,
|
|
64
|
-
source_path: carto.source_path,
|
|
65
|
-
is_public: carto.is_public,
|
|
66
|
-
is_static: carto.is_static,
|
|
67
|
-
type: 'css',
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
if (!uid && !config.local && data.is_public === false && process.env.NODE_ENV !== 'test' && !process.env.VITEST) {
|
|
72
|
-
throw ForbiddenError('access restricted');
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
if (!data.id && data.type !== 'css') {
|
|
76
|
-
Object.assign(data, { source_path: decodedPath });
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
if (!data.source_path && data.type !== 'css') {
|
|
80
|
-
throw NotFoundError('raster / cartocss not found');
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
const bbox = mercator.bbox(y, x, z, false, '900913');
|
|
84
|
-
|
|
85
|
-
const ttl = (nocache ? '0' : null)
|
|
86
|
-
|| (data.type === 'css' && !data.is_static ? '1w' : null);
|
|
87
|
-
|
|
88
|
-
const md5 = data.source_path
|
|
89
|
-
? createHash('md5').update(data.source_path).digest('hex')
|
|
90
|
-
: undefined;
|
|
91
|
-
const base64 = data.source_path
|
|
92
|
-
? Buffer.from(data.source_path).toString('base64url')
|
|
93
|
-
: undefined;
|
|
94
|
-
|
|
95
|
-
const getParams = () => {
|
|
96
|
-
if (data.type === 'css' && data.source_path) {
|
|
97
|
-
return { name: path.posix.join('vector', config.mapnik?.folder || '', data.source_path) };
|
|
98
|
-
}
|
|
99
|
-
if (data.type === 'css') {
|
|
100
|
-
return { name: path.posix.join('xml', config.mapnik?.folder || '', id) };
|
|
101
|
-
}
|
|
102
|
-
return { path: path.posix.join('raster', config.mapnik?.folder || '', data.source_path) };
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
const { path: rpath, name } = getParams();
|
|
106
|
-
|
|
107
|
-
const param = {
|
|
108
|
-
path: rpath, // for rasters only
|
|
109
|
-
name, // required for cartocss
|
|
110
|
-
width: 256,
|
|
111
|
-
bbox,
|
|
112
|
-
ttl,
|
|
113
|
-
format: 'webp',
|
|
114
|
-
meta,
|
|
115
|
-
base64: false,
|
|
116
|
-
debug,
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
const result = await RenderTile(param);
|
|
120
|
-
|
|
121
|
-
if (result.err) {
|
|
122
|
-
logger.file('rtile/error', {
|
|
123
|
-
error: result.err, x, y, z, id: data.id, type: data.type,
|
|
124
|
-
});
|
|
125
|
-
throw new Error(result.err);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
if (meta) {
|
|
129
|
-
const accelPath = result.tile_path?.startsWith('/') ? result.tile_path : `/${result.tile_path}`;
|
|
130
|
-
const metaHeaders = {
|
|
131
|
-
'Content-Type': 'image/webp',
|
|
132
|
-
'Cache-Control': nocache || nottl ? 'no-store, no-cache, must-revalidate' : 'public, max-age=2592000',
|
|
133
|
-
'X-Accel-Redirect': accelPath,
|
|
134
|
-
};
|
|
135
|
-
if (debug) {
|
|
136
|
-
return {
|
|
137
|
-
headers: metaHeaders,
|
|
138
|
-
base64: result.base64,
|
|
139
|
-
z,
|
|
140
|
-
x,
|
|
141
|
-
y,
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
|
-
return { headers: metaHeaders, code: 204 };
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
if (debug) {
|
|
148
|
-
return {
|
|
149
|
-
...result,
|
|
150
|
-
name,
|
|
151
|
-
path: rpath,
|
|
152
|
-
ttl,
|
|
153
|
-
md5_path: md5,
|
|
154
|
-
base64_path: base64,
|
|
155
|
-
raster: !!data.id,
|
|
156
|
-
carto: data.type === 'css',
|
|
157
|
-
is_static: data.type === 'css' ? data.is_static : true,
|
|
158
|
-
};
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
const buffer = result.data || Buffer.from(result.base64, 'base64');
|
|
162
|
-
|
|
163
|
-
return { headers: { 'Content-Type': 'image/webp', 'Cache-Control': nocache || nottl ? 'no-store, no-cache, must-revalidate' : 'public, max-age=2592000' }, data: buffer };
|
|
164
|
-
}
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { createHash } from 'node:crypto';
|
|
3
|
+
|
|
4
|
+
import { SphericalMercator } from '@mapbox/sphericalmercator';
|
|
5
|
+
|
|
6
|
+
const mercator = new SphericalMercator({ size: 256 });
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
config, logger, pgClients,
|
|
10
|
+
} from '@opengis/fastify-table/utils.js';
|
|
11
|
+
|
|
12
|
+
import { BadRequestError, ForbiddenError, NotFoundError } from '@opengis/fastify-table/errors.js';
|
|
13
|
+
|
|
14
|
+
import mapnik from '../../../plugins/mapnik/funcs/mapnik.js';
|
|
15
|
+
|
|
16
|
+
const { RenderTile } = mapnik();
|
|
17
|
+
|
|
18
|
+
const meta = !!config?.mapnik?.meta;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Формування растрового tile cartoCss
|
|
22
|
+
*
|
|
23
|
+
* @method GET
|
|
24
|
+
* @alias rtile
|
|
25
|
+
* @param {String} bbox - bbox
|
|
26
|
+
* @param {Number} height - висота по координатам
|
|
27
|
+
* @param {Number} width - ширина по координатам
|
|
28
|
+
* @param {String} data - стилізація
|
|
29
|
+
* @param {String} lang - мова
|
|
30
|
+
* @param {String} z - координата z
|
|
31
|
+
* @param {String} x - координата y
|
|
32
|
+
* @param {String} y - координата x
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
export default async function gisRtile({
|
|
36
|
+
id, z, y, x, debug, nocache, nottl, uid,
|
|
37
|
+
}, pg = pgClients.client) {
|
|
38
|
+
if (!RenderTile) {
|
|
39
|
+
throw BadRequestError('mapnik server address needed');
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (!id) {
|
|
43
|
+
throw BadRequestError('not enough params: id');
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (!x || !y || !z) {
|
|
47
|
+
throw BadRequestError('not enough params: xyz');
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const decodedPath = Buffer.from(id, 'base64url').toString('utf-8');
|
|
51
|
+
|
|
52
|
+
const data = pg.pk?.['gis.rasters']
|
|
53
|
+
? 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' })
|
|
54
|
+
.then(r => r.rows?.[0] || {})
|
|
55
|
+
: {};
|
|
56
|
+
|
|
57
|
+
const carto = pg.pk?.['gis.cartocss']
|
|
58
|
+
? await pg.queryCache('select cartocss_id, source_path, is_public, is_static from gis.cartocss where cartocss_id=$1::text', { args: [id], table: 'gis.cartocss' }).then(r => r.rows?.[0] || {})
|
|
59
|
+
: {};
|
|
60
|
+
|
|
61
|
+
if (carto.cartocss_id) {
|
|
62
|
+
Object.assign(data, {
|
|
63
|
+
id: carto.cartocss_id,
|
|
64
|
+
source_path: carto.source_path,
|
|
65
|
+
is_public: carto.is_public,
|
|
66
|
+
is_static: carto.is_static,
|
|
67
|
+
type: 'css',
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (!uid && !config.local && data.is_public === false && process.env.NODE_ENV !== 'test' && !process.env.VITEST) {
|
|
72
|
+
throw ForbiddenError('access restricted');
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (!data.id && data.type !== 'css') {
|
|
76
|
+
Object.assign(data, { source_path: decodedPath });
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (!data.source_path && data.type !== 'css') {
|
|
80
|
+
throw NotFoundError('raster / cartocss not found');
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const bbox = mercator.bbox(y, x, z, false, '900913');
|
|
84
|
+
|
|
85
|
+
const ttl = (nocache ? '0' : null)
|
|
86
|
+
|| (data.type === 'css' && !data.is_static ? '1w' : null);
|
|
87
|
+
|
|
88
|
+
const md5 = data.source_path
|
|
89
|
+
? createHash('md5').update(data.source_path).digest('hex')
|
|
90
|
+
: undefined;
|
|
91
|
+
const base64 = data.source_path
|
|
92
|
+
? Buffer.from(data.source_path).toString('base64url')
|
|
93
|
+
: undefined;
|
|
94
|
+
|
|
95
|
+
const getParams = () => {
|
|
96
|
+
if (data.type === 'css' && data.source_path) {
|
|
97
|
+
return { name: path.posix.join('vector', config.mapnik?.folder || '', data.source_path) };
|
|
98
|
+
}
|
|
99
|
+
if (data.type === 'css') {
|
|
100
|
+
return { name: path.posix.join('xml', config.mapnik?.folder || '', id) };
|
|
101
|
+
}
|
|
102
|
+
return { path: path.posix.join('raster', config.mapnik?.folder || '', data.source_path) };
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
const { path: rpath, name } = getParams();
|
|
106
|
+
|
|
107
|
+
const param = {
|
|
108
|
+
path: rpath, // for rasters only
|
|
109
|
+
name, // required for cartocss
|
|
110
|
+
width: 256,
|
|
111
|
+
bbox,
|
|
112
|
+
ttl,
|
|
113
|
+
format: 'webp',
|
|
114
|
+
meta,
|
|
115
|
+
base64: false,
|
|
116
|
+
debug,
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
const result = await RenderTile(param);
|
|
120
|
+
|
|
121
|
+
if (result.err) {
|
|
122
|
+
logger.file('rtile/error', {
|
|
123
|
+
error: result.err, x, y, z, id: data.id, type: data.type,
|
|
124
|
+
});
|
|
125
|
+
throw new Error(result.err);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (meta) {
|
|
129
|
+
const accelPath = result.tile_path?.startsWith('/') ? result.tile_path : `/${result.tile_path}`;
|
|
130
|
+
const metaHeaders = {
|
|
131
|
+
'Content-Type': 'image/webp',
|
|
132
|
+
'Cache-Control': nocache || nottl ? 'no-store, no-cache, must-revalidate' : 'public, max-age=2592000',
|
|
133
|
+
'X-Accel-Redirect': accelPath,
|
|
134
|
+
};
|
|
135
|
+
if (debug) {
|
|
136
|
+
return {
|
|
137
|
+
headers: metaHeaders,
|
|
138
|
+
base64: result.base64,
|
|
139
|
+
z,
|
|
140
|
+
x,
|
|
141
|
+
y,
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
return { headers: metaHeaders, code: 204 };
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
if (debug) {
|
|
148
|
+
return {
|
|
149
|
+
...result,
|
|
150
|
+
name,
|
|
151
|
+
path: rpath,
|
|
152
|
+
ttl,
|
|
153
|
+
md5_path: md5,
|
|
154
|
+
base64_path: base64,
|
|
155
|
+
raster: !!data.id,
|
|
156
|
+
carto: data.type === 'css',
|
|
157
|
+
is_static: data.type === 'css' ? data.is_static : true,
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const buffer = result.data || Buffer.from(result.base64, 'base64');
|
|
162
|
+
|
|
163
|
+
return { headers: { 'Content-Type': 'image/webp', 'Cache-Control': nocache || nottl ? 'no-store, no-cache, must-revalidate' : 'public, max-age=2592000' }, data: buffer };
|
|
164
|
+
}
|
|
@@ -1,152 +1,152 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
|
-
import { ListObjectsV2Command } from '@aws-sdk/client-s3';
|
|
3
|
-
|
|
4
|
-
/* eslint-disable no-await-in-loop */
|
|
5
|
-
import {
|
|
6
|
-
config, isFileExists, logger, pgClients, downloadFile, s3Client,
|
|
7
|
-
} from '@opengis/fastify-table/utils.js';
|
|
8
|
-
|
|
9
|
-
import { BadRequestError, NotFoundError, NotImplementedError } from '@opengis/fastify-table/errors.js';
|
|
10
|
-
|
|
11
|
-
import mapnik from '../../../plugins/mapnik/funcs/mapnik.js';
|
|
12
|
-
|
|
13
|
-
const { UploadRaster, GetRasterStatus } = mapnik();
|
|
14
|
-
|
|
15
|
-
const CHUNK_SIZE = 1024 * 1024; // 1 MB per chunk
|
|
16
|
-
|
|
17
|
-
function sequence(files, data, fn) {
|
|
18
|
-
return files.reduce(
|
|
19
|
-
(promise, relpath) => promise.then(() => fn({
|
|
20
|
-
...data,
|
|
21
|
-
relpath, // allow upload multiple to one directory for vrt
|
|
22
|
-
})),
|
|
23
|
-
Promise.resolve(),
|
|
24
|
-
);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
async function uploadRasterFile({
|
|
28
|
-
id, prefix, relpath: relpathOriginal, callback = () => { },
|
|
29
|
-
}) {
|
|
30
|
-
const metadata = await isFileExists(relpathOriginal);
|
|
31
|
-
const relpath = ['raster', config.mapnik?.folder || '', relpathOriginal.replace(/\/\//, '/').replace(config.folder, '')].join('/');
|
|
32
|
-
|
|
33
|
-
let offset = 0;
|
|
34
|
-
|
|
35
|
-
try {
|
|
36
|
-
const uploadStatus = await GetRasterStatus({ path: relpath, md5: true });
|
|
37
|
-
|
|
38
|
-
if (uploadStatus.finished) {
|
|
39
|
-
callback(`Already uploaded: ${relpath}`);
|
|
40
|
-
return { message: 'already uploaded', status: 200 };
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
if (!metadata || !metadata.ContentLength) {
|
|
44
|
-
callback(`File not found at s3: ${relpath}`);
|
|
45
|
-
return { error: `File not found at s3: ${relpath}`, code: 404 };
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
offset = uploadStatus.exists ? +uploadStatus.size : 0;
|
|
49
|
-
|
|
50
|
-
if (offset === metadata.ContentLength) {
|
|
51
|
-
callback(`Already uploaded: ${relpath}`);
|
|
52
|
-
return { message: 'already uploaded', status: 200 };
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
while (offset < metadata.ContentLength) {
|
|
56
|
-
const end = Math.min(offset + CHUNK_SIZE - 1, metadata.ContentLength - 1);
|
|
57
|
-
const Range = `bytes=${offset}-${end}`;
|
|
58
|
-
|
|
59
|
-
callback(`Uploading chunk ${(end / 1024 / 1024).toFixed(0)}/${(metadata.ContentLength / 1024 / 1024).toFixed(0)} MB...`);
|
|
60
|
-
|
|
61
|
-
const chunk = await downloadFile(relpathOriginal, { Range, fallback: false });
|
|
62
|
-
// const { Body: chunk } = await s3Client.send(new GetObjectCommand({ Bucket, Key, Range }));
|
|
63
|
-
const bufferPart = chunk ? await chunk.transformToByteArray() : [];
|
|
64
|
-
|
|
65
|
-
if (!bufferPart.length) {
|
|
66
|
-
callback(`Server error: file not found / zero bytes: ${relpath}`);
|
|
67
|
-
break;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const result = await UploadRaster({
|
|
71
|
-
path: relpath,
|
|
72
|
-
filesize: metadata.ContentLength,
|
|
73
|
-
data: bufferPart,
|
|
74
|
-
chunked: true,
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
if (result.finished) {
|
|
78
|
-
callback(`Upload completed: ${relpath}`);
|
|
79
|
-
break;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
if (!result.uploaded) {
|
|
83
|
-
callback(`Chunked upload error: ${relpath}`);
|
|
84
|
-
break;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
offset = +result.uploaded;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
return null;
|
|
91
|
-
}
|
|
92
|
-
catch (err) {
|
|
93
|
-
logger.file('mapnik/upload/error', { error: err.toString(), stack: err.stack });
|
|
94
|
-
callback(config.local ? err.toString() : `Upload error: ${relpath}`);
|
|
95
|
-
return null;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
export default async function uploadRaster({
|
|
100
|
-
id, callback = () => { },
|
|
101
|
-
}, pg = pgClients.client) {
|
|
102
|
-
if (!UploadRaster || !GetRasterStatus) {
|
|
103
|
-
throw NotImplementedError('mapnik server address needed');
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
if (!id) {
|
|
107
|
-
throw BadRequestError('not enough params: id');
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
const data = pg.pk?.['gis.rasters']
|
|
111
|
-
? await pg.query('select raster_id as id, source_path from gis.rasters where raster_id=$1::text', [id])
|
|
112
|
-
.then(r => r.rows?.[0])
|
|
113
|
-
: null;
|
|
114
|
-
|
|
115
|
-
if (!data?.id) {
|
|
116
|
-
throw NotFoundError('raster not found');
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
if (!data.source_path) {
|
|
120
|
-
throw BadRequestError('raster source_path not set');
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
const prefix = '/map/raster';
|
|
124
|
-
const relpath = `${prefix}/${data.source_path}`;
|
|
125
|
-
|
|
126
|
-
if (!path.extname(relpath)) {
|
|
127
|
-
const metadata = await s3Client.send(new ListObjectsV2Command({
|
|
128
|
-
Bucket: config.s3?.containerName || 'work',
|
|
129
|
-
Prefix: path.join(config.folder, relpath).replace(/\\/g, '/'),
|
|
130
|
-
}));
|
|
131
|
-
if (!metadata.Contents?.length) {
|
|
132
|
-
throw NotFoundError('invalid: raster source_path: not found / empty directory');
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
// list rasters, skip preview subdir content, skip folders from s3 directory name of which only starts with same characters, but does not exactly match
|
|
136
|
-
const files = metadata.Contents.map(file => file.Key).filter((file) => path.basename(path.dirname(file)) === path.basename(relpath) && !path.basename(path.dirname(file)).startsWith('preview') && path.extname(file).toLowerCase() === '.tif');
|
|
137
|
-
|
|
138
|
-
if (!files.length) {
|
|
139
|
-
throw BadRequestError('invalid: raster source_path: no raster files at directory');
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
await sequence(files, { id, prefix, callback }, uploadRasterFile);
|
|
143
|
-
return 'uploaded';
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
await uploadRasterFile({
|
|
148
|
-
id, prefix, callback, relpath: data.source_path,
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
return 'uploaded';
|
|
152
|
-
}
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { ListObjectsV2Command } from '@aws-sdk/client-s3';
|
|
3
|
+
|
|
4
|
+
/* eslint-disable no-await-in-loop */
|
|
5
|
+
import {
|
|
6
|
+
config, isFileExists, logger, pgClients, downloadFile, s3Client,
|
|
7
|
+
} from '@opengis/fastify-table/utils.js';
|
|
8
|
+
|
|
9
|
+
import { BadRequestError, NotFoundError, NotImplementedError } from '@opengis/fastify-table/errors.js';
|
|
10
|
+
|
|
11
|
+
import mapnik from '../../../plugins/mapnik/funcs/mapnik.js';
|
|
12
|
+
|
|
13
|
+
const { UploadRaster, GetRasterStatus } = mapnik();
|
|
14
|
+
|
|
15
|
+
const CHUNK_SIZE = 1024 * 1024; // 1 MB per chunk
|
|
16
|
+
|
|
17
|
+
function sequence(files, data, fn) {
|
|
18
|
+
return files.reduce(
|
|
19
|
+
(promise, relpath) => promise.then(() => fn({
|
|
20
|
+
...data,
|
|
21
|
+
relpath, // allow upload multiple to one directory for vrt
|
|
22
|
+
})),
|
|
23
|
+
Promise.resolve(),
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
async function uploadRasterFile({
|
|
28
|
+
id, prefix, relpath: relpathOriginal, callback = () => { },
|
|
29
|
+
}) {
|
|
30
|
+
const metadata = await isFileExists(relpathOriginal);
|
|
31
|
+
const relpath = ['raster', config.mapnik?.folder || '', relpathOriginal.replace(/\/\//, '/').replace(config.folder, '')].join('/');
|
|
32
|
+
|
|
33
|
+
let offset = 0;
|
|
34
|
+
|
|
35
|
+
try {
|
|
36
|
+
const uploadStatus = await GetRasterStatus({ path: relpath, md5: true });
|
|
37
|
+
|
|
38
|
+
if (uploadStatus.finished) {
|
|
39
|
+
callback(`Already uploaded: ${relpath}`);
|
|
40
|
+
return { message: 'already uploaded', status: 200 };
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (!metadata || !metadata.ContentLength) {
|
|
44
|
+
callback(`File not found at s3: ${relpath}`);
|
|
45
|
+
return { error: `File not found at s3: ${relpath}`, code: 404 };
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
offset = uploadStatus.exists ? +uploadStatus.size : 0;
|
|
49
|
+
|
|
50
|
+
if (offset === metadata.ContentLength) {
|
|
51
|
+
callback(`Already uploaded: ${relpath}`);
|
|
52
|
+
return { message: 'already uploaded', status: 200 };
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
while (offset < metadata.ContentLength) {
|
|
56
|
+
const end = Math.min(offset + CHUNK_SIZE - 1, metadata.ContentLength - 1);
|
|
57
|
+
const Range = `bytes=${offset}-${end}`;
|
|
58
|
+
|
|
59
|
+
callback(`Uploading chunk ${(end / 1024 / 1024).toFixed(0)}/${(metadata.ContentLength / 1024 / 1024).toFixed(0)} MB...`);
|
|
60
|
+
|
|
61
|
+
const chunk = await downloadFile(relpathOriginal, { Range, fallback: false });
|
|
62
|
+
// const { Body: chunk } = await s3Client.send(new GetObjectCommand({ Bucket, Key, Range }));
|
|
63
|
+
const bufferPart = chunk ? await chunk.transformToByteArray() : [];
|
|
64
|
+
|
|
65
|
+
if (!bufferPart.length) {
|
|
66
|
+
callback(`Server error: file not found / zero bytes: ${relpath}`);
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const result = await UploadRaster({
|
|
71
|
+
path: relpath,
|
|
72
|
+
filesize: metadata.ContentLength,
|
|
73
|
+
data: bufferPart,
|
|
74
|
+
chunked: true,
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
if (result.finished) {
|
|
78
|
+
callback(`Upload completed: ${relpath}`);
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (!result.uploaded) {
|
|
83
|
+
callback(`Chunked upload error: ${relpath}`);
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
offset = +result.uploaded;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
catch (err) {
|
|
93
|
+
logger.file('mapnik/upload/error', { error: err.toString(), stack: err.stack });
|
|
94
|
+
callback(config.local ? err.toString() : `Upload error: ${relpath}`);
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export default async function uploadRaster({
|
|
100
|
+
id, callback = () => { },
|
|
101
|
+
}, pg = pgClients.client) {
|
|
102
|
+
if (!UploadRaster || !GetRasterStatus) {
|
|
103
|
+
throw NotImplementedError('mapnik server address needed');
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (!id) {
|
|
107
|
+
throw BadRequestError('not enough params: id');
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const data = pg.pk?.['gis.rasters']
|
|
111
|
+
? await pg.query('select raster_id as id, source_path from gis.rasters where raster_id=$1::text', [id])
|
|
112
|
+
.then(r => r.rows?.[0])
|
|
113
|
+
: null;
|
|
114
|
+
|
|
115
|
+
if (!data?.id) {
|
|
116
|
+
throw NotFoundError('raster not found');
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if (!data.source_path) {
|
|
120
|
+
throw BadRequestError('raster source_path not set');
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const prefix = '/map/raster';
|
|
124
|
+
const relpath = `${prefix}/${data.source_path}`;
|
|
125
|
+
|
|
126
|
+
if (!path.extname(relpath)) {
|
|
127
|
+
const metadata = await s3Client.send(new ListObjectsV2Command({
|
|
128
|
+
Bucket: config.s3?.containerName || 'work',
|
|
129
|
+
Prefix: path.join(config.folder, relpath).replace(/\\/g, '/'),
|
|
130
|
+
}));
|
|
131
|
+
if (!metadata.Contents?.length) {
|
|
132
|
+
throw NotFoundError('invalid: raster source_path: not found / empty directory');
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// list rasters, skip preview subdir content, skip folders from s3 directory name of which only starts with same characters, but does not exactly match
|
|
136
|
+
const files = metadata.Contents.map(file => file.Key).filter((file) => path.basename(path.dirname(file)) === path.basename(relpath) && !path.basename(path.dirname(file)).startsWith('preview') && path.extname(file).toLowerCase() === '.tif');
|
|
137
|
+
|
|
138
|
+
if (!files.length) {
|
|
139
|
+
throw BadRequestError('invalid: raster source_path: no raster files at directory');
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
await sequence(files, { id, prefix, callback }, uploadRasterFile);
|
|
143
|
+
return 'uploaded';
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
await uploadRasterFile({
|
|
148
|
+
id, prefix, callback, relpath: data.source_path,
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
return 'uploaded';
|
|
152
|
+
}
|