mirror of
https://github.com/justUmen/Bjornulf_custom_nodes.git
synced 2026-03-25 06:22:13 -03:00
0.77
This commit is contained in:
47
web/js/load_text.js
Normal file
47
web/js/load_text.js
Normal file
@@ -0,0 +1,47 @@
|
||||
import { app } from "../../../scripts/app.js";
|
||||
|
||||
app.registerExtension({
|
||||
name: "Bjornulf.LoadTextFromFolder",
|
||||
async nodeCreated(node) {
|
||||
if (node.comfyClass === "Bjornulf_LoadTextFromFolder") {
|
||||
// Add a refresh button widget
|
||||
// Assuming this is inside your node's setup function
|
||||
const refreshButton = node.addWidget(
|
||||
"button",
|
||||
"Refresh File List",
|
||||
null,
|
||||
() => {
|
||||
fetch("/get_text_files", {
|
||||
method: "POST",
|
||||
})
|
||||
.then((response) => response.json())
|
||||
.then((data) => {
|
||||
if (data.success) {
|
||||
// Update the dropdown with the new file list
|
||||
node.widgets[0].options.values = data.files; // Assuming the dropdown is the first widget
|
||||
node.widgets[0].value = data.files[0] || ""; // Set default value
|
||||
app.ui.dialog.show(
|
||||
"[LoadTextFromFolder] File list refreshed successfully!"
|
||||
);
|
||||
} else {
|
||||
app.ui.dialog.show(
|
||||
`[LoadTextFromFolder] Failed to refresh file list: ${
|
||||
data.error || "Unknown error"
|
||||
}`
|
||||
);
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error(
|
||||
"[LoadTextFromFolder] Error fetching text files:",
|
||||
error
|
||||
);
|
||||
app.ui.dialog.show(
|
||||
"[LoadTextFromFolder] An error occurred while refreshing the file list."
|
||||
);
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user