ADD 增加远程自定义编码读取文件节点

This commit is contained in:
kyj@bowong.ai 2025-03-21 16:54:10 +08:00
parent a6a30ca42b
commit 337bee24aa
2 changed files with 26 additions and 4 deletions

View File

@ -1,4 +1,4 @@
from .nodes.text import LoadText
from .nodes.text import *
from .nodes.traverse_folder import TraverseFolder
from .nodes.unload_all_models import UnloadAllModels
from .nodes.string_empty_judgement import StringEmptyJudgement
@ -24,7 +24,8 @@ NODE_CLASS_MAPPINGS = {
"StringEmptyJudgement": StringEmptyJudgement,
"unloadAllModels": UnloadAllModels,
"TraverseFolder": TraverseFolder,
"LoadTextCustom": LoadText
"LoadTextCustom": LoadTextLocal,
"LoadTextCustomOnline": LoadTextOnline
}
# A dictionary that contains the friendly/humanly readable titles for the nodes
@ -40,5 +41,6 @@ NODE_DISPLAY_NAME_MAPPINGS = {
"StringEmptyJudgement": "字符串是否为空",
"unloadAllModels": "卸载所有已加载模型",
"TraverseFolder": "遍历文件夹",
"LoadTextCustom": "读取文本文件"
"LoadTextCustom": "读取文本文件(本地)",
"LoadTextCustomOnline": "读取文本文件(线上)"
}

View File

@ -55,7 +55,7 @@ def get_file(root_dir, file):
return full_path
class LoadText:
class LoadTextLocal:
@classmethod
def INPUT_TYPES(s):
return {
@ -105,3 +105,23 @@ class LoadText:
def load(self, root_dir, file, encoding):
with open(get_file(root_dir,file), "r", encoding=encoding) as f:
return (f.read(),)
class LoadTextOnline:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"file_path":("STRING", {"default": "input/"}),
"encoding": ("STRING", {"default": "utf-8"}),
}
}
RETURN_TYPES = ("STRING",)
FUNCTION = "load"
CATEGORY = "不忘科技-自定义节点🚩"
def load(self, file_path, encoding):
with open(file_path, "r", encoding=encoding) as f:
return (f.read(),)