Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions packages/config-loader/src/json/imagery.config.cache.ts
Original file line number Diff line number Diff line change
@@ -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);

Expand All @@ -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
Expand All @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/config/src/config/base.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 3 additions & 1 deletion packages/config/src/config/imagery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { z } from 'zod';

import { ConfigBase } from './base.js';

export const ConfigImageryVersion = 2;

/**
* Taken from tiff's SampleFormat
*
Expand Down Expand Up @@ -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(),
Expand Down
1 change: 1 addition & 0 deletions packages/config/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export {
ConfigImagery,
ConfigImageryOverview,
ConfigImageryV1,
ConfigImageryVersion,
ImageryBandDataType,
ImageryBandType,
ImageryDataType,
Expand Down
Loading