chiitiler 1.22.0 → 1.22.3

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 CHANGED
@@ -60,6 +60,7 @@ You're done. That same endpoint works as an XYZ tile source for Leaflet, MapLibr
60
60
  - **[PLATEAU VIEW](https://plateauview.mlit.go.jp/)** — Cesium.js imagery via `/tiles`
61
61
  - **[qgis-amazonlocationservice-plugin](https://github.com/dayjournal/qgis-amazonlocationservice-plugin)** — QGIS integration
62
62
  - **[Allmaps Latest](https://bsky.app/profile/latest.allmaps.org)** — Bluesky bot
63
+ - **[Kumoy](https://www.kumoy.io/)** - used for thumbnail image of designed maps
63
64
 
64
65
  ## HTTP API
65
66
 
@@ -107,7 +108,7 @@ const png = await getRenderedTileBuffer({
107
108
 
108
109
  Available renderers: `getRenderedTileBuffer`, `getRenderedClipBuffer`, `getRenderedCameraBuffer`, and their `*Stream` variants (`Sharp` instances for further piping).
109
110
 
110
- Outbound HTTP requests send a `User-Agent` identifying chiitiler by default; override it with `setUserAgent('my-app/1.0')` or the `CHIITILER_USER_AGENT` environment variable.
111
+ chiitiler doesn't override the `User-Agent` on outbound HTTP requests by default, so the runtime's default is used (Node sends `node`). Some tile providers (e.g. OpenStreetMap) require an identifying User-Agent — set one with `setUserAgent('my-app/1.0')` or the `CHIITILER_USER_AGENT` environment variable.
111
112
 
112
113
  ## Configuration
113
114
 
@@ -119,7 +120,7 @@ All options can be set via CLI flag or environment variable.
119
120
  | --- | --- | --- |
120
121
  | `--port <n>` | `CHIITILER_PORT` | `3000` |
121
122
  | `--debug` | `CHIITILER_DEBUG` | `false` |
122
- | `--user-agent <ua>` | `CHIITILER_USER_AGENT` | `chiitiler (+https://github.com/Kanahiro/chiitiler)` |
123
+ | `--user-agent <ua>` | `CHIITILER_USER_AGENT` | (none) |
123
124
  | — | `CHIITILER_PROCESSES` | `1` (set `0` for all CPUs) |
124
125
 
125
126
  ### Cache
@@ -1,4 +1,4 @@
1
- import sharp from 'sharp';
1
+ import { type Sharp } from 'sharp';
2
2
  import type { StyleSpecification } from '@maplibre/maplibre-gl-style-spec';
3
3
  import type { Cache } from '../cache/index.js';
4
4
  type GetRenderedTileOptions = {
@@ -13,7 +13,7 @@ type GetRenderedTileOptions = {
13
13
  quality: number;
14
14
  };
15
15
  type SupportedFormat = 'png' | 'jpeg' | 'jpg' | 'webp';
16
- declare function getRenderedTile({ stylejson, z, x, y, tileSize, cache, margin, ext, quality, }: GetRenderedTileOptions): Promise<sharp.Sharp>;
16
+ declare function getRenderedTile({ stylejson, z, x, y, tileSize, cache, margin, ext, quality, }: GetRenderedTileOptions): Promise<Sharp>;
17
17
  type GetRenderedClipOptions = {
18
18
  stylejson: string | StyleSpecification;
19
19
  bbox: [number, number, number, number];
@@ -22,7 +22,7 @@ type GetRenderedClipOptions = {
22
22
  ext: SupportedFormat;
23
23
  quality: number;
24
24
  };
25
- declare function getRenderedClip({ stylejson, bbox, size, cache, ext, quality, }: GetRenderedClipOptions): Promise<sharp.Sharp>;
25
+ declare function getRenderedClip({ stylejson, bbox, size, cache, ext, quality, }: GetRenderedClipOptions): Promise<Sharp>;
26
26
  type GetRenderedCameraOptions = {
27
27
  stylejson: string | StyleSpecification;
28
28
  cache: Cache;
@@ -35,5 +35,5 @@ type GetRenderedCameraOptions = {
35
35
  height: number;
36
36
  width: number;
37
37
  };
38
- declare function getRenderedCamera(options: GetRenderedCameraOptions): Promise<sharp.Sharp>;
38
+ declare function getRenderedCamera(options: GetRenderedCameraOptions): Promise<Sharp>;
39
39
  export { getRenderedTile, getRenderedClip, getRenderedCamera, type GetRenderedClipOptions, type GetRenderedTileOptions, type GetRenderedCameraOptions, type SupportedFormat, };
@@ -1,2 +1,2 @@
1
- declare function getFilesystemSource(uri: string): Promise<Buffer<ArrayBufferLike> | null>;
1
+ declare function getFilesystemSource(uri: string): Promise<Buffer | null>;
2
2
  export { getFilesystemSource };
package/dist/source/fs.js CHANGED
@@ -1,15 +1,25 @@
1
- import fs from 'fs';
2
- function getFilesystemSource(uri) {
3
- return new Promise((resolve, _) => {
4
- fs.readFile(uri.replace('file://', ''), (err, data) => {
5
- if (err) {
6
- console.error(`[ERROR]: ${err}`);
7
- resolve(null);
8
- }
9
- else {
10
- resolve(data);
11
- }
12
- });
13
- });
1
+ import fs from 'node:fs/promises';
2
+ async function getFilesystemSource(uri) {
3
+ const path = uri.replace('file://', '');
4
+ const data = await fs.readFile(path).catch(() => null);
5
+ if (data !== null)
6
+ return data;
7
+ // maplibre-gl-native percent-encodes {fontstack} in glyphs URLs
8
+ // (e.g. "Noto Sans Regular" -> "Noto%20Sans%20Regular"),
9
+ // so retry with the percent-decoded path
10
+ let decodedPath;
11
+ try {
12
+ decodedPath = decodeURIComponent(path);
13
+ }
14
+ catch {
15
+ decodedPath = path;
16
+ }
17
+ if (decodedPath !== path) {
18
+ const decodedData = await fs.readFile(decodedPath).catch(() => null);
19
+ if (decodedData !== null)
20
+ return decodedData;
21
+ }
22
+ console.error(`[ERROR]: failed to read ${path}`);
23
+ return null;
14
24
  }
15
25
  export { getFilesystemSource };
@@ -9,8 +9,9 @@ async function getHttpSource(uri, cache = noneCache()) {
9
9
  return val; // hit
10
10
  // miss
11
11
  try {
12
+ const userAgent = getUserAgent();
12
13
  const res = await fetch(uri, {
13
- headers: { 'User-Agent': getUserAgent() },
14
+ headers: userAgent ? { 'User-Agent': userAgent } : undefined,
14
15
  });
15
16
  if (!res.ok) {
16
17
  console.log(`failed to fetch ${uri}`);
@@ -83,7 +83,11 @@ async function getPmtilesSource(uri, cache = noneCache()) {
83
83
  if (val !== undefined)
84
84
  return val; // hit
85
85
  if (pmtiles === undefined) {
86
- const fetchSource = new FetchSource(pmtilesUri, new Headers({ 'User-Agent': getUserAgent() }));
86
+ const userAgent = getUserAgent();
87
+ const headers = new Headers();
88
+ if (userAgent)
89
+ headers.set('User-Agent', userAgent);
90
+ const fetchSource = new FetchSource(pmtilesUri, headers);
87
91
  pmtiles = new PMTiles(fetchSource);
88
92
  pmtilesCache.set(pmtilesUri, pmtiles);
89
93
  }
@@ -3,5 +3,9 @@
3
3
  * Takes precedence over the CHIITILER_USER_AGENT environment variable.
4
4
  */
5
5
  declare function setUserAgent(userAgent: string | undefined): void;
6
- declare function getUserAgent(): string;
6
+ /**
7
+ * Returns the configured User-Agent, or undefined when none is set (in which
8
+ * case no User-Agent header should be added).
9
+ */
10
+ declare function getUserAgent(): string | undefined;
7
11
  export { getUserAgent, setUserAgent };
@@ -1,7 +1,7 @@
1
1
  // User-Agent for all outbound HTTP requests (http(s):// and pmtiles://http(s)://).
2
- // Some tile providers (e.g. OpenStreetMap) reject requests without an
3
- // identifying User-Agent, so we always send one.
4
- const DEFAULT_USER_AGENT = 'chiitiler (+https://github.com/Kanahiro/chiitiler)';
2
+ // By default we don't override the User-Agent at all (the runtime's default is
3
+ // used). Set one explicitly via --user-agent, CHIITILER_USER_AGENT, or
4
+ // setUserAgent() — e.g. some tile providers (OpenStreetMap) require one.
5
5
  let overrideUserAgent;
6
6
  /**
7
7
  * Override the User-Agent sent with outbound HTTP requests.
@@ -10,9 +10,11 @@ let overrideUserAgent;
10
10
  function setUserAgent(userAgent) {
11
11
  overrideUserAgent = userAgent;
12
12
  }
13
+ /**
14
+ * Returns the configured User-Agent, or undefined when none is set (in which
15
+ * case no User-Agent header should be added).
16
+ */
13
17
  function getUserAgent() {
14
- return (overrideUserAgent ??
15
- process.env.CHIITILER_USER_AGENT ??
16
- DEFAULT_USER_AGENT);
18
+ return overrideUserAgent ?? process.env.CHIITILER_USER_AGENT;
17
19
  }
18
20
  export { getUserAgent, setUserAgent };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "chiitiler",
4
- "version": "1.22.0",
4
+ "version": "1.22.3",
5
5
  "description": "Tiny map rendering server for MapLibre Style Spec",
6
6
  "main": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",
@@ -50,6 +50,6 @@
50
50
  "lru-cache": "^11.3.5",
51
51
  "maplibre-gl": "^5.23.0",
52
52
  "pmtiles": "^4.4.1",
53
- "sharp": "^0.34.5"
53
+ "sharp": "^0.35.3"
54
54
  }
55
55
  }