mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
🚚 Directorize and alphabetize nodes (#2445)
* 🚚 Directorize nodes * ⚡ Alphabetize nodes and credentials * 🔥 Remove unused node * 🔥 Remove unused codex * 🔥 Remove duplicate cred file references * 🐛 Fix node file paths * 🔥 Remove duplicate node reference
This commit is contained in:
75
packages/nodes-base/nodes/ReadPdf/ReadPdf.node.ts
Normal file
75
packages/nodes-base/nodes/ReadPdf/ReadPdf.node.ts
Normal file
@@ -0,0 +1,75 @@
|
||||
import {
|
||||
BINARY_ENCODING,
|
||||
IExecuteFunctions,
|
||||
} from 'n8n-core';
|
||||
|
||||
import {
|
||||
INodeExecutionData,
|
||||
INodeType,
|
||||
INodeTypeDescription,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
const pdf = require('pdf-parse');
|
||||
|
||||
export class ReadPdf implements INodeType {
|
||||
description: INodeTypeDescription = {
|
||||
displayName: 'Read PDF',
|
||||
name: 'readPDF',
|
||||
icon: 'fa:file-pdf',
|
||||
group: ['input'],
|
||||
version: 1,
|
||||
description: 'Reads a PDF and extracts its content',
|
||||
defaults: {
|
||||
name: 'Read PDF',
|
||||
color: '#003355',
|
||||
},
|
||||
inputs: ['main'],
|
||||
outputs: ['main'],
|
||||
properties: [
|
||||
{
|
||||
displayName: 'Binary Property',
|
||||
name: 'binaryPropertyName',
|
||||
type: 'string',
|
||||
default: 'data',
|
||||
required: true,
|
||||
description: 'Name of the binary property from which to read the PDF file.',
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
||||
const items = this.getInputData();
|
||||
|
||||
const returnData: INodeExecutionData[] = [];
|
||||
const length = items.length as unknown as number;
|
||||
let item: INodeExecutionData;
|
||||
|
||||
for (let itemIndex = 0; itemIndex < length; itemIndex++) {
|
||||
|
||||
try{
|
||||
|
||||
item = items[itemIndex];
|
||||
const binaryPropertyName = this.getNodeParameter('binaryPropertyName', itemIndex) as string;
|
||||
|
||||
if (item.binary === undefined) {
|
||||
item.binary = {};
|
||||
}
|
||||
|
||||
const binaryData = Buffer.from(item.binary[binaryPropertyName].data, BINARY_ENCODING);
|
||||
returnData.push({
|
||||
binary: item.binary,
|
||||
json: await pdf(binaryData),
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
if (this.continueOnFail()) {
|
||||
returnData.push({json:{ error: error.message }});
|
||||
continue;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
return this.prepareOutputData(returnData);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user