Fix name of BambooHR node

This commit is contained in:
Jan Oberhauser
2022-01-22 18:48:58 +01:00
parent 88809936ee
commit bbf3c4c004
63 changed files with 52 additions and 52 deletions

View File

@@ -0,0 +1,42 @@
import {
FileProperties,
} from '../../Interfaces';
export const fileDownloadDescription: FileProperties = [
{
displayName: 'File ID',
name: 'fileId',
type: 'string',
required: true,
displayOptions: {
show: {
operation: [
'download',
],
resource: [
'file',
],
},
},
default: '',
description: 'ID of the file',
},
{
displayName: 'Put Output In Field',
name: 'output',
type: 'string',
default: 'data',
required: true,
description: 'The name of the output field to put the binary file data in',
displayOptions: {
show: {
operation: [
'download',
],
resource: [
'file',
],
},
},
},
];

View File

@@ -0,0 +1,59 @@
import {
IExecuteFunctions,
} from 'n8n-core';
import {
IDataObject,
INodeExecutionData,
} from 'n8n-workflow';
import {
apiRequest,
} from '../../../transport';
export async function download(this: IExecuteFunctions, index: number) {
const body: IDataObject = {};
const requestMethod = 'GET';
const items = this.getInputData();
//meta data
const fileId: string = this.getNodeParameter('fileId', index) as string;
const output: string = this.getNodeParameter('output', index) as string;
//endpoint
const endpoint = `files/${fileId}/`;
//response
const response = await apiRequest.call(this, requestMethod, endpoint, body, {} as IDataObject,
{ encoding: null, json: false, resolveWithFullResponse: true });
let mimeType = response.headers['content-type'] as string | undefined;
mimeType = mimeType ? mimeType.split(';').find(value => value.includes('/')) : undefined;
const contentDisposition = response.headers['content-disposition'];
const fileNameRegex = /(?<=filename=").*\b/;
const match = fileNameRegex.exec(contentDisposition);
let fileName = '';
// file name was found
if (match !== null) {
fileName = match[0];
}
const newItem: INodeExecutionData = {
json: items[index].json,
binary: {},
};
if (items[index].binary !== undefined) {
// Create a shallow copy of the binary data so that the old
// data references which do not get changed still stay behind
// but the incoming data does not get changed.
Object.assign(newItem.binary, items[index].binary);
}
newItem.binary = {
[output]: await this.helpers.prepareBinaryData(response.body as unknown as Buffer, fileName, mimeType),
};
return this.prepareOutputData(newItem as unknown as INodeExecutionData[]);
}

View File

@@ -0,0 +1,7 @@
import { download as execute } from './execute';
import { fileDownloadDescription as description } from './description';
export {
description,
execute,
};