fix(catalog): self-discover P5 model-list endpoint for unmapped backends

fetchVehicleList fell back to /extern/vehicle/modelfamilies for any backend
not in BACKEND_MODEL_PATH; p5fiat (Fiat) isn't mapped, so it returned 0
models and Fiat seeded nothing (0 catalog_vehicles on dev+prod). When the
primary path yields nothing, try the other known P5 listing endpoints and
use the first that returns models, logging which one worked so it can be
pinned. Only runs on the empty path → mapped backends unaffected.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-05 15:01:50 +03:00
parent 1fc4f7780c
commit d918869742

View File

@@ -2058,6 +2058,37 @@ export class PL24Service {
}
}
// Fallback: the primary modelPath returned nothing (e.g. p5fiat is not mapped
// in BACKEND_MODEL_PATH yet). Try the other known P5 listing endpoints so an
// unmapped backend self-discovers its model list instead of silently seeding 0.
// Only runs when the primary yields nothing → no impact on mapped backends.
const candidatePaths = [
"/extern/vehicle/modelfamilies",
"/extern/vehicle/models",
"/extern/vehicle/modelFamilies",
"/extern/vehicle/catalogs",
"/extern/vehicle/scope",
"/extern/vehicles/vehiclesOverview",
"/extern/model/categories",
].filter((p) => p !== modelPath);
for (const candidate of candidatePaths) {
try {
const cu = `${this.baseUrl}${catalogBase}${candidate}?lang=${this.language}&serviceName=${serviceName}`;
const cr = await fetch(cu, { method: "GET", headers, signal: AbortSignal.timeout(15000) });
if (!cr.ok) continue;
const cd = (await cr.json()) as Record<string, any>;
const cv = this.parseVehicleListResponse(cd, serviceName);
if (cv.length > 0) {
this.logger.log(
`fetchVehicleList: ${serviceName} discovered via ${candidate} (${cv.length} models) — pin BACKEND_MODEL_PATH["${backendKey}"]="${candidate}"`,
);
return cv;
}
} catch {
// try next candidate
}
}
this.logger.log(`No vehicle list available for ${serviceName} (HTTP ${response.status})`);
return [];
} catch (err) {