added ftp controlservice health check and fixed gallery js error
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { getDeviceId } from '../lib/device';
|
||||
import { DEFAULT_LOCALE } from '../i18n/messages';
|
||||
|
||||
export interface EventBrandingPayload {
|
||||
primary_color?: string | null;
|
||||
@@ -149,6 +150,31 @@ export class FetchEventError extends Error {
|
||||
}
|
||||
}
|
||||
|
||||
function coerceLocalized(value: unknown, fallback: string): string {
|
||||
if (typeof value === 'string' && value.trim() !== '') {
|
||||
return value;
|
||||
}
|
||||
|
||||
if (value && typeof value === 'object') {
|
||||
const obj = value as Record<string, unknown>;
|
||||
const preferredKeys = ['de', 'en'];
|
||||
|
||||
for (const key of preferredKeys) {
|
||||
const candidate = obj[key];
|
||||
if (typeof candidate === 'string' && candidate.trim() !== '') {
|
||||
return candidate;
|
||||
}
|
||||
}
|
||||
|
||||
const firstString = Object.values(obj).find((candidate) => typeof candidate === 'string' && candidate.trim() !== '');
|
||||
if (typeof firstString === 'string') {
|
||||
return firstString;
|
||||
}
|
||||
}
|
||||
|
||||
return fallback;
|
||||
}
|
||||
|
||||
const API_ERROR_CODES: FetchEventErrorCode[] = [
|
||||
'invalid_token',
|
||||
'token_expired',
|
||||
@@ -231,7 +257,24 @@ export async function fetchEvent(eventKey: string): Promise<EventData> {
|
||||
});
|
||||
}
|
||||
|
||||
return await res.json();
|
||||
const json = await res.json();
|
||||
|
||||
const normalized: EventData = {
|
||||
...json,
|
||||
name: coerceLocalized(json?.name, 'Fotospiel Event'),
|
||||
default_locale: typeof json?.default_locale === 'string' && json.default_locale.trim() !== ''
|
||||
? json.default_locale
|
||||
: DEFAULT_LOCALE,
|
||||
};
|
||||
|
||||
if (json?.type) {
|
||||
normalized.type = {
|
||||
...json.type,
|
||||
name: coerceLocalized(json.type?.name, 'Event'),
|
||||
};
|
||||
}
|
||||
|
||||
return normalized;
|
||||
} catch (error) {
|
||||
if (error instanceof FetchEventError) {
|
||||
throw error;
|
||||
|
||||
Reference in New Issue
Block a user