Various improvements
This commit is contained in:
@@ -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}`;
|
||||
};
|
||||
Reference in New Issue
Block a user