Skip to content

Commit

Permalink
fix(cli): Update the chunkd verison for the fix, and allow trailing s…
Browse files Browse the repository at this point in the history
…lash uri (#3140)

#### Motivation

Currently config bundle commend fails to bundle config file due to some
bugs.
- trialling slash inside the uri might cause the failure
- `fsa.source().head()` got a bug for reading macros urls.

#### Modification

- updated chunkd package version include the fixs.
- Allow both uri with or without trailing slash, so we can force the
trailling slash in the future.

#### Checklist

_If not applicable, provide explanation of why._

- [x] Tests updated
- [ ] Docs updated
- [ ] Issue linked in Title
  • Loading branch information
Wentao-Kuang authored Feb 22, 2024
1 parent 32c501c commit a0b3d9e
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 25 deletions.
42 changes: 21 additions & 21 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions packages/config-loader/src/json/__tests__/config.loader.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { ConfigProviderMemory } from '@basemaps/config';
import { fsa, FsMemory, SourceMemory, Tiff } from '@basemaps/shared';
import { getTiffTagSize, TiffTag } from '@cogeotiff/core';

import { matchUri } from '../json.config.js';
import { getImageryName, initConfigFromUrls } from '../tiff.config.js';

const simpleTiff = new URL('../../../../__tests__/static/rgba8_tiled.tiff', import.meta.url);
Expand Down Expand Up @@ -152,4 +153,19 @@ describe('config import', () => {
'05-ecan-banks-peninsula-original-9mjdj',
);
});

it('should match uris with trailing slashes or macros', () => {
assert(
matchUri(
's3://linz-basemaps/3857/ōtorohanga_urban_2021_0-1m_RGB/01FYWKATAEK2ZTJQ2PX44Y0XNT/',
's3://linz-basemaps/3857/%C5%8Dtorohanga_urban_2021_0-1m_RGB/01FYWKATAEK2ZTJQ2PX44Y0XNT/',
),
);
assert(
matchUri(
's3://linz-basemaps/3857/ōtorohanga_urban_2021_0-1m_RGB/01FYWKATAEK2ZTJQ2PX44Y0XNT/',
's3://linz-basemaps/3857/ōtorohanga_urban_2021_0-1m_RGB/01FYWKATAEK2ZTJQ2PX44Y0XNT',
),
);
});
});
9 changes: 8 additions & 1 deletion packages/config-loader/src/json/json.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ function isTiff(u: URL): boolean {
return filePath.endsWith('.tiff') || filePath.endsWith('.tif');
}

export function matchUri(a: string, b: string): boolean {
const UrlA = new URL(a.endsWith('/') ? a : a + '/');
const UrlB = new URL(b.endsWith('/') ? b : b + '/');
if (UrlA.href === UrlB.href) return true;
return false;
}

export function guessIdFromUri(uri: string): string | null {
const parts = uri.split('/');
const id = uri.endsWith('/') ? parts.at(-2) : parts.at(-1);
Expand Down Expand Up @@ -199,7 +206,7 @@ export class ConfigJson {
): string | undefined {
if (uri == null) return uri;
if (uri.startsWith(ConfigPrefix.Imagery)) return uri;
const record = imagery.find((f) => f.uri === uri); ///
const record = imagery.find((f) => matchUri(f.uri, uri)); ///
if (record == null) throw new Error('Unable to find imagery id for uri:' + uri);

if (record.title && record.title !== layer.title) {
Expand Down
2 changes: 1 addition & 1 deletion packages/lambda-tiler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@
"bundle": "./bundle.sh"
},
"devDependencies": {
"@chunkd/fs": "^11.2.0",
"@basemaps/attribution": "^7.0.0",
"@chunkd/fs": "^11.2.0",
"@types/aws-lambda": "^8.10.75",
"@types/pixelmatch": "^5.0.0",
"pretty-json-log": "^1.0.0"
Expand Down
4 changes: 2 additions & 2 deletions packages/shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
"@basemaps/geo": "^7.0.0",
"@basemaps/tiler": "^7.0.0",
"@chunkd/fs": "^11.2.0",
"@chunkd/fs-aws": "^11.2.1",
"@chunkd/middleware": "^11.0.1",
"@chunkd/fs-aws": "^11.2.2",
"@chunkd/middleware": "^11.1.0",
"@cogeotiff/core": "^9.0.3",
"@cotar/core": "^6.0.1",
"@linzjs/geojson": "^7.0.0",
Expand Down

0 comments on commit a0b3d9e

Please sign in to comment.