@mapwhit/tileserver 3.6.0 → 3.7.0

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.
Files changed (2) hide show
  1. package/lib/tiles.js +8 -6
  2. package/package.json +1 -2
package/lib/tiles.js CHANGED
@@ -1,13 +1,12 @@
1
1
  const fs = require('node:fs');
2
2
  const path = require('node:path');
3
- const zlib = require('node:zlib');
3
+ const { createHash } = require('node:crypto');
4
4
 
5
5
  const fresh = require('fresh');
6
6
  const Router = require('@pirxpilot/router');
7
7
  const mbtiles = require('@mapwhit/mbtiles');
8
8
 
9
9
  const { fixTileJSONCenter, getTileUrls } = require('./utils');
10
- const etag = require('etag');
11
10
 
12
11
  module.exports = serveData;
13
12
 
@@ -66,10 +65,7 @@ function serveData(mountPath, options, item) {
66
65
  if (tile == null) {
67
66
  return next(404);
68
67
  }
69
- if (options.removeETag) {
70
- delete headers['ETag']; // do not trust the tile ETag -- regenerate
71
- }
72
- if (!options.noETag && !headers['ETag']) {
68
+ if (!options.noETag) {
73
69
  headers['ETag'] = etag(tile);
74
70
  }
75
71
  headers['Content-Type'] ??= 'application/x-protobuf';
@@ -125,3 +121,9 @@ function initZoomRanges(min, max) {
125
121
  }
126
122
  return ranges;
127
123
  }
124
+
125
+ function etag(buffer) {
126
+ const hash = createHash('sha1').update(buffer).digest('base64').slice(0, -1);
127
+ const len = buffer.byteLength.toString(16);
128
+ return `"${len}-${hash}"`;
129
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mapwhit/tileserver",
3
- "version": "3.6.0",
3
+ "version": "3.7.0",
4
4
  "description": "Map tile server for JSON GL styles - serving vector tiles",
5
5
  "bin": {
6
6
  "tileserver": "bin/tileserver",
@@ -22,7 +22,6 @@
22
22
  "@mapwhit/mbtiles": "^1.0.1",
23
23
  "@pirxpilot/connect": "~4",
24
24
  "@pirxpilot/router": "~1",
25
- "etag": "~1",
26
25
  "fresh": "~2",
27
26
  "ms": "~2",
28
27
  "rc": "~1",