fix latent loader bug and add .latent temp folder support for make it more safe
This commit is contained in:
+4
-1
@@ -14,8 +14,10 @@ app.registerExtension({
|
||||
const uploadFile = async (file) => {
|
||||
try {
|
||||
const body = new FormData();
|
||||
// 将文件上传到临时目录,以避免覆盖问题
|
||||
body.append("image", file);
|
||||
body.append("overwrite", "true");
|
||||
body.append("type", "temp"); // <--- 添加这一行
|
||||
const resp = await api.fetchApi("/upload/image", {
|
||||
method: "POST",
|
||||
body,
|
||||
@@ -23,7 +25,8 @@ app.registerExtension({
|
||||
|
||||
if (resp.status === 200) {
|
||||
const data = await resp.json();
|
||||
const path = data.subfolder ? `${data.subfolder}/${data.name}` : data.name;
|
||||
// 确保路径包含了 subfolder 和 type
|
||||
const path = `${data.type}/${data.subfolder ? `${data.subfolder}/` : ''}${data.name}`;
|
||||
const textWidget = this.widgets.find((w) => w.name === "latent_file");
|
||||
if (textWidget) {
|
||||
textWidget.value = path;
|
||||
|
||||
+11
-2
@@ -22,9 +22,18 @@ class LatentLoaderAdvanced:
|
||||
CATEGORY = "ComfyUI-Only/Latent"
|
||||
|
||||
def load_latent(self, latent_file):
|
||||
latent_path = folder_paths.get_annotated_filepath(latent_file)
|
||||
if latent_file.startswith("temp/"):
|
||||
filename = latent_file[len("temp/"):]
|
||||
# 直接、安全地构建临时文件的完整路径
|
||||
temp_dir = folder_paths.get_temp_directory()
|
||||
latent_path = os.path.abspath(os.path.join(temp_dir, filename))
|
||||
# 安全检查:确保最终路径在 temp 目录内,防止目录遍历攻击
|
||||
if not latent_path.startswith(os.path.abspath(temp_dir)):
|
||||
raise FileNotFoundError(f"Invalid path specified: {latent_file}")
|
||||
else:
|
||||
latent_path = folder_paths.get_annotated_filepath(latent_file)
|
||||
|
||||
if not os.path.exists(latent_path):
|
||||
if not latent_path or not os.path.exists(latent_path):
|
||||
raise FileNotFoundError(f"File not found at path: {latent_path}.")
|
||||
|
||||
latent_data = None
|
||||
|
||||
Reference in New Issue
Block a user