From a8fba8f3fb4864189d87b1f9dd991201fa1984fd Mon Sep 17 00:00:00 2001 From: patriceac <48073125+patriceac@users.noreply.github.com> Date: Sat, 14 Jan 2023 23:54:09 -0800 Subject: [PATCH 1/3] Fix restoration of models with subfolders In dnd.js, when models are restored in the UI, there is code that strips the path from the model file name. Now that we allow models to be hosted in subfolders, this code break the task restoration (e.g. use settings, D&D, copy/paste) because "/my models/model.ckpt" becomes "model.ckpt", which won't be found. https://discord.com/channels/1014774730907209781/1014780368890630164/1063726724573052948 --- ui/media/js/dnd.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/ui/media/js/dnd.js b/ui/media/js/dnd.js index 573e068c..c2c7a93a 100644 --- a/ui/media/js/dnd.js +++ b/ui/media/js/dnd.js @@ -363,12 +363,14 @@ function readUI() { } function getModelPath(filename, extensions) { - let pathIdx = filename.lastIndexOf('/') // Linux, Mac paths - if (pathIdx < 0) { - pathIdx = filename.lastIndexOf('\\') // Windows paths. - } - if (pathIdx >= 0) { - filename = filename.slice(pathIdx + 1) + if (filename.includes('/models/stable-diffusion/')) { + let pathIdx = filename.lastIndexOf('/') // Linux, Mac paths + if (pathIdx < 0) { + pathIdx = filename.lastIndexOf('\\') // Windows paths. + } + if (pathIdx >= 0) { + filename = filename.slice(pathIdx + 1) + } } extensions.forEach(ext => { if (filename.endsWith(ext)) { From 01368ac496136e9fdb7f0ede96bdadd81676cf5a Mon Sep 17 00:00:00 2001 From: patriceac <48073125+patriceac@users.noreply.github.com> Date: Wed, 25 Jan 2023 02:47:50 -0800 Subject: [PATCH 2/3] Add support for Windows path names --- ui/media/js/dnd.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/media/js/dnd.js b/ui/media/js/dnd.js index c2c7a93a..c9ea4891 100644 --- a/ui/media/js/dnd.js +++ b/ui/media/js/dnd.js @@ -363,7 +363,7 @@ function readUI() { } function getModelPath(filename, extensions) { - if (filename.includes('/models/stable-diffusion/')) { + if (filename.includes('/models/stable-diffusion/') || filename.includes('\\models\\stable-diffusion\\')) { let pathIdx = filename.lastIndexOf('/') // Linux, Mac paths if (pathIdx < 0) { pathIdx = filename.lastIndexOf('\\') // Windows paths. From a0178e15b3678f9c62d8e0eb98f548f0039ea30b Mon Sep 17 00:00:00 2001 From: patriceac <48073125+patriceac@users.noreply.github.com> Date: Mon, 6 Feb 2023 22:19:57 -0800 Subject: [PATCH 3/3] More robust relative path calculation --- ui/media/js/dnd.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/ui/media/js/dnd.js b/ui/media/js/dnd.js index c9ea4891..08778451 100644 --- a/ui/media/js/dnd.js +++ b/ui/media/js/dnd.js @@ -363,14 +363,15 @@ function readUI() { } function getModelPath(filename, extensions) { - if (filename.includes('/models/stable-diffusion/') || filename.includes('\\models\\stable-diffusion\\')) { - let pathIdx = filename.lastIndexOf('/') // Linux, Mac paths - if (pathIdx < 0) { - pathIdx = filename.lastIndexOf('\\') // Windows paths. - } - if (pathIdx >= 0) { - filename = filename.slice(pathIdx + 1) - } + let pathIdx + if (filename.includes('/models/stable-diffusion/')) { + pathIdx = filename.indexOf('/models/stable-diffusion/') + 25 // Linux, Mac paths + } + else if (filename.includes('\\models\\stable-diffusion\\')) { + pathIdx = filename.indexOf('\\models\\stable-diffusion\\') + 25 // Linux, Mac paths + } + if (pathIdx >= 0) { + filename = filename.slice(pathIdx) } extensions.forEach(ext => { if (filename.endsWith(ext)) {