n8n-nodes-comfyui-media
Version:
n8n node to integrate with ComfyUI stable diffusion workflows for image to video conversion
129 lines • 5.08 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ComfyuiMediaUpload = void 0;
const n8n_workflow_1 = require("n8n-workflow");
const form_data_1 = __importDefault(require("form-data"));
const apiClient_1 = require("./apiClient");
const inputProviders_1 = require("./inputProviders");
class ComfyuiMediaUpload {
constructor() {
this.description = {
displayName: 'ComfyUI Media Upload',
name: 'comfyuiMediaUpload',
icon: 'file:comfyui.svg',
group: ['transform'],
version: 1,
description: 'Media Upload to ComfyUI server',
defaults: {
name: 'ComfyUI Media Upload',
},
credentials: [
{
name: 'comfyUIApi',
required: true,
},
],
inputs: ['main'],
outputs: ['main'],
properties: [
{
displayName: 'Filename',
name: 'filename',
type: 'string',
default: '',
required: true,
description: 'The ComfyUI workflow in JSON format',
},
{
displayName: 'Input Type',
name: 'inputType',
type: 'options',
options: [
{ name: 'URL', value: 'url' },
{ name: 'Base64', value: 'base64' },
{ name: 'Binary', value: 'binary' }
],
default: 'url',
required: true,
},
{
displayName: 'Input Image',
name: 'inputImage',
type: 'string',
default: '',
required: true,
displayOptions: {
show: {
inputType: ['url', 'base64'],
},
},
description: 'URL or base64 data of the input image',
},
{
displayName: 'Binary Property',
name: 'binaryPropertyName',
type: 'string',
default: 'data',
required: true,
displayOptions: {
show: {
inputType: ['binary'],
},
},
description: 'Name of the binary property containing the image',
},
],
};
}
async execute() {
const api = new apiClient_1.N8nApiClient(this.helpers);
const credentials = await this.getCredentials('comfyUIApi');
const apiUrl = credentials.apiUrl;
const apiKey = credentials.apiKey;
const headers = { 'Content-Type': 'application/json' };
if (apiKey)
headers['Authorization'] = `Bearer ${apiKey}`;
const filename = this.getNodeParameter('filename', 0);
try {
const inputType = this.getNodeParameter('inputType', 0);
let provider;
if (inputType === 'url') {
const inputImage = this.getNodeParameter('inputImage', 0);
provider = new inputProviders_1.UrlInputProvider(api, inputImage);
}
else if (inputType === 'base64') {
const inputImage = this.getNodeParameter('inputImage', 0);
provider = new inputProviders_1.Base64InputProvider(inputImage);
}
else {
const binaryPropertyName = this.getNodeParameter('binaryPropertyName', 0);
provider = new inputProviders_1.BinaryInputProvider(this.helpers, binaryPropertyName, this.getInputData());
}
const buffer = await provider.getBuffer();
const formData = new form_data_1.default();
formData.append('image', buffer, filename);
formData.append('subfolder', '');
formData.append('overwrite', 'true');
const uploadResponse = await api.request({
method: 'POST',
url: `${apiUrl}/upload/image`,
headers: { ...headers, ...formData.getHeaders() },
body: formData,
});
const imageInfo = JSON.parse(uploadResponse);
return [[{
json: {
fileName: imageInfo.name,
}
}]];
}
catch (err) {
throw new n8n_workflow_1.NodeApiError(this.getNode(), { message: err.message });
}
}
}
exports.ComfyuiMediaUpload = ComfyuiMediaUpload;
//# sourceMappingURL=ComfyuiMediaUpload.node.js.map