Various improvements

This commit is contained in:
Stefan Hardegger
2025-08-21 13:55:38 +02:00
parent 35a5825e76
commit a660056003
11 changed files with 829 additions and 55 deletions

View File

@@ -678,9 +678,34 @@ export const databaseApi = {
},
};
// Image utility
// Library context for images - will be set by a React context provider
let currentLibraryId: string | null = null;
// Set the current library ID (called by library context or components)
export const setCurrentLibraryId = (libraryId: string | null): void => {
currentLibraryId = libraryId;
};
// Get current library ID synchronously (fallback to 'default')
export const getCurrentLibraryId = (): string => {
return currentLibraryId || 'default';
};
// Clear library cache when switching libraries
export const clearLibraryCache = (): void => {
currentLibraryId = null;
};
// Image utility - now library-aware
export const getImageUrl = (path: string): string => {
if (!path) return '';
// Images are served directly by nginx at /images/
return `/images/${path}`;
// For compatibility during transition, handle both patterns
if (path.startsWith('http')) {
return path; // External URL
}
// Use library-aware API endpoint
const libraryId = getCurrentLibraryId();
return `/api/files/images/${libraryId}/${path}`;
};