Changeset 3356947
- Timestamp:
- 09/06/2025 05:06:55 AM (7 months ago)
- Location:
- ready-made-oxygen-integration
- Files:
-
- 1 deleted
- 4 edited
- 6 copied
-
tags/1.1.1 (copied) (copied from ready-made-oxygen-integration/trunk)
-
tags/1.1.1/README.md (copied) (copied from ready-made-oxygen-integration/trunk/README.md)
-
tags/1.1.1/includes/js/addPasteButton-modular.js (copied) (copied from ready-made-oxygen-integration/trunk/includes/js/addPasteButton-modular.js)
-
tags/1.1.1/includes/js/addPasteButton.js (deleted)
-
tags/1.1.1/includes/js/modules (copied) (copied from ready-made-oxygen-integration/trunk/includes/js/modules)
-
tags/1.1.1/includes/js/modules/imageProcessor.js (modified) (3 diffs)
-
tags/1.1.1/includes/js/modules/pasteHandler.js (modified) (2 diffs)
-
tags/1.1.1/readme.txt (copied) (copied from ready-made-oxygen-integration/trunk/readme.txt)
-
tags/1.1.1/ready-made-oxygen-integration.php (copied) (copied from ready-made-oxygen-integration/trunk/ready-made-oxygen-integration.php)
-
trunk/includes/js/modules/imageProcessor.js (modified) (3 diffs)
-
trunk/includes/js/modules/pasteHandler.js (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
ready-made-oxygen-integration/tags/1.1.1/includes/js/modules/imageProcessor.js
r3322576 r3356947 9 9 */ 10 10 async function processImageOriginal(original) { 11 const filename = original.attachment_url?.split("/").pop(); 12 if (!filename) { 13 console.warn("READOXIN: ⚠️ No filename found in attachment URL:", original.attachment_url); 14 return; 15 } 16 17 console.log("READOXIN: 🔄 Processing image:", filename); 11 console.log("READOXIN: 🔄 Processing image:", original.attachment_url?.substring(0, 50) + "..."); 18 12 19 13 // Check if wpApiSettings is available … … 24 18 25 19 let restUrl = wpApiSettings.root + wpApiSettings.versionString; 20 let filename = original.attachment_url?.split("/").pop() || `figma-image-${Date.now()}.png`; 21 let blob = null; 26 22 27 23 try { 28 // console.log("READOXIN: 🔍 Searching for existing media:", filename); 29 30 // First, check if the image already exists in the media library 31 const media = await fetch(`${restUrl}media?search=${filename}`, { 32 headers: { "X-WP-Nonce": wpApiSettings.nonce }, 33 }).then(res => { 34 // console.log("READOXIN: 📡 Media search response status:", res.status); 35 return res.json(); 36 }); 24 // Check if this is a data URL (local image) or server URL 25 if (original.attachment_url?.startsWith('data:image/')) { 26 console.log("READOXIN: 🖼️ Processing local data URL image"); 27 28 // Convert data URL to blob 29 const response = await fetch(original.attachment_url); 30 blob = await response.blob(); 31 32 // Generate filename from timestamp since data URLs don't have filenames 33 filename = `figma-local-${Date.now()}.png`; 34 35 console.log("READOXIN: ✅ Converted data URL to blob, size:", blob.size, "bytes"); 36 } else { 37 // Handle server URL (original behavior) 38 if (!original.attachment_url?.split("/").pop()) { 39 console.warn("READOXIN: ⚠️ No filename found in attachment URL:", original.attachment_url); 40 return; 41 } 42 43 filename = original.attachment_url.split("/").pop(); 44 console.log("READOXIN: 🌐 Processing server URL image:", filename); 45 46 // First, check if the image already exists in the media library 47 const media = await fetch(`${restUrl}media?search=${filename}`, { 48 headers: { "X-WP-Nonce": wpApiSettings.nonce }, 49 }).then(res => res.json()); 37 50 38 let metadata = null;51 let metadata = null; 39 52 40 if (media.length > 0) { 41 metadata = media[0]; 42 console.log("READOXIN: ✅ Found existing media in library:", metadata.id); 43 } else { 44 console.log("READOXIN: 📥 Media not found, downloading from temp URL:", original.attachment_url); 53 if (media.length > 0) { 54 metadata = media[0]; 55 console.log("READOXIN: ✅ Found existing media in library:", metadata.id); 56 57 // Update the original object and return early 58 original.image_type = "2"; 59 original.attachment_id = metadata.id; 60 original.attachment_url = metadata.source_url || ""; 61 original.attachment_width = metadata.media_details?.width || 0; 62 original.attachment_height = metadata.media_details?.height || 0; 63 return; 64 } 65 66 console.log("READOXIN: 📥 Media not found, downloading from server URL:", original.attachment_url); 45 67 46 // Download the image from the temp URL 47 const blob = await fetch(original.attachment_url).then(res => { 48 // console.log("READOXIN: 📡 Image download response status:", res.status); 68 // Download the image from the server URL 69 blob = await fetch(original.attachment_url).then(res => { 49 70 if (!res.ok) { 50 71 throw new Error(`Failed to download image: ${res.status} ${res.statusText}`); … … 54 75 55 76 console.log("READOXIN: ✅ Image downloaded successfully, size:", blob.size, "bytes"); 77 } 56 78 57 // Upload to WordPress media library58 const formData = new FormData();59 formData.append("file", blob, filename);79 // Upload to WordPress media library (common for both data URLs and server URLs) 80 const formData = new FormData(); 81 formData.append("file", blob, filename); 60 82 61 // console.log("READOXIN: 📤 Uploading to WordPress media library...");62 63 const uploaded = await fetch(`${restUrl}media`, {64 method: "POST",65 headers: { "X-WP-Nonce": wpApiSettings.nonce },66 body: formData,67 }).then(res => {68 console.log("READOXIN: 📡 Media upload response status:", res.status);69 if (!res.ok) {70 throw new Error(`Failed to upload image: ${res.status} ${res.statusText}`);71 }72 return res.json();73 });83 console.log("READOXIN: 📤 Uploading to WordPress media library as:", filename); 84 85 const uploaded = await fetch(`${restUrl}media`, { 86 method: "POST", 87 headers: { "X-WP-Nonce": wpApiSettings.nonce }, 88 body: formData, 89 }).then(res => { 90 console.log("READOXIN: 📡 Media upload response status:", res.status); 91 if (!res.ok) { 92 throw new Error(`Failed to upload image: ${res.status} ${res.statusText}`); 93 } 94 return res.json(); 95 }); 74 96 75 if (uploaded && uploaded.id) {76 metadata = uploaded;77 console.log("READOXIN: ✅ Image uploaded successfully with ID:", uploaded.id);78 }97 let metadata = null; 98 if (uploaded && uploaded.id) { 99 metadata = uploaded; 100 console.log("READOXIN: ✅ Image uploaded successfully with ID:", uploaded.id); 79 101 } 80 102 -
ready-made-oxygen-integration/tags/1.1.1/includes/js/modules/pasteHandler.js
r3322576 r3356947 27 27 } 28 28 29 // Process images 29 // Process images (both server URLs and local data URLs) 30 30 const imageBlocks = []; 31 31 JSON.stringify(json, (key, value) => { … … 34 34 value.original.image_type === "1" && 35 35 value.original.attachment_url && 36 value.original.attachment_url !== "" && 37 value.original.attachment_url.includes(readoxinSettings.tempUrlPattern)) { 38 imageBlocks.push(value.original); 36 value.original.attachment_url !== "") { 37 38 // Check if it's a data URL (local image) or server URL with temp pattern 39 const isDataUrl = value.original.attachment_url.startsWith('data:image/'); 40 const isServerTempUrl = value.original.attachment_url.includes(readoxinSettings.tempUrlPattern); 41 42 if (isDataUrl || isServerTempUrl) { 43 console.log("READOXIN: 📋 Found image to process:", isDataUrl ? "data URL" : "server URL"); 44 imageBlocks.push(value.original); 45 } 39 46 } 40 47 return value; -
ready-made-oxygen-integration/trunk/includes/js/modules/imageProcessor.js
r3322576 r3356947 9 9 */ 10 10 async function processImageOriginal(original) { 11 const filename = original.attachment_url?.split("/").pop(); 12 if (!filename) { 13 console.warn("READOXIN: ⚠️ No filename found in attachment URL:", original.attachment_url); 14 return; 15 } 16 17 console.log("READOXIN: 🔄 Processing image:", filename); 11 console.log("READOXIN: 🔄 Processing image:", original.attachment_url?.substring(0, 50) + "..."); 18 12 19 13 // Check if wpApiSettings is available … … 24 18 25 19 let restUrl = wpApiSettings.root + wpApiSettings.versionString; 20 let filename = original.attachment_url?.split("/").pop() || `figma-image-${Date.now()}.png`; 21 let blob = null; 26 22 27 23 try { 28 // console.log("READOXIN: 🔍 Searching for existing media:", filename); 29 30 // First, check if the image already exists in the media library 31 const media = await fetch(`${restUrl}media?search=${filename}`, { 32 headers: { "X-WP-Nonce": wpApiSettings.nonce }, 33 }).then(res => { 34 // console.log("READOXIN: 📡 Media search response status:", res.status); 35 return res.json(); 36 }); 24 // Check if this is a data URL (local image) or server URL 25 if (original.attachment_url?.startsWith('data:image/')) { 26 console.log("READOXIN: 🖼️ Processing local data URL image"); 27 28 // Convert data URL to blob 29 const response = await fetch(original.attachment_url); 30 blob = await response.blob(); 31 32 // Generate filename from timestamp since data URLs don't have filenames 33 filename = `figma-local-${Date.now()}.png`; 34 35 console.log("READOXIN: ✅ Converted data URL to blob, size:", blob.size, "bytes"); 36 } else { 37 // Handle server URL (original behavior) 38 if (!original.attachment_url?.split("/").pop()) { 39 console.warn("READOXIN: ⚠️ No filename found in attachment URL:", original.attachment_url); 40 return; 41 } 42 43 filename = original.attachment_url.split("/").pop(); 44 console.log("READOXIN: 🌐 Processing server URL image:", filename); 45 46 // First, check if the image already exists in the media library 47 const media = await fetch(`${restUrl}media?search=${filename}`, { 48 headers: { "X-WP-Nonce": wpApiSettings.nonce }, 49 }).then(res => res.json()); 37 50 38 let metadata = null;51 let metadata = null; 39 52 40 if (media.length > 0) { 41 metadata = media[0]; 42 console.log("READOXIN: ✅ Found existing media in library:", metadata.id); 43 } else { 44 console.log("READOXIN: 📥 Media not found, downloading from temp URL:", original.attachment_url); 53 if (media.length > 0) { 54 metadata = media[0]; 55 console.log("READOXIN: ✅ Found existing media in library:", metadata.id); 56 57 // Update the original object and return early 58 original.image_type = "2"; 59 original.attachment_id = metadata.id; 60 original.attachment_url = metadata.source_url || ""; 61 original.attachment_width = metadata.media_details?.width || 0; 62 original.attachment_height = metadata.media_details?.height || 0; 63 return; 64 } 65 66 console.log("READOXIN: 📥 Media not found, downloading from server URL:", original.attachment_url); 45 67 46 // Download the image from the temp URL 47 const blob = await fetch(original.attachment_url).then(res => { 48 // console.log("READOXIN: 📡 Image download response status:", res.status); 68 // Download the image from the server URL 69 blob = await fetch(original.attachment_url).then(res => { 49 70 if (!res.ok) { 50 71 throw new Error(`Failed to download image: ${res.status} ${res.statusText}`); … … 54 75 55 76 console.log("READOXIN: ✅ Image downloaded successfully, size:", blob.size, "bytes"); 77 } 56 78 57 // Upload to WordPress media library58 const formData = new FormData();59 formData.append("file", blob, filename);79 // Upload to WordPress media library (common for both data URLs and server URLs) 80 const formData = new FormData(); 81 formData.append("file", blob, filename); 60 82 61 // console.log("READOXIN: 📤 Uploading to WordPress media library...");62 63 const uploaded = await fetch(`${restUrl}media`, {64 method: "POST",65 headers: { "X-WP-Nonce": wpApiSettings.nonce },66 body: formData,67 }).then(res => {68 console.log("READOXIN: 📡 Media upload response status:", res.status);69 if (!res.ok) {70 throw new Error(`Failed to upload image: ${res.status} ${res.statusText}`);71 }72 return res.json();73 });83 console.log("READOXIN: 📤 Uploading to WordPress media library as:", filename); 84 85 const uploaded = await fetch(`${restUrl}media`, { 86 method: "POST", 87 headers: { "X-WP-Nonce": wpApiSettings.nonce }, 88 body: formData, 89 }).then(res => { 90 console.log("READOXIN: 📡 Media upload response status:", res.status); 91 if (!res.ok) { 92 throw new Error(`Failed to upload image: ${res.status} ${res.statusText}`); 93 } 94 return res.json(); 95 }); 74 96 75 if (uploaded && uploaded.id) {76 metadata = uploaded;77 console.log("READOXIN: ✅ Image uploaded successfully with ID:", uploaded.id);78 }97 let metadata = null; 98 if (uploaded && uploaded.id) { 99 metadata = uploaded; 100 console.log("READOXIN: ✅ Image uploaded successfully with ID:", uploaded.id); 79 101 } 80 102 -
ready-made-oxygen-integration/trunk/includes/js/modules/pasteHandler.js
r3322576 r3356947 27 27 } 28 28 29 // Process images 29 // Process images (both server URLs and local data URLs) 30 30 const imageBlocks = []; 31 31 JSON.stringify(json, (key, value) => { … … 34 34 value.original.image_type === "1" && 35 35 value.original.attachment_url && 36 value.original.attachment_url !== "" && 37 value.original.attachment_url.includes(readoxinSettings.tempUrlPattern)) { 38 imageBlocks.push(value.original); 36 value.original.attachment_url !== "") { 37 38 // Check if it's a data URL (local image) or server URL with temp pattern 39 const isDataUrl = value.original.attachment_url.startsWith('data:image/'); 40 const isServerTempUrl = value.original.attachment_url.includes(readoxinSettings.tempUrlPattern); 41 42 if (isDataUrl || isServerTempUrl) { 43 console.log("READOXIN: 📋 Found image to process:", isDataUrl ? "data URL" : "server URL"); 44 imageBlocks.push(value.original); 45 } 39 46 } 40 47 return value;
Note: See TracChangeset
for help on using the changeset viewer.