mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
fix(Ghost Node): Fix post tags and add credential tests (#3278)
* Renamed Tag IDs to Tags and changed the value to tag.name * Updated credentials to use new system * Nodelinter changes
This commit is contained in:
committed by
GitHub
parent
7090a79b5d
commit
a14d85ea48
@@ -10,38 +10,30 @@ import {
|
||||
} from 'n8n-core';
|
||||
|
||||
import {
|
||||
IDataObject, NodeApiError,
|
||||
IDataObject,
|
||||
JsonObject,
|
||||
NodeApiError,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import jwt from 'jsonwebtoken';
|
||||
|
||||
export async function ghostApiRequest(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, method: string, endpoint: string, body: any = {}, query: IDataObject = {}, uri?: string): Promise<any> { // tslint:disable-line:no-any
|
||||
|
||||
const source = this.getNodeParameter('source', 0) as string;
|
||||
|
||||
let credentials;
|
||||
let version;
|
||||
let token;
|
||||
let credentialType;
|
||||
|
||||
if (source === 'contentApi') {
|
||||
//https://ghost.org/faq/api-versioning/
|
||||
version = 'v3';
|
||||
credentials = await this.getCredentials('ghostContentApi');
|
||||
query.key = credentials.apiKey as string;
|
||||
credentialType = 'ghostContentApi';
|
||||
} else {
|
||||
version = 'v2';
|
||||
credentials = await this.getCredentials('ghostAdminApi');
|
||||
// Create the token (including decoding secret)
|
||||
const [id, secret] = (credentials.apiKey as string).split(':');
|
||||
|
||||
token = jwt.sign({}, Buffer.from(secret, 'hex'), {
|
||||
keyid: id,
|
||||
algorithm: 'HS256',
|
||||
expiresIn: '5m',
|
||||
audience: `/${version}/admin/`,
|
||||
});
|
||||
credentialType = 'ghostAdminApi';
|
||||
}
|
||||
|
||||
credentials = await this.getCredentials(credentialType);
|
||||
|
||||
const options: OptionsWithUri = {
|
||||
method,
|
||||
qs: query,
|
||||
@@ -50,17 +42,10 @@ export async function ghostApiRequest(this: IHookFunctions | IExecuteFunctions |
|
||||
json: true,
|
||||
};
|
||||
|
||||
if (token) {
|
||||
options.headers = {
|
||||
Authorization: `Ghost ${token}`,
|
||||
};
|
||||
}
|
||||
|
||||
try {
|
||||
return await this.helpers.request!(options);
|
||||
|
||||
} catch (error) {
|
||||
throw new NodeApiError(this.getNode(), error);
|
||||
return await this.helpers.requestWithAuthentication.call(this, credentialType, options);
|
||||
} catch(error) {
|
||||
throw new NodeApiError(this.getNode(), error as JsonObject);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user