diff --git a/packages/config-loader/src/json/imagery.config.cache.ts b/packages/config-loader/src/json/imagery.config.cache.ts index 56f0e7b89..2e8986b8e 100644 --- a/packages/config-loader/src/json/imagery.config.cache.ts +++ b/packages/config-loader/src/json/imagery.config.cache.ts @@ -1,13 +1,13 @@ import { promisify } from 'node:util'; import { gzip } from 'node:zlib'; -import { sha256base58 } from '@basemaps/config'; +import { ConfigImageryVersion, sha256base58 } from '@basemaps/config'; import { fsa, LogType } from '@basemaps/shared'; import { FileInfo } from '@chunkd/fs'; import { ConfigImageryTiff } from './tiff.config.js'; -export const ConfigCacheVersion = `V1`; // TODO this could just be the config packageJson ? +export const ConfigCacheVersion = `V1.` + ConfigImageryVersion; // TODO this could just be the config packageJson ? const gzipPromise = promisify(gzip); @@ -17,7 +17,7 @@ const gzipPromise = promisify(gzip); * @example * ``` * YYYY-MM/proto_hostname/hashKey.json.gz - * 2034-04/s3_linz-imagery/Ci4chK59behxsGZq6TaUde5DoVb7jTxhyaZ44j4wBnCb.json.gz + * 2034-04/s3/linz-imagery/Ci4chK59behxsGZq6TaUde5DoVb7jTxhyaZ44j4wBnCb.json.gz * ``` * * @param sourceFiles @@ -26,13 +26,17 @@ const gzipPromise = promisify(gzip); * @returns a unique config location */ function getCacheKey(sourceFiles: FileInfo[], cacheLocation: URL): URL { + // All source hosts used for the config + const sourceHosts = new Set(sourceFiles.map((m) => m.url.hostname)); + const hostNames = [...sourceHosts.values()]; + hostNames.sort(); + const configKey = ConfigCacheVersion + sourceFiles.map((m) => `${m.url.href}::${m.size}::${m.lastModified}`).join('\n'); - // create a config hash based on the YYYY-MM/proto_hostname/hashKey.json.gz - const datePart = new Date().toISOString().slice(0, 7); + // create a config hash based on the /proto/hostname/hashKey.json.gz const protoPart = cacheLocation.protocol.replace(':', ''); // convert file: into file - const configKeyHash = [datePart, `${protoPart}_${sha256base58(configKey)}_.json.gz`].join('/'); + const configKeyHash = [protoPart, hostNames.join('__'), `${sha256base58(configKey)}_.json.gz`].join('/'); return new URL(configKeyHash, cacheLocation); } diff --git a/packages/config/src/config/base.ts b/packages/config/src/config/base.ts index c0e5099e0..59702ad4b 100644 --- a/packages/config/src/config/base.ts +++ b/packages/config/src/config/base.ts @@ -1,6 +1,6 @@ import { z } from 'zod'; -import { ConfigId } from '../index.js'; +import { ConfigId } from '../base.config.js'; /** * Ensure a ID is prefixed with one of the configuration objects diff --git a/packages/config/src/config/imagery.ts b/packages/config/src/config/imagery.ts index 4b2f7c427..44b631546 100644 --- a/packages/config/src/config/imagery.ts +++ b/packages/config/src/config/imagery.ts @@ -3,6 +3,8 @@ import { z } from 'zod'; import { ConfigBase } from './base.js'; +export const ConfigImageryVersion = 2; + /** * Taken from tiff's SampleFormat * @@ -212,7 +214,7 @@ export const ConfigImageryV1Parser = ConfigImageryBase.extend({ * Version two of imagery configuration adds more information about the bands found inside the imagery */ export const ConfigImageryV2Parser = ConfigImageryBase.extend({ - v: z.literal(2), + v: z.literal(ConfigImageryVersion), /** Human friendly title for the imagery */ title: z.string(), diff --git a/packages/config/src/index.ts b/packages/config/src/index.ts index 5132c0647..1e892057c 100644 --- a/packages/config/src/index.ts +++ b/packages/config/src/index.ts @@ -14,6 +14,7 @@ export { ConfigImagery, ConfigImageryOverview, ConfigImageryV1, + ConfigImageryVersion, ImageryBandDataType, ImageryBandType, ImageryDataType,