commit 8adad25782ca388bc74af2aed2da0e3d18128e29
parent 9bdf438037c5dd3b68167766856475bc94157db7
Author: Katja (ctucx) <git@ctu.cx>
Date: Fri, 31 Jan 2025 21:42:16 +0100
parent 9bdf438037c5dd3b68167766856475bc94157db7
Author: Katja (ctucx) <git@ctu.cx>
Date: Fri, 31 Jan 2025 21:42:16 +0100
rename `hafas_client.js` to `hafasClient.js`
8 files changed, 56 insertions(+), 55 deletions(-)
diff --git a/src/app_functions.js b/src/app_functions.js @@ -6,7 +6,7 @@ import { showLoader, hideOverlay, showModal, showAlertModal } from './overlays.j import { languages } from './languages.js'; import { isEmptyObject, generateSlug, loyaltyCardToString, loyaltyCardFromString } from './helpers.js'; import { formatDateTime } from './formatters.js'; -import { getHafasClient, client } from './hafas_client.js'; +import { getHafasClient, client } from './hafasClient.js'; import { trainsearchToHafas, hafasToTrainsearch } from './refresh_token/index.js'; import { default as ds100 } from './ds100.json';
diff --git a/src/departuresView.js b/src/departuresView.js @@ -6,7 +6,7 @@ import { processLeg } from './app_functions.js'; import { formatDateTime, formatDuration, formatPrice } from './formatters.js'; import { showAlertModal, showLoader, hideOverlay, showModal } from './overlays.js'; import { go } from './router.js'; -import { getHafasClient, client } from './hafas_client.js'; +import { getHafasClient, client } from './hafasClient.js'; import { t } from './languages.js'; const departuresTemplate = (data, profile) => {
diff --git a/src/hafasClient.js b/src/hafasClient.js @@ -0,0 +1,50 @@ +import { createClient as createVendoClient } from "db-vendo-client"; +import { profile as dbnavProfile } from "db-vendo-client/p/dbnav/index.js"; + +const clients = {}; +let createHafasClient; + +export let client; + +export const getHafasClient = async profileName => { + if (!clients[profileName]) { + let profile; + switch(profileName) { + case "db": + clients[profileName] = createVendoClient(dbnavProfile, "trainsearch", {enrichStations: false}); + console.info("initialized vendo client"); + return clients[profileName]; + case "bvg": + const { profile: bvgProfile } = await import('hafas-client/p/bvg/index.js'); + profile = bvgProfile; + break; + case "nahsh": + const { profile: nahshProfile } = await import('hafas-client/p/nahsh/index.js'); + profile = nahshProfile; + break; + case "rmv": + const { profile: rmvProfile } = await import('hafas-client/p/rmv/index.js'); + profile = rmvProfile; + break; + case "vrn": + const { profile: vrnProfile } = await import('hafas-client/p/vrn/index.js'); + profile = vrnProfile; + break; + case "oebb": + const { profile: oebbProfile } = await import('hafas-client/p/oebb/index.js'); + profile = oebbProfile; + break; + default: + throw "Unknown profile name: " + profileName; + } + if (!createHafasClient) createHafasClient = (await import("hafas-client")).createClient; + clients[profileName] = createHafasClient(profile, "trainsearch"); + } + + console.info("initialized hafas client with profile " + profileName); + return clients[profileName]; +} + +export const initHafasClient = async profileName => { + client = await getHafasClient(profileName); +};
diff --git a/src/hafas_client.js b/src/hafas_client.js @@ -1,49 +0,0 @@ -const clients = {}; -let createHafasClient; -export let client; - -import { createClient as createVendoClient } from "db-vendo-client"; -import { profile as dbnavProfile } from "db-vendo-client/p/dbnav/index.js"; - -export const getHafasClient = async profileName => { - if (!clients[profileName]) { - let profile; - switch(profileName) { - case "db": - clients[profileName] = createVendoClient(dbnavProfile, "trainsearch", {enrichStations: false}); - console.info("initialized vendo client"); - return clients[profileName]; - case "bvg": - const { profile: bvgProfile } = await import('hafas-client/p/bvg/index.js'); - profile = bvgProfile; - break; - case "nahsh": - const { profile: nahshProfile } = await import('hafas-client/p/nahsh/index.js'); - profile = nahshProfile; - break; - case "rmv": - const { profile: rmvProfile } = await import('hafas-client/p/rmv/index.js'); - profile = rmvProfile; - break; - case "vrn": - const { profile: vrnProfile } = await import('hafas-client/p/vrn/index.js'); - profile = vrnProfile; - break; - case "oebb": - const { profile: oebbProfile } = await import('hafas-client/p/oebb/index.js'); - profile = oebbProfile; - break; - default: - throw "Unknown profile name: " + profileName; - } - if (!createHafasClient) createHafasClient = (await import("hafas-client")).createClient; - clients[profileName] = createHafasClient(profile, "trainsearch"); - } - - console.info("initialized hafas client with profile " + profileName); - return clients[profileName]; -} - -export const initHafasClient = async profileName => { - client = await getHafasClient(profileName); -};
diff --git a/src/main.js b/src/main.js @@ -3,7 +3,7 @@ import { ElementById } from './helpers.js'; import { showAlertModal, hideOverlay } from './overlays.js'; import { initSettings, settings } from './settings.js'; import { initDataStorage } from './dataStorage.js'; -import { initHafasClient } from './hafas_client.js'; +import { initHafasClient } from './hafasClient.js'; import { searchView } from './searchView.js'; import { journeysView } from './journeysView.js'; import { journeyView } from './journeyView.js';
diff --git a/src/searchView.js b/src/searchView.js @@ -8,7 +8,7 @@ import { go } from './router.js'; import { showAlertModal, showSelectModal, showLoader, hideOverlay} from './overlays.js'; import { t } from './languages.js'; import { showSettings } from './settingsView.js'; -import { client } from './hafas_client.js'; +import { client } from './hafasClient.js'; const viewState = { currDate: new Date(),
diff --git a/src/settingsView.js b/src/settingsView.js @@ -5,7 +5,7 @@ import { showModal, hideOverlay } from './overlays.js'; import { ElementById, hideElement, showElement } from './helpers.js'; import { t } from './languages.js'; import { searchView } from './searchView.js'; -import { initHafasClient } from './hafas_client.js'; +import { initHafasClient } from './hafasClient.js'; export const showSettings = async () => { showModal(t('settings'), settingsTemplate());
diff --git a/src/tripView.js b/src/tripView.js @@ -6,7 +6,7 @@ import { processLeg } from './app_functions.js'; import { formatDateTime, formatDuration, formatPrice, formatLineAdditionalName, formatLineDisplayName } from './formatters.js'; import { showAlertModal, showLoader, hideOverlay, showModal } from './overlays.js'; import { go } from './router.js'; -import { getHafasClient, client } from './hafas_client.js'; +import { getHafasClient, client } from './hafasClient.js'; import { t } from './languages.js'; const tripTemplate = (data, profile) => {