chiitiler 1.12.6 → 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
@@ -264,6 +264,7 @@ const s3Cache = ChiitilerCache.s3Cache({
264
264
  region: 'ap-northeast-1',
265
265
  endpoint: null,
266
266
  });
267
+ // credentials are loaded from environment variables: AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY
267
268
 
268
269
  const tileBuf = await getRenderedTileBuffer({
269
270
  stylejson: 'https://example.com/style.json', // or StyleSpecification object
@@ -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';
@@ -39,24 +39,32 @@ class S3Source {
39
39
  getKey() {
40
40
  return `s3://${this.bucket}/${this.key}`;
41
41
  }
42
- async getBytes(offset, length) {
43
- const cmd = new GetObjectCommand({
44
- Bucket: this.bucket,
45
- Key: this.key,
46
- Range: `bytes=${offset}-${offset + length - 1}`,
47
- });
42
+ async getBytes(offset, length, signal, etag) {
43
+ let resp;
48
44
  try {
49
- const obj = await this.s3Client.send(cmd);
50
- if (obj.Body === undefined)
51
- return { data: Buffer.alloc(0).buffer };
52
- const buf = Buffer.from(await obj.Body.transformToByteArray());
53
- 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
+ }));
54
51
  }
55
52
  catch (e) {
56
- if (e.name !== 'NoSuchKey')
57
- console.log(e);
58
- 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;
59
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
+ };
60
68
  }
61
69
  }
62
70
  /**
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "chiitiler",
4
- "version": "1.12.6",
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",