diff --git a/packages/ui/src/components/CreationWizardPopup.tsx b/packages/ui/src/components/CreationWizardPopup.tsx index 447a4c2b..f9bce92b 100644 --- a/packages/ui/src/components/CreationWizardPopup.tsx +++ b/packages/ui/src/components/CreationWizardPopup.tsx @@ -276,7 +276,7 @@ export const CreationWizardPopup: React.FC = ({ // Helper function to upload internal video const uploadInternalVideo = async (file: File): Promise => { return new Promise((resolve, reject) => { - const serverUrl = import.meta.env.VITE_SERVER_IMAGE_API_URL || 'http://192.168.1.11:3333'; + const serverUrl = import.meta.env.VITE_SERVER_IMAGE_API_URL; const formData = new FormData(); formData.append('file', file); diff --git a/packages/ui/src/components/GlobalDragDrop.tsx b/packages/ui/src/components/GlobalDragDrop.tsx index f139c606..41756f29 100644 --- a/packages/ui/src/components/GlobalDragDrop.tsx +++ b/packages/ui/src/components/GlobalDragDrop.tsx @@ -49,7 +49,7 @@ const GlobalDragDrop = () => { } else if (isUrl) { // URL workflow toast.info(translate('Processing link...')); - const serverUrl = import.meta.env.VITE_SERVER_IMAGE_API_URL || 'http://localhost:3333'; + const serverUrl = import.meta.env.VITE_SERVER_IMAGE_API_URL; const { data: { session } } = await supabase.auth.getSession(); const headers: Record = {}; diff --git a/packages/ui/src/components/ImageEditor.tsx b/packages/ui/src/components/ImageEditor.tsx index db337408..2eda38ae 100644 --- a/packages/ui/src/components/ImageEditor.tsx +++ b/packages/ui/src/components/ImageEditor.tsx @@ -51,7 +51,7 @@ export const ImageEditor = ({ imageUrl, pictureId, onSave, onClose }: ImageEdito formData.append('file', file); formData.append('operations', JSON.stringify(ops)); - const serverUrl = import.meta.env.VITE_SERVER_IMAGE_API_URL || 'http://192.168.1.11:3333'; + const serverUrl = import.meta.env.VITE_SERVER_IMAGE_API_URL; const res = await fetch(`${serverUrl}/api/images/transform`, { method: 'POST', body: formData diff --git a/packages/ui/src/components/PhotoCard.tsx b/packages/ui/src/components/PhotoCard.tsx index 0b8d88a2..f96117ab 100644 --- a/packages/ui/src/components/PhotoCard.tsx +++ b/packages/ui/src/components/PhotoCard.tsx @@ -102,14 +102,6 @@ const PhotoCard = ({ setLocalVersionCount(versionCount); } }, [versionCount]); - - // Legacy fetch removed in favor of passed prop - /* - useEffect(() => { - // ... legacy fetch logic ... - }, [pictureId, isOwner, user]); - */ - const handleLike = async (e: React.MouseEvent) => { e.stopPropagation(); diff --git a/packages/ui/src/components/ResponsiveImage.tsx b/packages/ui/src/components/ResponsiveImage.tsx index e9eb0d53..f712353f 100644 --- a/packages/ui/src/components/ResponsiveImage.tsx +++ b/packages/ui/src/components/ResponsiveImage.tsx @@ -54,6 +54,7 @@ const ResponsiveImage: React.FC = React.memo(({ const ref = React.useRef(null); const imgRef = React.useRef(null); + useEffect(() => { if (props.loading === 'eager' || providedData) { setIsInView(true); diff --git a/packages/ui/src/components/VideoCard.tsx b/packages/ui/src/components/VideoCard.tsx index ce7c2961..b685ad60 100644 --- a/packages/ui/src/components/VideoCard.tsx +++ b/packages/ui/src/components/VideoCard.tsx @@ -177,7 +177,7 @@ const VideoCard = ({ const jobId = match[1]; // Use VITE_SERVER_IMAGE_API_URL or default. Do NOT infer from videoUrl if it logic fails. - let baseUrl = import.meta.env.VITE_SERVER_IMAGE_API_URL || 'http://localhost:3333'; + let baseUrl = import.meta.env.VITE_SERVER_IMAGE_API_URL; // Fallback: If videoUrl is internal (same origin), use that origin. // But for Supabase URLs, we MUST use the API server URL. @@ -265,7 +265,7 @@ const VideoCard = ({ const jobId = match[1]; // Use VITE_SERVER_IMAGE_API_URL or default - let baseUrl = import.meta.env.VITE_SERVER_IMAGE_API_URL || 'http://localhost:3333'; + let baseUrl = import.meta.env.VITE_SERVER_IMAGE_API_URL; if (videoUrl.startsWith('/') || videoUrl.includes(window.location.origin)) { baseUrl = window.location.origin; diff --git a/packages/ui/src/hooks/useResponsiveImage.ts b/packages/ui/src/hooks/useResponsiveImage.ts index e9c4c4bd..f26eb099 100644 --- a/packages/ui/src/hooks/useResponsiveImage.ts +++ b/packages/ui/src/hooks/useResponsiveImage.ts @@ -22,7 +22,7 @@ export const useResponsiveImage = ({ responsiveSizes = DEFAULT_SIZES, formats = DEFAULT_FORMATS, enabled = true, - apiUrl, + apiUrl = import.meta.env.VITE_SERVER_IMAGE_API_URL, }: UseResponsiveImageProps) => { const [data, setData] = useState(null); const [loading, setLoading] = useState(false); @@ -78,7 +78,7 @@ export const useResponsiveImage = ({ if (!requestCache.has(cacheKey)) { const requestPromise = (async () => { - const serverUrl = apiUrl || import.meta.env.VITE_SERVER_IMAGE_API_URL || 'http://192.168.1.11:3333'; + const serverUrl = apiUrl || import.meta.env.VITE_SERVER_IMAGE_API_URL; // Resolve relative URLs to absolute so the server-side API can fetch them const resolvedSrc = src.startsWith('/') ? `${window.location.origin}${src}` : src; const params = new URLSearchParams({ diff --git a/packages/ui/src/lib/db.ts b/packages/ui/src/lib/db.ts index 07abf9ad..ba335eb4 100644 --- a/packages/ui/src/lib/db.ts +++ b/packages/ui/src/lib/db.ts @@ -106,7 +106,7 @@ export const fetchAnalytics = async (options: { limit?: number, startDate?: stri if (options.endDate) params.append('endDate', options.endDate); // Server URL logic from fetchMediaItemsByIds - const serverUrl = import.meta.env.VITE_SERVER_IMAGE_API_URL || 'http://localhost:3333'; + const serverUrl = import.meta.env.VITE_SERVER_IMAGE_API_URL; const res = await fetch(`${serverUrl}/api/analytics?${params.toString()}`, { headers }); @@ -130,7 +130,7 @@ export const clearAnalytics = async () => { headers['Authorization'] = `Bearer ${token}`; // Server URL logic from fetchMediaItemsByIds - const serverUrl = import.meta.env.VITE_SERVER_IMAGE_API_URL || 'http://localhost:3333'; + const serverUrl = import.meta.env.VITE_SERVER_IMAGE_API_URL; const res = await fetch(`${serverUrl}/api/analytics`, { method: 'DELETE', diff --git a/packages/ui/src/lib/openai.ts b/packages/ui/src/lib/openai.ts index 4a0c624d..e9fbd277 100644 --- a/packages/ui/src/lib/openai.ts +++ b/packages/ui/src/lib/openai.ts @@ -115,7 +115,7 @@ export const createOpenAIClient = async (apiKey?: string): Promise => { if (!userId) throw new Error('User ID is required for upload'); - console.log('uploading ', import.meta.env); - const MAX_SIZE = Number(import.meta.env.VITE_MAX_IMAGE_SIZE) || 1572864; // 1.5MB default const SERVER_URL = import.meta.env.VITE_SERVER_IMAGE_API_URL; + if (!SERVER_URL) throw new Error('VITE_SERVER_IMAGE_API_URL is not configured'); - // Use proxy if file is too large and server URL is configured - if (file.size > MAX_SIZE && SERVER_URL) { - console.log(`File size (${file.size}) exceeds threshold (${MAX_SIZE}), uploading via proxy...`); - const formData = new FormData(); - formData.append('file', file); + console.log(`Uploading ${file.name} (${file.size} bytes) via server API...`); + const formData = new FormData(); + formData.append('file', file); - // The server expects multipart/form-data - const response = await fetch(`${SERVER_URL}/api/images?forward=supabase&original=true`, { - method: 'POST', - body: formData, - }); + const response = await fetch(`${SERVER_URL}/api/images?forward=supabase&original=true`, { + method: 'POST', + body: formData, + }); - if (!response.ok) { - const errorText = await response.text(); - console.error('Proxy upload failed:', errorText); - throw new Error(`Failed to upload image via proxy: ${response.statusText}`); - } - - const data = await response.json(); - return { publicUrl: data.url, meta: data.meta }; - } else { - // Direct Supabase upload - console.log(`File size (${file.size}) within threshold (${MAX_SIZE}), uploading directly...`); - const fileExt = file.name.split('.').pop(); - // Generate a unique filename using user ID and timestamp/random string - const fileName = `${userId}/${Date.now()}-${Math.random().toString(36).substring(7)}.${fileExt}`; - - const { error: uploadError } = await supabase.storage - .from('pictures') - .upload(fileName, file); - - if (uploadError) throw uploadError; - - const { data: { publicUrl } } = supabase.storage - .from('pictures') - .getPublicUrl(fileName); - - return { publicUrl }; + if (!response.ok) { + const errorText = await response.text(); + console.error('Server upload failed:', errorText); + throw new Error(`Failed to upload image via server: ${response.statusText}`); } + + const data = await response.json(); + return { publicUrl: data.url, meta: data.meta }; }; /** diff --git a/packages/ui/src/modules/pages/editor/EmailPreviewPanel.tsx b/packages/ui/src/modules/pages/editor/EmailPreviewPanel.tsx index 797cea11..5991bdb8 100644 --- a/packages/ui/src/modules/pages/editor/EmailPreviewPanel.tsx +++ b/packages/ui/src/modules/pages/editor/EmailPreviewPanel.tsx @@ -20,7 +20,7 @@ export const EmailPreviewPanel = ({ iframeRef, authToken, }: EmailPreviewPanelProps) => { - const serverUrl = import.meta.env.VITE_SERVER_IMAGE_API_URL || 'http://localhost:3333'; + const serverUrl = import.meta.env.VITE_SERVER_IMAGE_API_URL; const previewPath = orgSlug ? `/org/${orgSlug}/user/${page.owner}/pages/${page.slug}/email-preview` : `/user/${page.owner}/pages/${page.slug}/email-preview`; diff --git a/packages/ui/src/modules/pages/editor/hooks/useEmailActions.ts b/packages/ui/src/modules/pages/editor/hooks/useEmailActions.ts index bbd40e89..de25938d 100644 --- a/packages/ui/src/modules/pages/editor/hooks/useEmailActions.ts +++ b/packages/ui/src/modules/pages/editor/hooks/useEmailActions.ts @@ -32,7 +32,7 @@ export function useEmailActions({ page, orgSlug }: UseEmailActionsParams) { setIsSendingEmail(true); try { - const serverUrl = import.meta.env.VITE_SERVER_IMAGE_API_URL || 'http://localhost:3333'; + const serverUrl = import.meta.env.VITE_SERVER_IMAGE_API_URL; const endpoint = orgSlug ? `${serverUrl}/org/${orgSlug}/user/${page.owner}/pages/${page.slug}/email-send` : `${serverUrl}/user/${page.owner}/pages/${page.slug}/email-send`; diff --git a/packages/ui/src/modules/posts/client-pictures.ts b/packages/ui/src/modules/posts/client-pictures.ts index 9a3b38c2..fb7e1a86 100644 --- a/packages/ui/src/modules/posts/client-pictures.ts +++ b/packages/ui/src/modules/posts/client-pictures.ts @@ -279,7 +279,7 @@ export const fetchMediaItemsByIds = async ( } // Call server API endpoint - const serverUrl = import.meta.env.VITE_SERVER_IMAGE_API_URL || 'http://localhost:3333'; + const serverUrl = import.meta.env.VITE_SERVER_IMAGE_API_URL; const response = await fetch(`${serverUrl}/api/media-items?${params.toString()}`); if (!response.ok) { diff --git a/packages/ui/src/pages/PlaygroundImageEditor.tsx b/packages/ui/src/pages/PlaygroundImageEditor.tsx index 9ab68b81..a16cce17 100644 --- a/packages/ui/src/pages/PlaygroundImageEditor.tsx +++ b/packages/ui/src/pages/PlaygroundImageEditor.tsx @@ -87,7 +87,7 @@ const PlaygroundImageEditor = () => { formData.append('file', file); formData.append('operations', JSON.stringify(ops)); - const serverUrl = import.meta.env.VITE_SERVER_IMAGE_API_URL || 'http://192.168.1.11:3333'; + const serverUrl = import.meta.env.VITE_SERVER_IMAGE_API_URL; const res = await fetch(`${serverUrl}/api/images/transform`, { method: 'POST', body: formData diff --git a/packages/ui/src/pages/VideoPlayerPlaygroundIntern.tsx b/packages/ui/src/pages/VideoPlayerPlaygroundIntern.tsx index 5117f0a1..1ea842f5 100644 --- a/packages/ui/src/pages/VideoPlayerPlaygroundIntern.tsx +++ b/packages/ui/src/pages/VideoPlayerPlaygroundIntern.tsx @@ -47,7 +47,7 @@ const VideoPlayerPlaygroundIntern = () => { }; const trackProgress = (id: string) => { - const serverUrl = import.meta.env.VITE_SERVER_IMAGE_API_URL || 'http://192.168.1.11:3333'; + const serverUrl = import.meta.env.VITE_SERVER_IMAGE_API_URL; const eventSource = new EventSource(`${serverUrl}/api/videos/jobs/${id}/progress`); eventSource.onmessage = (event) => { @@ -77,7 +77,7 @@ const VideoPlayerPlaygroundIntern = () => { }; const pollJob = async (id: string) => { - const serverUrl = import.meta.env.VITE_SERVER_IMAGE_API_URL || 'http://192.168.1.11:3333'; + const serverUrl = import.meta.env.VITE_SERVER_IMAGE_API_URL; let attempts = 0; const maxAttempts = 60; // 2 minutes @@ -132,7 +132,7 @@ const VideoPlayerPlaygroundIntern = () => { const formData = new FormData(); formData.append('file', file); - const serverUrl = import.meta.env.VITE_SERVER_IMAGE_API_URL || 'http://192.168.1.11:3333'; + const serverUrl = import.meta.env.VITE_SERVER_IMAGE_API_URL; try { const xhr = new XMLHttpRequest(); diff --git a/packages/ui/src/utils/uploadUtils.ts b/packages/ui/src/utils/uploadUtils.ts index 5450602e..3d3fc8e4 100644 --- a/packages/ui/src/utils/uploadUtils.ts +++ b/packages/ui/src/utils/uploadUtils.ts @@ -9,7 +9,7 @@ export const uploadInternalVideo = async ( onProgress?: (progress: number) => void ): Promise<{ dbId: string; thumbnailUrl: string; meta: any }> => { return new Promise((resolve, reject) => { - const serverUrl = import.meta.env.VITE_SERVER_IMAGE_API_URL || 'http://192.168.1.11:3333'; + const serverUrl = import.meta.env.VITE_SERVER_IMAGE_API_URL; const formData = new FormData(); formData.append('file', file); const title = file.name.replace(/\.[^/.]+$/, '');