1
1
mirror of https://github.com/n8n-io/n8n.git synced 2024-09-11 13:15:28 +03:00

added aditional input type, added option for image resolution

This commit is contained in:
michael-radency 2022-01-12 16:34:26 +02:00
parent 3136a79620
commit a00464588d

View File

@ -19,53 +19,105 @@ export class PageresNode implements INodeType {
},
inputs: ['main'],
outputs: ['main'],
properties: [
// Node properties which the user gets displayed and
// can change on the node.
{
displayName: 'Input Type',
name: 'inputType',
type: 'options',
options: [
{
name: 'Url',
value: 'urlSource',
},
{
name: 'HTML',
value: 'htmlSource',
},
],
default: 'urlSource',
description: 'The source to generate image.',
},
{
displayName: 'URL',
name: 'url',
name: 'imageSource',
type: 'string',
default: '',
placeholder: 'https://harshil.dev',
description: 'URL of the Website',
displayOptions: {
show: {
inputType: [
'urlSource',
],
},
},
},
{
displayName: 'Destination',
name: 'destination',
displayName: 'HTML Snippet',
name: 'imageSource',
type: 'string',
default: '',
placeholder: '/user/local/',
description: 'Download destination',
placeholder: '<div><p>Hello World!</p></div>',
description: 'HTML code',
displayOptions: {
show: {
inputType: [
'htmlSource',
],
},
},
},
{
displayName: 'Image Resolution',
name: 'imageResolution',
type: 'string',
default: '',
placeholder: '480x320',
description: 'Enter Image Resolution',
},
],
};
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
const items = this.getInputData();
const sourceType = this.getNodeParameter('inputType', 0) as string;
let item: INodeExecutionData;
let a: any;
let generatedImages: any;
let binaryProperty: string = 'data';
// Itterates over all input items and add the key "myString" with the
// value the parameter "myString" resolves to.
// (This could be a different value for each item in case it contains an expression)
console.log('Before Loop');
for (let i = 0; i < items.length; i++) {
let url = this.getNodeParameter('url', i, '') as string;
a = await new Pageres({ delay: 2 })
.src(url, ['480x320'], { crop: true })
// .src('data:text/html,<h1>Awesome!</h1>', ['1024x768'])
let imageSource:string = '';
let imageResolution = this.getNodeParameter('imageResolution', i, '') as string
if(sourceType === 'urlSource'){
imageSource = this.getNodeParameter('imageSource', i, '') as string;
} else {
const html = this.getNodeParameter('imageSource', i, '') as string
imageSource = `data:text/html,${html}`;
}
generatedImages = await new Pageres({ delay: 2 })
.src(imageSource, [imageResolution], { crop: true })
.run();
items[i].binary = items[i].binary ?? {};
items[i].binary![binaryProperty] = await this.helpers.prepareBinaryData(
a[0]
generatedImages[0]
);
items[i].binary![binaryProperty].fileName = 'fileName';
items[i].binary![binaryProperty].fileExtension = 'png';
console.log('Finished generating screenshots!');
item = items[i];
//item.json['myString'] = a;
}
return this.prepareOutputData(items);
}