Files
fotospiel-app/resources/js/guest/services/galleryApi.ts
Codex Agent 9bde8f3f32 Neue Branding-Page und Gäste-PWA reagiert nun auf Branding-Einstellungen vom event-admin. Implemented local Google Fonts pipeline and admin UI selects for branding and invites.
- Added fonts:sync-google command (uses GOOGLE_FONTS_API_KEY, generates /public/fonts/google files, manifest, CSS, cache flush) and
    exposed manifest via new GET /api/v1/tenant/fonts endpoint with fallbacks for existing local fonts.
  - Imported generated fonts CSS, added API client + font loader hook, and wired branding page font fields to searchable selects (with
    custom override) that auto-load selected fonts.
  - Invites layout editor now offers font selection per element with runtime font loading for previews/export alignment.
  - New tests cover font sync command and font manifest API.

  Tests run: php artisan test --filter=Fonts --testsuite=Feature.
  Note: repository already has other modified files (e.g., EventPublicController, SettingsStoreRequest, guest components, etc.); left
  untouched. Run php artisan fonts:sync-google after setting the API key to populate /public/fonts/google.
2025-11-25 19:31:52 +01:00

90 lines
2.4 KiB
TypeScript

import type { LocaleCode } from '../i18n/messages';
export interface GalleryBranding {
primary_color: string;
secondary_color: string;
background_color: string;
surface_color?: string;
mode?: 'light' | 'dark' | 'auto';
palette?: {
primary?: string | null;
secondary?: string | null;
background?: string | null;
surface?: string | null;
} | null;
}
export interface GalleryMetaResponse {
event: {
id: number;
name: string;
slug?: string | null;
description?: string | null;
gallery_expires_at?: string | null;
};
branding: GalleryBranding;
}
export interface GalleryPhotoResource {
id: number;
thumbnail_url: string | null;
full_url: string | null;
download_url: string;
likes_count: number;
guest_name?: string | null;
created_at?: string | null;
}
export interface GalleryPhotosResponse {
data: GalleryPhotoResource[];
next_cursor: string | null;
}
async function handleResponse<T>(response: Response): Promise<T> {
if (response.status === 204) {
return {} as T;
}
const data = await response.json().catch(() => null);
if (!response.ok) {
const errorPayload = data as { error?: { message?: string; code?: unknown } } | null;
const error = new Error(errorPayload?.error?.message ?? 'Request failed') as Error & { code?: unknown };
error.code = errorPayload?.error?.code ?? response.status;
throw error;
}
return data as T;
}
export async function fetchGalleryMeta(token: string, locale?: LocaleCode): Promise<GalleryMetaResponse> {
const params = new URLSearchParams();
if (locale) params.set('locale', locale);
const response = await fetch(`/api/v1/gallery/${encodeURIComponent(token)}${params.toString() ? `?${params.toString()}` : ''}`, {
headers: {
'Accept': 'application/json',
},
credentials: 'omit',
});
return handleResponse<GalleryMetaResponse>(response);
}
export async function fetchGalleryPhotos(token: string, cursor?: string | null, limit = 30): Promise<GalleryPhotosResponse> {
const params = new URLSearchParams();
params.set('limit', String(limit));
if (cursor) {
params.set('cursor', cursor);
}
const response = await fetch(`/api/v1/gallery/${encodeURIComponent(token)}/photos?${params.toString()}`, {
headers: {
'Accept': 'application/json',
},
credentials: 'omit',
});
return handleResponse<GalleryPhotosResponse>(response);
}