chiitiler 1.12.5 → 1.12.7

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
@@ -102,6 +102,7 @@ you can pass server options via environment variables
102
102
  | CHIITILER_S3CACHE_BUCKET | | s3cache bucket name |
103
103
  | CHIITILER_S3_REGION | us-east1 | s3 bucket region for caching/fetching |
104
104
  | CHIITILER_S3_ENDPOINT | | s3 endpoint for caching/fetching |
105
+ | CHIITILER_S3_FORCE_PATH_STYLE | false | force path style for s3, needed for minio |
105
106
 
106
107
  ### Local
107
108
 
@@ -263,6 +264,7 @@ const s3Cache = ChiitilerCache.s3Cache({
263
264
  region: 'ap-northeast-1',
264
265
  endpoint: null,
265
266
  });
267
+ // credentials are loaded from environment variables: AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY
266
268
 
267
269
  const tileBuf = await getRenderedTileBuffer({
268
270
  stylejson: 'https://example.com/style.json', // or StyleSpecification object
@@ -2,7 +2,8 @@ import { type Cache } from './index.js';
2
2
  type S3CacheOptions = {
3
3
  bucket: string;
4
4
  region: string;
5
- endpoint: string | null;
5
+ endpoint?: string;
6
+ forcePathStyle?: boolean;
6
7
  };
7
8
  declare function s3Cache(options: S3CacheOptions): Cache;
8
9
  export { s3Cache };
package/dist/cache/s3.js CHANGED
@@ -4,6 +4,7 @@ function s3Cache(options) {
4
4
  const s3Client = getS3Client({
5
5
  region: options.region,
6
6
  endpoint: options.endpoint,
7
+ forcePathStyle: options.forcePathStyle,
7
8
  });
8
9
  return {
9
10
  name: 's3',
package/dist/cli.js CHANGED
@@ -19,6 +19,7 @@ function parseCacheStrategy(method, options) {
19
19
  bucket: options.s3CacheBucket,
20
20
  region: options.s3Region,
21
21
  endpoint: options.s3Endpoint,
22
+ forcePathStyle: options.s3ForcePathStyle,
22
23
  });
23
24
  // command-line is not specified -> try to read from env
24
25
  const cacheEnv = process.env.CHIITILER_CACHE_METHOD;
@@ -36,7 +37,8 @@ function parseCacheStrategy(method, options) {
36
37
  return caches.s3Cache({
37
38
  bucket: process.env.CHIITILER_S3CACHE_BUCKET ?? '',
38
39
  region: process.env.CHIITILER_S3_REGION ?? 'us-east1',
39
- endpoint: process.env.CHIITILER_S3_ENDPOINT ?? null,
40
+ endpoint: process.env.CHIITILER_S3_ENDPOINT,
41
+ forcePathStyle: process.env.CHIITILER_S3_FORCE_PATH_STYLE === 'true',
40
42
  });
41
43
  // undefined or invalid
42
44
  return caches.noneCache();
@@ -74,6 +76,7 @@ export function createProgram() {
74
76
  .option('-s3r --s3-region <region-name>', 's3 bucket region for get/put', 'us-east1')
75
77
  .option('-s3b --s3-cache-bucket <bucket-name>', 's3 cache bucket name', '')
76
78
  .option('-s3e --s3-endpoint <url>', 's3 endpoint url', '')
79
+ .option('-3p --s3-force-path-style', 's3 force path style', '')
77
80
  .option('-p --port <port>', 'port number')
78
81
  .option('-D --debug', 'debug mode')
79
82
  .action((options) => {
@@ -85,6 +88,7 @@ export function createProgram() {
85
88
  s3CacheBucket: options.s3CacheBucket,
86
89
  s3Region: options.s3Region,
87
90
  s3Endpoint: options.s3Endpoint,
91
+ s3ForcePathStyle: options.s3ForcePathStyle === 'true',
88
92
  }),
89
93
  port: parsePort(options.port),
90
94
  debug: parseDebug(options.debug),
package/dist/s3.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { S3Client } from '@aws-sdk/client-s3';
2
- declare const getS3Client: ({ region, endpoint, }: {
2
+ declare const getS3Client: ({ region, endpoint, forcePathStyle, }: {
3
3
  region: string;
4
- endpoint: string | null;
4
+ endpoint?: string | undefined;
5
+ forcePathStyle?: boolean | undefined;
5
6
  }) => S3Client;
6
7
  export { getS3Client };
package/dist/s3.js CHANGED
@@ -1,23 +1,13 @@
1
1
  import { S3Client } from '@aws-sdk/client-s3';
2
2
  let s3Client; // singleton
3
- const getS3Client = function ({ region, endpoint, }) {
3
+ const getS3Client = function ({ region, endpoint, forcePathStyle, }) {
4
4
  if (s3Client !== undefined)
5
5
  return s3Client;
6
- let s3ClientConfig = {
6
+ const s3ClientConfig = {
7
7
  region,
8
- endpoint: endpoint ?? undefined,
8
+ endpoint,
9
+ forcePathStyle,
9
10
  };
10
- if (process.env.NODE_ENV === 'development') {
11
- s3ClientConfig = {
12
- region,
13
- credentials: {
14
- accessKeyId: 'minioadmin',
15
- secretAccessKey: 'minioadmin',
16
- },
17
- forcePathStyle: true,
18
- endpoint: 'http://minio:9000',
19
- };
20
- }
21
11
  s3Client = new S3Client(s3ClientConfig);
22
12
  return s3Client;
23
13
  };
@@ -1,6 +1,6 @@
1
1
  import * as fs from 'fs';
2
2
  import { PMTiles } from 'pmtiles';
3
- import { GetObjectCommand } from '@aws-sdk/client-s3';
3
+ import { GetObjectCommand, } from '@aws-sdk/client-s3';
4
4
  import { LRUCache } from 'lru-cache';
5
5
  import { getS3Client } from '../s3.js';
6
6
  import { noneCache } from '../cache/index.js';
@@ -32,30 +32,39 @@ class S3Source {
32
32
  this.key = key;
33
33
  this.s3Client = getS3Client({
34
34
  region: process.env.CHIITILER_S3_REGION ?? 'us-east1',
35
- endpoint: process.env.CHIITILER_S3_ENDPOINT ?? null,
35
+ endpoint: process.env.CHIITILER_S3_ENDPOINT,
36
+ forcePathStyle: process.env.CHIITILER_S3_FORCE_PATH_STYLE === 'true',
36
37
  });
37
38
  }
38
39
  getKey() {
39
40
  return `s3://${this.bucket}/${this.key}`;
40
41
  }
41
- async getBytes(offset, length) {
42
- const cmd = new GetObjectCommand({
43
- Bucket: this.bucket,
44
- Key: this.key,
45
- Range: `bytes=${offset}-${offset + length - 1}`,
46
- });
42
+ async getBytes(offset, length, signal, etag) {
43
+ let resp;
47
44
  try {
48
- const obj = await this.s3Client.send(cmd);
49
- if (obj.Body === undefined)
50
- return { data: Buffer.alloc(0).buffer };
51
- const buf = Buffer.from(await obj.Body.transformToByteArray());
52
- return { data: buf.buffer };
45
+ resp = await this.s3Client.send(new GetObjectCommand({
46
+ Bucket: this.bucket,
47
+ Key: this.key,
48
+ Range: 'bytes=' + offset + '-' + (offset + length - 1),
49
+ IfMatch: etag,
50
+ }));
53
51
  }
54
52
  catch (e) {
55
- if (e.name !== 'NoSuchKey')
56
- console.log(e);
57
- return { data: Buffer.alloc(0).buffer };
53
+ if (e instanceof Error &&
54
+ e.name === 'PreconditionFailed') {
55
+ throw new Error('etag mismatch');
56
+ }
57
+ throw e;
58
58
  }
59
+ const arr = await resp.Body?.transformToByteArray();
60
+ if (!arr)
61
+ throw Error('Failed to read S3 response body');
62
+ return {
63
+ data: arr.buffer,
64
+ etag: resp.ETag,
65
+ expires: resp.Expires?.toISOString(),
66
+ cacheControl: resp.CacheControl,
67
+ };
59
68
  }
60
69
  }
61
70
  /**
package/dist/source/s3.js CHANGED
@@ -3,7 +3,8 @@ import { getS3Client } from '../s3.js';
3
3
  async function getS3Source(uri) {
4
4
  const s3Client = getS3Client({
5
5
  region: process.env.CHIITILER_S3_REGION ?? 'us-east1',
6
- endpoint: process.env.CHIITILER_S3_ENDPOINT ?? null,
6
+ endpoint: process.env.CHIITILER_S3_ENDPOINT,
7
+ forcePathStyle: process.env.CHIITILER_S3_FORCE_PATH_STYLE === 'true',
7
8
  });
8
9
  const bucket = uri.replace('s3://', '').split('/')[0];
9
10
  const key = uri.replace(`s3://${bucket}/`, '');
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "chiitiler",
4
- "version": "1.12.5",
4
+ "version": "1.12.7",
5
5
  "description": "Tiny map rendering server for MapLibre Style Spec",
6
6
  "main": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",