A search_folder option has been added to Load Video to allow for video files to be loaded directly from temp, or output directories The date formatting support available on the Image save node has been added to the Video Combine node A typo in extension name, and several debugging lines have been cleaned
78 lines
2.6 KiB
JavaScript
78 lines
2.6 KiB
JavaScript
import { app } from "../../../scripts/app.js";
|
|
import { api } from '../../../scripts/api.js'
|
|
import { ComfyWidgets } from "../../../scripts/widgets.js"
|
|
|
|
function folderUpload(node, inputName, inputData, app) {
|
|
const directoryWidget = node.widgets.find((w) => w.name === "directory");
|
|
let uploadWidget;
|
|
|
|
var default_value = directoryWidget.value;
|
|
async function uploadFile(file) {
|
|
try {
|
|
// Wrap file in formdata so it includes filename
|
|
const body = new FormData();
|
|
const i = file.webkitRelativePath.lastIndexOf('/');
|
|
const subfolder = file.webkitRelativePath.slice(0,i+1)
|
|
const new_file = new File([file], file.name, {
|
|
type: file.type,
|
|
lastModified: file.lastModified,
|
|
});
|
|
body.append("image", new_file);
|
|
if (i > 0) {
|
|
body.append("subfolder", subfolder);
|
|
}
|
|
const resp = await api.fetchApi("/upload/image", {
|
|
method: "POST",
|
|
body,
|
|
});
|
|
|
|
if (resp.status === 200) {
|
|
const data = await resp.json();
|
|
// Add the new folder to the dropdown list and update the widget value
|
|
if (!directoryWidget.options.values.includes(data.subfolder)) {
|
|
directoryWidget.options.values.push(subfolder);
|
|
}
|
|
} else {
|
|
alert(resp.status + " - " + resp.statusText);
|
|
}
|
|
} catch (error) {
|
|
alert(error);
|
|
}
|
|
}
|
|
|
|
const fileInput = document.createElement("input");
|
|
Object.assign(fileInput, {
|
|
type: "file",
|
|
style: "display: none",
|
|
webkitdirectory: true,
|
|
onchange: async () => {
|
|
for(const file of fileInput.files) {
|
|
await uploadFile(file);
|
|
}
|
|
const directory = fileInput.files[0].webkitRelativePath
|
|
const i = directory.lastIndexOf('/');
|
|
if (i > 0) {
|
|
directoryWidget.value = directory.slice(0,directory.lastIndexOf('/'))
|
|
}
|
|
},
|
|
});
|
|
document.body.append(fileInput);
|
|
|
|
// Create the button widget for selecting the files
|
|
uploadWidget = node.addWidget("button", "choose folder to upload", "directory", () => {
|
|
fileInput.click();
|
|
});
|
|
uploadWidget.serialize = false;
|
|
return { widget: uploadWidget };
|
|
}
|
|
ComfyWidgets.FOLDERUPLOAD = folderUpload;
|
|
|
|
app.registerExtension({
|
|
name: "VideoHelperSuite.UploadFolder",
|
|
async beforeRegisterNodeDef(nodeType, nodeData, app) {
|
|
if (nodeData?.name == "VHS_LoadImages") {
|
|
nodeData.input.required.upload = ["FOLDERUPLOAD"];
|
|
}
|
|
},
|
|
});
|