@opengis/gis 0.2.165 → 0.2.166
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
|
@@ -176,12 +176,14 @@ async function createIcon(options) {
|
|
|
176
176
|
return sharp(Buffer.from(svg)).png().toBuffer();
|
|
177
177
|
}
|
|
178
178
|
|
|
179
|
-
async function
|
|
179
|
+
async function getIcon(options, nocache = false) {
|
|
180
180
|
await iconDirectoryReady;
|
|
181
181
|
|
|
182
182
|
const iconPath = path.join(iconDirectory, options.filename);
|
|
183
|
-
|
|
184
|
-
|
|
183
|
+
if (!nocache) {
|
|
184
|
+
const cachedIcon = await readFileIfExists(iconPath);
|
|
185
|
+
if (cachedIcon) return cachedIcon;
|
|
186
|
+
}
|
|
185
187
|
|
|
186
188
|
const icon = await createIcon(options);
|
|
187
189
|
if (!icon) return null;
|
|
@@ -194,11 +196,12 @@ export default async function gisIconApi(req, reply) {
|
|
|
194
196
|
const options = parseIconFilename(req.params?.['*'] || '');
|
|
195
197
|
if (!options) return reply.status(400).send('invalid icon name');
|
|
196
198
|
|
|
197
|
-
const
|
|
199
|
+
const nocache = !!req.query?.nocache;
|
|
200
|
+
const image = await getIcon(options, nocache);
|
|
198
201
|
if (!image) return reply.status(404).send('icon not found');
|
|
199
202
|
|
|
200
203
|
return reply
|
|
201
204
|
.type(contentTypeByFormat[options.format])
|
|
202
|
-
.header('Cache-Control', 'public, max-age=31536000, immutable')
|
|
205
|
+
.header('Cache-Control', nocache ? 'no-cache' : 'public, max-age=31536000, immutable')
|
|
203
206
|
.send(image);
|
|
204
207
|
}
|
|
@@ -2,7 +2,15 @@ import { config } from '@opengis/fastify-table/utils.js';
|
|
|
2
2
|
|
|
3
3
|
import mapnik from '../../../plugins/mapnik/funcs/mapnik.js';
|
|
4
4
|
|
|
5
|
-
const { GetLogs } = mapnik();
|
|
5
|
+
const { GetLogs } = mapnik();
|
|
6
|
+
|
|
7
|
+
function sendTextOrJson(reply, contentType, payload) {
|
|
8
|
+
if (typeof payload === 'string' || Buffer.isBuffer(payload)) {
|
|
9
|
+
return reply.type(contentType).send(payload);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return reply.type('application/json').send(payload);
|
|
13
|
+
}
|
|
6
14
|
|
|
7
15
|
export default async function mapnikLogger({
|
|
8
16
|
params,
|
|
@@ -12,18 +20,21 @@ export default async function mapnikLogger({
|
|
|
12
20
|
}
|
|
13
21
|
|
|
14
22
|
const { data, links, err } = await GetLogs({ path: params['*'] });
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
23
|
+
if (err) {
|
|
24
|
+
return reply.status(400).send(err);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (links) {
|
|
28
|
+
if (typeof links !== 'string') {
|
|
29
|
+
return sendTextOrJson(reply, 'text/html; charset=UTF-8', links);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return reply.headers({
|
|
22
33
|
"Content-Type": "text/html; charset=UTF-8",
|
|
23
34
|
"Content-Security-Policy": "default-src 'none'",
|
|
24
35
|
"X-Content-Type-Options": "nosniff",
|
|
25
36
|
}).send(links.replace(/\/api\/gis-logger/g, '/logger-gis'));
|
|
26
37
|
}
|
|
27
38
|
|
|
28
|
-
return reply
|
|
29
|
-
}
|
|
39
|
+
return sendTextOrJson(reply, 'text/plain; charset=UTF-8', data);
|
|
40
|
+
}
|
|
@@ -9,9 +9,13 @@ import {
|
|
|
9
9
|
|
|
10
10
|
import mapnik from '../../../plugins/mapnik/funcs/mapnik.js';
|
|
11
11
|
|
|
12
|
-
const { RenderTile } = mapnik();
|
|
13
|
-
|
|
14
|
-
const mercator = new SphericalMercator({ size: 256 });
|
|
12
|
+
const { RenderTile } = mapnik();
|
|
13
|
+
|
|
14
|
+
const mercator = new SphericalMercator({ size: 256 });
|
|
15
|
+
|
|
16
|
+
function isTrue(value) {
|
|
17
|
+
return value === true || value === 'true' || value === '1';
|
|
18
|
+
}
|
|
15
19
|
|
|
16
20
|
/**
|
|
17
21
|
* Формування растрового tile cartoCss
|
|
@@ -28,14 +32,16 @@ const mercator = new SphericalMercator({ size: 256 });
|
|
|
28
32
|
* @param {String} y - координата x
|
|
29
33
|
*/
|
|
30
34
|
|
|
31
|
-
export default async function gisRtile({
|
|
32
|
-
pg = pgClients.client, params, query, user,
|
|
33
|
-
}, reply) {
|
|
35
|
+
export default async function gisRtile({
|
|
36
|
+
pg = pgClients.client, params, query, user,
|
|
37
|
+
}, reply) {
|
|
34
38
|
if (!RenderTile) {
|
|
35
39
|
return reply.status(400).send({ error: 'mapnik server address needed', code: 400 });
|
|
36
40
|
}
|
|
37
41
|
|
|
38
|
-
const { id, z, y } = params;
|
|
42
|
+
const { id, z, y } = params;
|
|
43
|
+
const nocache = isTrue(query.nocache);
|
|
44
|
+
const nottl = isTrue(query.nottl);
|
|
39
45
|
|
|
40
46
|
const x = params.x.split('.')[0] - 0;
|
|
41
47
|
|
|
@@ -85,8 +91,10 @@ export default async function gisRtile({
|
|
|
85
91
|
const meta = config?.mapnik?.meta ? true : false;
|
|
86
92
|
|
|
87
93
|
try {
|
|
88
|
-
|
|
89
|
-
|
|
94
|
+
// ttl: '0' tells the Mapnik service to skip its tile cache and render again.
|
|
95
|
+
const ttl = nocache
|
|
96
|
+
? '0'
|
|
97
|
+
: (data.type === 'css' && !data.is_static ? '1w' : null);
|
|
90
98
|
|
|
91
99
|
const md5 = data.source_path
|
|
92
100
|
? createHash('md5').update(data.source_path).digest('hex')
|
|
@@ -132,10 +140,18 @@ export default async function gisRtile({
|
|
|
132
140
|
const accelPath = result.tile_path?.startsWith('/') ? result.tile_path : `/${result.tile_path}`;
|
|
133
141
|
const metaHeaders = {
|
|
134
142
|
'Content-Type': 'image/webp',
|
|
135
|
-
'Cache-Control':
|
|
143
|
+
'Cache-Control': nocache || nottl ? 'no-store, no-cache, must-revalidate' : 'public, max-age=2592000',
|
|
136
144
|
'X-Accel-Redirect': accelPath,
|
|
137
145
|
};
|
|
138
|
-
if (query.debug)
|
|
146
|
+
if (query.debug) {
|
|
147
|
+
return reply.type('application/json').send({
|
|
148
|
+
...metaHeaders,
|
|
149
|
+
base64: result.base64,
|
|
150
|
+
z,
|
|
151
|
+
x,
|
|
152
|
+
y,
|
|
153
|
+
});
|
|
154
|
+
}
|
|
139
155
|
reply.headers(metaHeaders);
|
|
140
156
|
return reply.code(204).send();
|
|
141
157
|
}
|
|
@@ -156,7 +172,7 @@ export default async function gisRtile({
|
|
|
156
172
|
|
|
157
173
|
const buffer = result.data || Buffer.from(result.base64, 'base64');
|
|
158
174
|
|
|
159
|
-
return reply.headers({ 'Content-Type': 'image/webp', 'Cache-Control':
|
|
175
|
+
return reply.headers({ 'Content-Type': 'image/webp', 'Cache-Control': nocache || nottl ? 'no-store, no-cache, must-revalidate' : 'public, max-age=2592000' }).send(buffer);
|
|
160
176
|
}
|
|
161
177
|
catch (err) {
|
|
162
178
|
logger.file('rtile/error', {
|