mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-25 04:34:06 -08:00
⚡ Add Free API support to DeepL Node (#1810)
This commit is contained in:
parent
1ec916e530
commit
07a9108e46
|
@ -11,5 +11,21 @@ export class DeepLApi implements ICredentialType {
|
||||||
type: 'string' as NodePropertyTypes,
|
type: 'string' as NodePropertyTypes,
|
||||||
default: '',
|
default: '',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
displayName: 'API Plan',
|
||||||
|
name: 'apiPlan',
|
||||||
|
type: 'options' as NodePropertyTypes,
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
name: 'Pro Plan',
|
||||||
|
value: 'pro',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Free Plan',
|
||||||
|
value: 'free',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
default: 'pro',
|
||||||
|
},
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,15 @@ export async function deepLApiRequest(
|
||||||
headers: IDataObject = {},
|
headers: IDataObject = {},
|
||||||
) {
|
) {
|
||||||
|
|
||||||
|
const proApiEndpoint = 'https://api.deepl.com/v2';
|
||||||
|
const freeApiEndpoint = 'https://api-free.deepl.com/v2';
|
||||||
|
|
||||||
|
const credentials = this.getCredentials('deepLApi');
|
||||||
|
|
||||||
|
if (credentials === undefined) {
|
||||||
|
throw new NodeOperationError(this.getNode(), 'No credentials got returned!');
|
||||||
|
}
|
||||||
|
|
||||||
const options: OptionsWithUri = {
|
const options: OptionsWithUri = {
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
|
@ -29,7 +38,7 @@ export async function deepLApiRequest(
|
||||||
method,
|
method,
|
||||||
body,
|
body,
|
||||||
qs,
|
qs,
|
||||||
uri: uri || `https://api.deepl.com/v2${resource}`,
|
uri: uri || `${credentials.apiPlan === 'pro' ? proApiEndpoint : freeApiEndpoint}${resource}`,
|
||||||
json: true,
|
json: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -42,12 +51,6 @@ export async function deepLApiRequest(
|
||||||
delete options.body;
|
delete options.body;
|
||||||
}
|
}
|
||||||
|
|
||||||
const credentials = this.getCredentials('deepLApi');
|
|
||||||
|
|
||||||
if (credentials === undefined) {
|
|
||||||
throw new NodeOperationError(this.getNode(), 'No credentials got returned!');
|
|
||||||
}
|
|
||||||
|
|
||||||
options.qs.auth_key = credentials.apiKey;
|
options.qs.auth_key = credentials.apiKey;
|
||||||
|
|
||||||
return await this.helpers.request!(options);
|
return await this.helpers.request!(options);
|
||||||
|
|
Loading…
Reference in a new issue