mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-25 04:34:06 -08:00
Clean up auth parameter
This commit is contained in:
parent
49001ce789
commit
36c3fb2039
|
@ -10,7 +10,6 @@ import {
|
|||
import {
|
||||
OptionsWithUri,
|
||||
} from 'request';
|
||||
import { queryString } from '../TheHive/QueryFunctions';
|
||||
|
||||
|
||||
/**
|
||||
|
@ -22,15 +21,17 @@ export async function redditApiRequest(
|
|||
endpoint: string,
|
||||
qs: IDataObject,
|
||||
body: IDataObject,
|
||||
noAuth: boolean,
|
||||
): Promise<any> { // tslint:disable-line:no-any
|
||||
|
||||
const resource = this.getNodeParameter('resource', 0) as string;
|
||||
const requiresAuth = ['myAccount', 'submission'].includes(resource);
|
||||
|
||||
const options: OptionsWithUri = {
|
||||
headers: {
|
||||
'user-agent': 'n8n',
|
||||
},
|
||||
method,
|
||||
uri: noAuth ? `https://www.reddit.com/${endpoint}` : `https://oauth.reddit.com/api/v1/${endpoint}`,
|
||||
uri: requiresAuth ? `https://oauth.reddit.com/api/v1/${endpoint}` : `https://www.reddit.com/${endpoint}`,
|
||||
qs,
|
||||
body,
|
||||
json: true,
|
||||
|
@ -45,9 +46,10 @@ export async function redditApiRequest(
|
|||
}
|
||||
|
||||
try {
|
||||
return noAuth
|
||||
? await this.helpers.request.call(this, options)
|
||||
: await this.helpers.requestOAuth2.call(this, 'redditOAuth2Api', options);
|
||||
return requiresAuth
|
||||
? await this.helpers.requestOAuth2.call(this, 'redditOAuth2Api', options)
|
||||
: await this.helpers.request.call(this, options);
|
||||
|
||||
} catch (error) {
|
||||
if (error.message) {
|
||||
const errorObject = JSON.parse(error.message.match(/{.*}/)[0]);
|
||||
|
@ -67,14 +69,13 @@ export async function redditApiRequestAllItems(
|
|||
endpoint: string,
|
||||
qs: IDataObject,
|
||||
body: IDataObject,
|
||||
noAuth: boolean,
|
||||
): Promise<any> { // tslint:disable-line:no-any
|
||||
|
||||
let responseData;
|
||||
const returnData: IDataObject[] = [];
|
||||
|
||||
do {
|
||||
responseData = await redditApiRequest.call(this, method, endpoint, qs, body, noAuth);
|
||||
responseData = await redditApiRequest.call(this, method, endpoint, qs, body);
|
||||
qs.after = responseData.after;
|
||||
responseData.data.children.forEach((child: any) => returnData.push(child.data)); // tslint:disable-line:no-any
|
||||
|
||||
|
@ -99,13 +100,13 @@ export async function handleListing(
|
|||
|
||||
const returnAll = this.getNodeParameter('returnAll', i);
|
||||
if (returnAll) {
|
||||
return await redditApiRequestAllItems.call(this, 'GET', endpoint, {}, {}, true);
|
||||
return await redditApiRequestAllItems.call(this, 'GET', endpoint, {}, {});
|
||||
}
|
||||
|
||||
const qs: IDataObject = {
|
||||
limit: this.getNodeParameter('limit', i),
|
||||
};
|
||||
responseData = await redditApiRequestAllItems.call(this, 'GET', endpoint, qs, {}, true);
|
||||
responseData = await redditApiRequestAllItems.call(this, 'GET', endpoint, qs, {});
|
||||
responseData = responseData.splice(0, qs.limit);
|
||||
|
||||
return responseData;
|
||||
|
|
|
@ -12,7 +12,6 @@ import {
|
|||
import {
|
||||
handleListing,
|
||||
redditApiRequest,
|
||||
redditApiRequestAllItems,
|
||||
} from './GenericFunctions';
|
||||
|
||||
import {
|
||||
|
@ -129,7 +128,7 @@ export class Reddit implements INodeType {
|
|||
if (information === 'trending') {
|
||||
|
||||
const endpoint = 'api/trending_subreddits.json';
|
||||
responseData = await redditApiRequest.call(this, 'GET', endpoint, {}, {}, true);
|
||||
responseData = await redditApiRequest.call(this, 'GET', endpoint, {}, {});
|
||||
|
||||
} else {
|
||||
|
||||
|
@ -153,7 +152,7 @@ export class Reddit implements INodeType {
|
|||
};
|
||||
|
||||
const details = this.getNodeParameter('details', i) as string;
|
||||
responseData = await redditApiRequest.call(this, 'GET', endpoints[details], {}, {}, false);
|
||||
responseData = await redditApiRequest.call(this, 'GET', endpoints[details], {}, {});
|
||||
|
||||
if (details === 'identity') {
|
||||
responseData = responseData.features;
|
||||
|
@ -181,7 +180,7 @@ export class Reddit implements INodeType {
|
|||
body.resubmit = true;
|
||||
}
|
||||
|
||||
responseData = await redditApiRequest.call(this, 'POST', 'submit', {}, body, false);
|
||||
responseData = await redditApiRequest.call(this, 'POST', 'submit', {}, body);
|
||||
|
||||
}
|
||||
|
||||
|
@ -197,7 +196,7 @@ export class Reddit implements INodeType {
|
|||
if (['about', 'rules', 'sidebar', 'sticky'].includes(content)) {
|
||||
|
||||
const endpoint = `r/${subreddit}/about/${content}.json`;
|
||||
responseData = await redditApiRequest.call(this, 'GET', endpoint, qs, {}, true);
|
||||
responseData = await redditApiRequest.call(this, 'GET', endpoint, qs, {});
|
||||
|
||||
if (content === 'rules') {
|
||||
responseData = responseData.rules;
|
||||
|
@ -217,7 +216,7 @@ export class Reddit implements INodeType {
|
|||
query: this.getNodeParameter('keyword', i),
|
||||
};
|
||||
|
||||
responseData = await redditApiRequest.call(this, 'GET', endpoint, qs, {}, true);
|
||||
responseData = await redditApiRequest.call(this, 'GET', endpoint, qs, {});
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue