mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-02-09 21:12:36 +08:00
robust patch & refactoring folder_paths about annotated_filepath
This commit is contained in:
parent
2c21210c72
commit
4d93ef8a0a
@ -70,7 +70,7 @@ def get_directory_by_type(type_name):
|
|||||||
|
|
||||||
# determine base_dir rely on annotation if name is 'filename.ext [annotation]' format
|
# determine base_dir rely on annotation if name is 'filename.ext [annotation]' format
|
||||||
# otherwise use default_path as base_dir
|
# otherwise use default_path as base_dir
|
||||||
def get_annotated_filepath(name, default_dir=None):
|
def touch_annotated_filepath(name):
|
||||||
if name.endswith("[output]"):
|
if name.endswith("[output]"):
|
||||||
base_dir = get_output_directory()
|
base_dir = get_output_directory()
|
||||||
name = name[:-9]
|
name = name[:-9]
|
||||||
@ -80,24 +80,29 @@ def get_annotated_filepath(name, default_dir=None):
|
|||||||
elif name.endswith("[temp]"):
|
elif name.endswith("[temp]"):
|
||||||
base_dir = get_temp_directory()
|
base_dir = get_temp_directory()
|
||||||
name = name[:-7]
|
name = name[:-7]
|
||||||
elif default_dir is not None:
|
|
||||||
base_dir = default_dir
|
|
||||||
else:
|
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)
|
return os.path.join(base_dir, name)
|
||||||
|
|
||||||
|
|
||||||
def exists_annotated_filepath(name):
|
def exists_annotated_filepath(name):
|
||||||
if name.endswith("[output]"):
|
name, base_dir = touch_annotated_filepath(name)
|
||||||
base_dir = get_output_directory()
|
|
||||||
name = name[:-9]
|
if base_dir is None:
|
||||||
elif name.endswith("[temp]"):
|
base_dir = get_input_directory() # fallback path
|
||||||
base_dir = get_temp_directory()
|
|
||||||
name = name[:-7]
|
|
||||||
else:
|
|
||||||
base_dir = get_input_directory()
|
|
||||||
name = name[:-8]
|
|
||||||
|
|
||||||
filepath = os.path.join(base_dir, name)
|
filepath = os.path.join(base_dir, name)
|
||||||
return os.path.exists(filepath)
|
return os.path.exists(filepath)
|
||||||
|
|||||||
@ -141,18 +141,22 @@ export class ComfyApp {
|
|||||||
{
|
{
|
||||||
content: "Copy (Clipspace)",
|
content: "Copy (Clipspace)",
|
||||||
callback: (obj) => {
|
callback: (obj) => {
|
||||||
console.log(this);
|
|
||||||
var widgets = null;
|
var widgets = null;
|
||||||
if(this.widgets) {
|
if(this.widgets) {
|
||||||
widgets = this.widgets.map(({ type, name, value }) => ({ type, name, value }));
|
widgets = this.widgets.map(({ type, name, value }) => ({ type, name, value }));
|
||||||
}
|
}
|
||||||
|
|
||||||
let img = new Image();
|
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 = {
|
ComfyApp.clipspace = {
|
||||||
'widgets': widgets,
|
'widgets': widgets,
|
||||||
'imgs': [img],
|
'imgs': imgs,
|
||||||
'original_imgs': [img],
|
'original_imgs': imgs,
|
||||||
'images': this.images
|
'images': this.images
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -161,8 +165,7 @@ export class ComfyApp {
|
|||||||
content: "Paste (Clipspace)",
|
content: "Paste (Clipspace)",
|
||||||
callback: () => {
|
callback: () => {
|
||||||
if(ComfyApp.clipspace != null) {
|
if(ComfyApp.clipspace != null) {
|
||||||
console.log(ComfyApp.clipspace.widgets);
|
if(ComfyApp.clipspace.widgets != null && this.widgets != null) {
|
||||||
if(ComfyApp.clipspace.widgets != null) {
|
|
||||||
ComfyApp.clipspace.widgets.forEach(({ type, name, value }) => {
|
ComfyApp.clipspace.widgets.forEach(({ type, name, value }) => {
|
||||||
const prop = Object.values(this.widgets).find(obj => obj.type === type && obj.name === name);
|
const prop = Object.values(this.widgets).find(obj => obj.type === type && obj.name === name);
|
||||||
if (prop) {
|
if (prop) {
|
||||||
@ -171,12 +174,27 @@ export class ComfyApp {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if(ComfyApp.clipspace.imgs != undefined && this.imgs != undefined) {
|
// image paste
|
||||||
this.imgs = ComfyApp.clipspace.imgs;
|
if(ComfyApp.clipspace.imgs != undefined && this.imgs != undefined && this.widgets != null) {
|
||||||
this.images = ComfyApp.clipspace.images;
|
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');
|
const index = this.widgets.findIndex(obj => obj.name === 'image');
|
||||||
if(index >= 0) {
|
if(index >= 0 && filename != "" && ComfyApp.clipspace.imgs != undefined) {
|
||||||
let filename = `${this.images[0].filename} [${this.images[0].type}]`;
|
this.imgs = ComfyApp.clipspace.imgs;
|
||||||
|
|
||||||
this.widgets[index].value = filename;
|
this.widgets[index].value = filename;
|
||||||
if(this.widgets_values != undefined) {
|
if(this.widgets_values != undefined) {
|
||||||
this.widgets_values[index] = filename;
|
this.widgets_values[index] = filename;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user