|
|
|
|
| |
| |
| |
| |
| |
| |
|
|
| export const convertGoogleDriveUrl = (url, mediaId, plantName) => {
|
| if (!url) return null;
|
|
|
|
|
| if (mediaId) {
|
|
|
| const safePlantName = plantName
|
| ? plantName.replace(/[^\w\s-]/g, '').trim().replace(/[-\s]+/g, '_')
|
| : 'unknown';
|
|
|
| const localPath = `/images/${mediaId}_${safePlantName}.jpg`;
|
| return localPath;
|
| }
|
|
|
|
|
| if (url.includes('drive.google.com')) {
|
| const viewMatch = url.match(/\/file\/d\/([a-zA-Z0-9-_]+)/);
|
| if (viewMatch) {
|
| const fileId = viewMatch[1];
|
| return `https://drive.google.com/uc?export=view&id=${fileId}`;
|
| }
|
| }
|
|
|
| return url;
|
| };
|
|
|
| |
| |
| |
| |
| |
| |
|
|
| export const getImageUrl = (url, mediaId, plantName) => {
|
| if (!url) return null;
|
| return convertGoogleDriveUrl(url, mediaId, plantName);
|
| };
|
|
|
| |
| |
| |
| |
| |
| |
|
|
| export const getPlaceholderImage = (width = 300, height = 200, text = 'No Image') => {
|
| return `data:image/svg+xml;base64,${btoa(`
|
| <svg width="${width}" height="${height}" viewBox="0 0 ${width} ${height}" fill="none" xmlns="http://www.w3.org/2000/svg">
|
| <rect width="${width}" height="${height}" fill="#f3f4f6"/>
|
| <rect x="20" y="20" width="${width-40}" height="${height-40}" rx="8" fill="#e5e7eb"/>
|
| <text x="${width/2}" y="${height/2}" font-family="Arial, sans-serif" font-size="16" text-anchor="middle" dominant-baseline="central" fill="#6b7280">${text}</text>
|
| </svg>
|
| `)}`;
|
| }; |