From 4b513d49c3407dce9cfe152e1500cc8c19d75e80 Mon Sep 17 00:00:00 2001 From: doubletwisted <118005273+doubletwisted@users.noreply.github.com> Date: Fri, 15 Aug 2025 21:45:19 +0200 Subject: [PATCH] fix: normalize pasted image paths and subfolder extraction (Windows-safe, upstream-only) --- web/executionUtils.js | 19 ++++++++++++++----- web/workerUtils.js | 8 +++++--- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/web/executionUtils.js b/web/executionUtils.js index 6e2c583..702504c 100644 --- a/web/executionUtils.js +++ b/web/executionUtils.js @@ -24,8 +24,17 @@ function convertPathsForPlatform(apiPrompt, targetSeparator) { if (typeof obj === 'string') { // Only convert strings that look like file paths if ((obj.includes('\\') || obj.includes('/')) && isLikelyFilename(obj)) { - // Replace any path separator with the target one - return obj.replace(/[\\\/]/g, targetSeparator); + const trimmed = obj.trim(); + const hasDrive = /^[A-Za-z]:\\\\|^[A-Za-z]:\//.test(trimmed); + const isAbsolute = trimmed.startsWith('/') || trimmed.startsWith('\\\\'); + const hasProtocol = /^\w+:\/\//.test(trimmed); + + // Preserve annotated relative paths (e.g., "pasted/image.png") as forward slashes + if (!hasDrive && !isAbsolute && !hasProtocol) { + return trimmed.replace(/\\/g, '/'); + } + // Replace any path separator with the worker's target separator otherwise + return trimmed.replace(/[\\\/]/g, targetSeparator); } return obj; } else if (Array.isArray(obj)) { @@ -507,9 +516,9 @@ export async function uploadImagesToWorker(extension, workerUrl, images) { let cleanName = imageData.name; let subfolder = ''; - // Extract subfolder if present - if (cleanName.includes('/')) { - const parts = cleanName.split('/'); + // Extract subfolder if present (handle both slash styles) + if (cleanName.includes('/') || cleanName.includes('\\')) { + const parts = cleanName.replace(/\\/g, '/').split('/'); subfolder = parts.slice(0, -1).join('/'); cleanName = parts[parts.length - 1]; } diff --git a/web/workerUtils.js b/web/workerUtils.js index ef87542..194f523 100644 --- a/web/workerUtils.js +++ b/web/workerUtils.js @@ -105,13 +105,15 @@ export function findImageReferences(extension, apiPrompt) { if (typeof mediaValue === 'string') { // Clean special suffixes like [input] or [output] const cleanValue = mediaValue.replace(/\s*\[\w+\]$/, '').trim(); - if (imageExtensions.test(cleanValue)) { - images.set(cleanValue, { + // Normalize to forward slashes so subfolder/filename derivation is consistent on Windows + const normalizedValue = cleanValue.replace(/\\/g, '/'); + if (imageExtensions.test(normalizedValue)) { + images.set(normalizedValue, { nodeId, nodeType: node.class_type, inputName: 'image' // Keep as 'image' for compatibility }); - extension.log(`Found media reference: ${cleanValue} in node ${nodeId} (${node.class_type})`, "debug"); + extension.log(`Found media reference: ${normalizedValue} in node ${nodeId} (${node.class_type})`, "debug"); } } }