mirror of
https://github.com/easydiffusion/easydiffusion.git
synced 2025-05-31 07:05:45 +02:00
Show models above folders in child folders to avoid models from appearing to belong the grandchild folder, prevent creating empty <optgroup />s
This commit is contained in:
parent
e0f22d29e8
commit
e7bf2ee58b
@ -179,10 +179,10 @@ def getModels():
|
|||||||
"Raised when picklescan reports a problem with a model"
|
"Raised when picklescan reports a problem with a model"
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def scan_directory(directory, suffixes):
|
def scan_directory(directory, suffixes, directoriesFirst:bool=True):
|
||||||
nonlocal models_scanned
|
nonlocal models_scanned
|
||||||
tree = []
|
tree = []
|
||||||
for entry in sorted(os.scandir(directory), key = lambda entry: (entry.is_file(), entry.name.lower())):
|
for entry in sorted(os.scandir(directory), key = lambda entry: (entry.is_file() == directoriesFirst, entry.name.lower())):
|
||||||
if entry.is_file():
|
if entry.is_file():
|
||||||
matching_suffix = list(filter(lambda s: entry.name.endswith(s), suffixes))
|
matching_suffix = list(filter(lambda s: entry.name.endswith(s), suffixes))
|
||||||
if len(matching_suffix) == 0: continue
|
if len(matching_suffix) == 0: continue
|
||||||
@ -197,7 +197,8 @@ def getModels():
|
|||||||
known_models[entry.path] = mtime
|
known_models[entry.path] = mtime
|
||||||
tree.append(entry.name[:-len(matching_suffix)])
|
tree.append(entry.name[:-len(matching_suffix)])
|
||||||
elif entry.is_dir():
|
elif entry.is_dir():
|
||||||
scan=scan_directory(entry.path, suffixes)
|
scan=scan_directory(entry.path, suffixes, directoriesFirst=False)
|
||||||
|
|
||||||
if len(scan) != 0:
|
if len(scan) != 0:
|
||||||
tree.append( (entry.name, scan ) )
|
tree.append( (entry.name, scan ) )
|
||||||
return tree
|
return tree
|
||||||
|
@ -1322,9 +1322,12 @@ async function getModels() {
|
|||||||
}
|
}
|
||||||
modelField.appendChild(modelOption)
|
modelField.appendChild(modelOption)
|
||||||
} else {
|
} else {
|
||||||
|
// Since <optgroup/>s can't be nested, don't show empty groups
|
||||||
|
if (modelName[1].some(child => typeof(child) == 'string')) {
|
||||||
const modelGroup = document.createElement('optgroup')
|
const modelGroup = document.createElement('optgroup')
|
||||||
modelGroup.label = path + modelName[0]
|
modelGroup.label = path + modelName[0]
|
||||||
modelField.appendChild(modelGroup)
|
modelField.appendChild(modelGroup)
|
||||||
|
}
|
||||||
modelName[1].forEach( createModelOptions(modelField, selectedModel, path + modelName[0] + "/" ) )
|
modelName[1].forEach( createModelOptions(modelField, selectedModel, path + modelName[0] + "/" ) )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user