Plugin Directory

Changeset 3356947


Ignore:
Timestamp:
09/06/2025 05:06:55 AM (7 months ago)
Author:
levelsdev
Message:

Release version 1.1.1 - Update image processor and paste handler modules

Location:
ready-made-oxygen-integration
Files:
1 deleted
4 edited
6 copied

Legend:

Unmodified
Added
Removed
  • ready-made-oxygen-integration/tags/1.1.1/includes/js/modules/imageProcessor.js

    r3322576 r3356947  
    99 */
    1010async 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) + "...");
    1812
    1913  // Check if wpApiSettings is available
     
    2418
    2519  let restUrl = wpApiSettings.root + wpApiSettings.versionString;
     20  let filename = original.attachment_url?.split("/").pop() || `figma-image-${Date.now()}.png`;
     21  let blob = null;
    2622
    2723  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());
    3750
    38     let metadata = null;
     51      let metadata = null;
    3952
    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);
    4567     
    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 => {
    4970        if (!res.ok) {
    5071          throw new Error(`Failed to download image: ${res.status} ${res.statusText}`);
     
    5475
    5576      console.log("READOXIN: ✅ Image downloaded successfully, size:", blob.size, "bytes");
     77    }
    5678
    57       // Upload to WordPress media library
    58       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);
    6082
    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    });
    7496
    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);
    79101    }
    80102
  • ready-made-oxygen-integration/tags/1.1.1/includes/js/modules/pasteHandler.js

    r3322576 r3356947  
    2727      }
    2828
    29       // Process images
     29      // Process images (both server URLs and local data URLs)
    3030      const imageBlocks = [];
    3131      JSON.stringify(json, (key, value) => {
     
    3434            value.original.image_type === "1" &&
    3535            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          }
    3946        }
    4047        return value;
  • ready-made-oxygen-integration/trunk/includes/js/modules/imageProcessor.js

    r3322576 r3356947  
    99 */
    1010async 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) + "...");
    1812
    1913  // Check if wpApiSettings is available
     
    2418
    2519  let restUrl = wpApiSettings.root + wpApiSettings.versionString;
     20  let filename = original.attachment_url?.split("/").pop() || `figma-image-${Date.now()}.png`;
     21  let blob = null;
    2622
    2723  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());
    3750
    38     let metadata = null;
     51      let metadata = null;
    3952
    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);
    4567     
    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 => {
    4970        if (!res.ok) {
    5071          throw new Error(`Failed to download image: ${res.status} ${res.statusText}`);
     
    5475
    5576      console.log("READOXIN: ✅ Image downloaded successfully, size:", blob.size, "bytes");
     77    }
    5678
    57       // Upload to WordPress media library
    58       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);
    6082
    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    });
    7496
    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);
    79101    }
    80102
  • ready-made-oxygen-integration/trunk/includes/js/modules/pasteHandler.js

    r3322576 r3356947  
    2727      }
    2828
    29       // Process images
     29      // Process images (both server URLs and local data URLs)
    3030      const imageBlocks = [];
    3131      JSON.stringify(json, (key, value) => {
     
    3434            value.original.image_type === "1" &&
    3535            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          }
    3946        }
    4047        return value;
Note: See TracChangeset for help on using the changeset viewer.