robust patch & refactoring folder_paths about annotated_filepath

This commit is contained in:
Lt.Dr.Data 2023-04-21 15:13:03 +09:00
parent 2c21210c72
commit 4d93ef8a0a
2 changed files with 47 additions and 24 deletions

View File

@ -70,7 +70,7 @@ def get_directory_by_type(type_name):
# determine base_dir rely on annotation if name is 'filename.ext [annotation]' format
# otherwise use default_path as base_dir
def get_annotated_filepath(name, default_dir=None):
def touch_annotated_filepath(name):
if name.endswith("[output]"):
base_dir = get_output_directory()
name = name[:-9]
@ -80,24 +80,29 @@ def get_annotated_filepath(name, default_dir=None):
elif name.endswith("[temp]"):
base_dir = get_temp_directory()
name = name[:-7]
elif default_dir is not None:
base_dir = default_dir
else:
base_dir = get_input_directory() # fallback path
return name, None
return name, base_dir
def get_annotated_filepath(name, default_dir=None):
name, base_dir = touch_annotated_filepath(name)
if base_dir is None:
if default_dir is not None:
base_dir = default_dir
else:
base_dir = get_input_directory() # fallback path
return os.path.join(base_dir, name)
def exists_annotated_filepath(name):
if name.endswith("[output]"):
base_dir = get_output_directory()
name = name[:-9]
elif name.endswith("[temp]"):
base_dir = get_temp_directory()
name = name[:-7]
else:
base_dir = get_input_directory()
name = name[:-8]
name, base_dir = touch_annotated_filepath(name)
if base_dir is None:
base_dir = get_input_directory() # fallback path
filepath = os.path.join(base_dir, name)
return os.path.exists(filepath)

View File

@ -141,18 +141,22 @@ export class ComfyApp {
{
content: "Copy (Clipspace)",
callback: (obj) => {
console.log(this);
var widgets = null;
if(this.widgets) {
widgets = this.widgets.map(({ type, name, value }) => ({ type, name, value }));
}
let img = new Image();
img.src = this.imgs[0].src;
var imgs = undefined;
if(this.imgs != undefined) {
img.src = this.imgs[0].src;
imgs = [img];
}
ComfyApp.clipspace = {
'widgets': widgets,
'imgs': [img],
'original_imgs': [img],
'imgs': imgs,
'original_imgs': imgs,
'images': this.images
};
}
@ -161,8 +165,7 @@ export class ComfyApp {
content: "Paste (Clipspace)",
callback: () => {
if(ComfyApp.clipspace != null) {
console.log(ComfyApp.clipspace.widgets);
if(ComfyApp.clipspace.widgets != null) {
if(ComfyApp.clipspace.widgets != null && this.widgets != null) {
ComfyApp.clipspace.widgets.forEach(({ type, name, value }) => {
const prop = Object.values(this.widgets).find(obj => obj.type === type && obj.name === name);
if (prop) {
@ -171,12 +174,27 @@ export class ComfyApp {
});
}
if(ComfyApp.clipspace.imgs != undefined && this.imgs != undefined) {
this.imgs = ComfyApp.clipspace.imgs;
this.images = ComfyApp.clipspace.images;
// image paste
if(ComfyApp.clipspace.imgs != undefined && this.imgs != undefined && this.widgets != null) {
var filename = "";
if(this.images && ComfyApp.clipspace.images) {
this.images = ComfyApp.clipspace.images;
}
if(ComfyApp.clipspace.images != undefined) {
filename = `${ComfyApp.clipspace.images[0].filename} [${ComfyApp.clipspace.images[0].type}]`;
}
else if(ComfyApp.clipspace.widgets != undefined) {
const index_in_clip = ComfyApp.clipspace.widgets.findIndex(obj => obj.name === 'image');
if(index_in_clip >= 0) {
filename = `${ComfyApp.clipspace.widgets[index_in_clip].value}`;
}
}
const index = this.widgets.findIndex(obj => obj.name === 'image');
if(index >= 0) {
let filename = `${this.images[0].filename} [${this.images[0].type}]`;
if(index >= 0 && filename != "" && ComfyApp.clipspace.imgs != undefined) {
this.imgs = ComfyApp.clipspace.imgs;
this.widgets[index].value = filename;
if(this.widgets_values != undefined) {
this.widgets_values[index] = filename;