More robust relative path calculation

This commit is contained in:
patriceac 2023-02-06 22:19:57 -08:00
parent 01368ac496
commit a0178e15b3

View File

@ -363,14 +363,15 @@ function readUI() {
} }
function getModelPath(filename, extensions) function getModelPath(filename, extensions)
{ {
if (filename.includes('/models/stable-diffusion/') || filename.includes('\\models\\stable-diffusion\\')) { let pathIdx
let pathIdx = filename.lastIndexOf('/') // Linux, Mac paths if (filename.includes('/models/stable-diffusion/')) {
if (pathIdx < 0) { pathIdx = filename.indexOf('/models/stable-diffusion/') + 25 // Linux, Mac paths
pathIdx = filename.lastIndexOf('\\') // Windows paths. }
else if (filename.includes('\\models\\stable-diffusion\\')) {
pathIdx = filename.indexOf('\\models\\stable-diffusion\\') + 25 // Linux, Mac paths
} }
if (pathIdx >= 0) { if (pathIdx >= 0) {
filename = filename.slice(pathIdx + 1) filename = filename.slice(pathIdx)
}
} }
extensions.forEach(ext => { extensions.forEach(ext => {
if (filename.endsWith(ext)) { if (filename.endsWith(ext)) {