mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
feat(Brandfetch Node): Update to use new API (#10877)
This commit is contained in:
@@ -2,10 +2,11 @@ import type {
|
||||
IDataObject,
|
||||
IExecuteFunctions,
|
||||
IHookFunctions,
|
||||
ILoadOptionsFunctions,
|
||||
JsonObject,
|
||||
IRequestOptions,
|
||||
IHttpRequestMethods,
|
||||
IRequestOptions,
|
||||
ILoadOptionsFunctions,
|
||||
INodeExecutionData,
|
||||
JsonObject,
|
||||
} from 'n8n-workflow';
|
||||
import { NodeApiError } from 'n8n-workflow';
|
||||
|
||||
@@ -13,22 +14,17 @@ export async function brandfetchApiRequest(
|
||||
this: IHookFunctions | IExecuteFunctions | ILoadOptionsFunctions,
|
||||
method: IHttpRequestMethods,
|
||||
resource: string,
|
||||
|
||||
body: any = {},
|
||||
qs: IDataObject = {},
|
||||
uri?: string,
|
||||
option: IDataObject = {},
|
||||
): Promise<any> {
|
||||
try {
|
||||
const credentials = await this.getCredentials('brandfetchApi');
|
||||
let options: IRequestOptions = {
|
||||
headers: {
|
||||
'x-api-key': credentials.apiKey,
|
||||
},
|
||||
method,
|
||||
method: method as IHttpRequestMethods,
|
||||
qs,
|
||||
body,
|
||||
uri: uri || `https://api.brandfetch.io/v1${resource}`,
|
||||
url: uri || `https://api.brandfetch.io/v2${resource}`,
|
||||
json: true,
|
||||
};
|
||||
|
||||
@@ -45,7 +41,11 @@ export async function brandfetchApiRequest(
|
||||
delete options.qs;
|
||||
}
|
||||
|
||||
const response = await this.helpers.request(options);
|
||||
const response = await this.helpers.requestWithAuthentication.call(
|
||||
this,
|
||||
'brandfetchApi',
|
||||
options,
|
||||
);
|
||||
|
||||
if (response.statusCode && response.statusCode !== 200) {
|
||||
throw new NodeApiError(this.getNode(), response as JsonObject);
|
||||
@@ -56,3 +56,22 @@ export async function brandfetchApiRequest(
|
||||
throw new NodeApiError(this.getNode(), error as JsonObject);
|
||||
}
|
||||
}
|
||||
|
||||
export async function fetchAndPrepareBinaryData(
|
||||
this: IExecuteFunctions,
|
||||
imageType: string,
|
||||
imageFormat: string,
|
||||
logoFormats: IDataObject,
|
||||
domain: string,
|
||||
newItem: INodeExecutionData,
|
||||
) {
|
||||
const data = await brandfetchApiRequest.call(this, 'GET', '', {}, {}, logoFormats.src as string, {
|
||||
json: false,
|
||||
encoding: null,
|
||||
});
|
||||
|
||||
newItem.binary![`${imageType}_${imageFormat}`] = await this.helpers.prepareBinaryData(
|
||||
Buffer.from(data),
|
||||
`${imageType}_${domain}.${imageFormat}`,
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user