fix(map-gateway): unlock warm layers and local station search
This commit is contained in:
@@ -63,12 +63,13 @@ function normalizeFeature(feature, generatedAt, index) {
|
||||
const identity = nativeId.match(/^(node|way|relation)\/([1-9]\d*)$/);
|
||||
if (!identity) throw new Error(`station_seed_feature_${index}_identity_invalid`);
|
||||
const attributes = compact({
|
||||
name: firstString(properties.name, properties["name:ru"], properties.official_name, properties.loc_name),
|
||||
name: firstString(properties["name:ru"], properties.name, properties.official_name, properties.loc_name),
|
||||
category,
|
||||
network: optionalString(properties.network),
|
||||
operator: optionalString(properties.operator),
|
||||
official_name: optionalString(properties.official_name),
|
||||
local_name: optionalString(properties.loc_name),
|
||||
alternate_names: alternateNames(properties),
|
||||
uic_ref: optionalString(properties.uic_ref),
|
||||
wheelchair: optionalString(properties.wheelchair),
|
||||
});
|
||||
@@ -101,6 +102,28 @@ function optionalString(value) {
|
||||
return normalized && normalized.length <= 256 ? normalized : undefined;
|
||||
}
|
||||
|
||||
function alternateNames(properties) {
|
||||
const primary = firstString(properties["name:ru"], properties.name, properties.official_name, properties.loc_name);
|
||||
const unique = new Map();
|
||||
for (const value of [
|
||||
properties.name,
|
||||
properties["name:ru"],
|
||||
properties["name:en"],
|
||||
properties.official_name,
|
||||
properties.loc_name,
|
||||
properties.short_name,
|
||||
properties.old_name,
|
||||
...String(properties.alt_name || "").split(";"),
|
||||
]) {
|
||||
const normalized = optionalString(value);
|
||||
if (!normalized || normalized.toLocaleLowerCase("ru") === primary?.toLocaleLowerCase("ru")) continue;
|
||||
const key = normalized.toLocaleLowerCase("ru");
|
||||
if (!unique.has(key)) unique.set(key, normalized);
|
||||
}
|
||||
const values = [...unique.values()].slice(0, 16);
|
||||
return values.length ? values : undefined;
|
||||
}
|
||||
|
||||
function compact(value) {
|
||||
return Object.fromEntries(Object.entries(value).filter(([, item]) => item !== undefined));
|
||||
}
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { createHash } from "node:crypto";
|
||||
import { once } from "node:events";
|
||||
import { mkdtemp, mkdir, rm, writeFile } from "node:fs/promises";
|
||||
import { createServer } from "node:net";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { dirname, join } from "node:path";
|
||||
import { spawn } from "node:child_process";
|
||||
|
||||
const root = await mkdtemp(join(tmpdir(), "nodedc-map-gateway-credential-smoke-"));
|
||||
@@ -13,7 +14,27 @@ let child;
|
||||
|
||||
try {
|
||||
await mkdir(join(cacheDir, "ion-endpoints"), { recursive: true });
|
||||
await writeFile(join(cacheDir, "index.json"), `${JSON.stringify({ version: 1, entries: {} })}\n`);
|
||||
const buildingsUrl = "https://assets.ion.cesium.com/us-east-1/asset_depot/96188/OpenStreetMap/CWT/2025-04-01/tileset.json?v=expired";
|
||||
const buildingsKey = createHash("sha256").update(buildingsUrl).digest("hex");
|
||||
const buildingsRelativePath = join("objects", buildingsKey.slice(0, 2), `${buildingsKey}.bin`);
|
||||
const buildingsBody = JSON.stringify({ asset: { version: "1.1" }, root: { geometricError: 0 } });
|
||||
await mkdir(dirname(join(cacheDir, buildingsRelativePath)), { recursive: true });
|
||||
await writeFile(join(cacheDir, buildingsRelativePath), buildingsBody);
|
||||
await writeFile(join(cacheDir, "index.json"), `${JSON.stringify({
|
||||
version: 1,
|
||||
entries: {
|
||||
[buildingsKey]: {
|
||||
key: buildingsKey,
|
||||
file: buildingsRelativePath,
|
||||
bytes: Buffer.byteLength(buildingsBody),
|
||||
contentType: "application/json",
|
||||
etag: null,
|
||||
savedAt: Date.now(),
|
||||
lastAccessAt: Date.now(),
|
||||
expiresAt: Date.now() - 1,
|
||||
},
|
||||
},
|
||||
})}\n`);
|
||||
await writeFile(join(cacheDir, "ion-endpoints", "1.json"), `${JSON.stringify({
|
||||
assetId: "1",
|
||||
type: "TERRAIN",
|
||||
@@ -38,7 +59,7 @@ try {
|
||||
await writeFile(join(cacheDir, "ion-endpoints", "96188.json"), `${JSON.stringify({
|
||||
assetId: "96188",
|
||||
type: "3DTILES",
|
||||
url: "https://assets.ion.cesium.com/us-east-1/asset_depot/96188/OpenStreetMap/CWT/2025-04-01/tileset.json?v=expired",
|
||||
url: buildingsUrl,
|
||||
accessToken: expiredBuildingsToken,
|
||||
attributions: [],
|
||||
savedAt: Date.now(),
|
||||
@@ -48,11 +69,13 @@ try {
|
||||
cwd: new URL("..", import.meta.url),
|
||||
env: {
|
||||
...process.env,
|
||||
NODE_ENV: "test",
|
||||
PORT: String(port),
|
||||
MAP_CACHE_DIR: cacheDir,
|
||||
MAP_GATEWAY_ALLOW_ANONYMOUS: "true",
|
||||
MAP_CACHE_MODE: "readwrite",
|
||||
CESIUM_ION_TOKEN: "",
|
||||
CESIUM_ION_TOKEN: "configured-master-token",
|
||||
CESIUM_ION_API_BASE_URL: `http://127.0.0.1:${port}/`,
|
||||
CESIUM_ION_ASSET_ALLOWLIST: "1,2,96188",
|
||||
MAP_GATEWAY_UPSTREAM_ALLOWLIST: "assets.ion.cesium.com,dev.virtualearth.net",
|
||||
},
|
||||
@@ -73,10 +96,16 @@ try {
|
||||
}
|
||||
const expired = await fetch(`http://127.0.0.1:${port}/api/map/ion/assets/96188/endpoint`);
|
||||
const expiredRaw = await expired.text();
|
||||
assert.equal(expired.status, 503);
|
||||
assert.equal(expired.status, 200);
|
||||
assert.equal(expiredRaw.includes(expiredBuildingsToken), false);
|
||||
assert.equal(expiredRaw.includes("accessToken"), false);
|
||||
console.log("ok: endpoint responses contain no credentials and a known-expired Ion JWT is never served");
|
||||
assert.equal(JSON.parse(expiredRaw).cache, "ion-endpoint-stale-upstream-error");
|
||||
|
||||
const cachedRoot = await fetch(`http://127.0.0.1:${port}/api/map/cache?url=${encodeURIComponent(`${buildingsUrl}&nodedc_client_revision=2`)}`);
|
||||
assert.equal(cachedRoot.status, 200);
|
||||
assert.equal(cachedRoot.headers.get("x-nodedc-map-cache"), "live-cache-stale");
|
||||
assert.deepEqual(await cachedRoot.json(), JSON.parse(buildingsBody));
|
||||
console.log("ok: endpoint responses contain no credentials and expired metadata still unlocks warm cache during upstream outage");
|
||||
} finally {
|
||||
if (child && !child.killed) {
|
||||
child.kill("SIGTERM");
|
||||
|
||||
Reference in New Issue
Block a user