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)
{
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)) {