mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
⚡ Small changes to Twitter-Node
This commit is contained in:
parent
d17d18ceb6
commit
e3a6064196
|
@ -988,7 +988,7 @@ class App {
|
||||||
throw new Error('Insufficient parameters for OAuth1 callback');
|
throw new Error('Insufficient parameters for OAuth1 callback');
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await Db.collections.Credentials!.findOne(cid as any);
|
const result = await Db.collections.Credentials!.findOne(cid as any); // tslint:disable-line:no-any
|
||||||
if (result === undefined) {
|
if (result === undefined) {
|
||||||
const errorResponse = new ResponseHelper.ResponseError('The credential is not known.', undefined, 404);
|
const errorResponse = new ResponseHelper.ResponseError('The credential is not known.', undefined, 404);
|
||||||
return ResponseHelper.sendErrorResponse(res, errorResponse);
|
return ResponseHelper.sendErrorResponse(res, errorResponse);
|
||||||
|
@ -1041,7 +1041,7 @@ class App {
|
||||||
// Add special database related data
|
// Add special database related data
|
||||||
newCredentialsData.updatedAt = this.getCurrentDate();
|
newCredentialsData.updatedAt = this.getCurrentDate();
|
||||||
// Save the credentials in DB
|
// Save the credentials in DB
|
||||||
await Db.collections.Credentials!.update(cid as any, newCredentialsData);
|
await Db.collections.Credentials!.update(cid as any, newCredentialsData); // tslint:disable-line:no-any
|
||||||
|
|
||||||
res.sendFile(pathResolve(__dirname, '../../templates/oauth-callback.html'));
|
res.sendFile(pathResolve(__dirname, '../../templates/oauth-callback.html'));
|
||||||
});
|
});
|
||||||
|
|
|
@ -219,14 +219,11 @@ export default mixins(
|
||||||
return this.credentialDataTemp;
|
return this.credentialDataTemp;
|
||||||
},
|
},
|
||||||
isOAuthType (): boolean {
|
isOAuthType (): boolean {
|
||||||
if (this.credentialTypeData.name === 'oAuth2Api') {
|
if (['oAuth1Api', 'oAuth2Api'].includes(this.credentialTypeData.name)) {
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (this.credentialTypeData.name === 'oAuth1Api') {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
const types = this.parentTypes(this.credentialTypeData.name);
|
const types = this.parentTypes(this.credentialTypeData.name);
|
||||||
return types.includes('oAuth2Api') || types.includes('oAuth1Api');
|
return types.includes('oAuth1Api') || types.includes('oAuth2Api');
|
||||||
},
|
},
|
||||||
isOAuthConnected (): boolean {
|
isOAuthConnected (): boolean {
|
||||||
if (this.isOAuthType === false) {
|
if (this.isOAuthType === false) {
|
||||||
|
|
|
@ -78,53 +78,15 @@ export const tweetFields = [
|
||||||
},
|
},
|
||||||
options: [
|
options: [
|
||||||
{
|
{
|
||||||
name: 'attachmentsValues',
|
name: 'attachment',
|
||||||
displayName: 'Attachments Values',
|
displayName: 'Attachment',
|
||||||
values: [
|
values: [
|
||||||
{
|
{
|
||||||
displayName: 'Data',
|
displayName: 'Binary Property',
|
||||||
name: 'data',
|
name: 'binaryPropertyName',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
default: '',
|
default: '',
|
||||||
description: 'The base64-encoded file content being uploaded.',
|
description: 'Name of the binary properties which contain data which should be added to tweet as attachment',
|
||||||
},
|
|
||||||
{
|
|
||||||
displayName: 'Category',
|
|
||||||
name: 'category',
|
|
||||||
type: 'options',
|
|
||||||
options: [
|
|
||||||
{
|
|
||||||
name: 'Amplify Video',
|
|
||||||
value: 'amplifyVideo',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'Gif',
|
|
||||||
value: 'tweetGif',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'Image',
|
|
||||||
value: 'tweetImage',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'Video',
|
|
||||||
value: 'tweetVideo',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
default: '',
|
|
||||||
description: 'The category that represents how the media will be used',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'attachmentsBinary',
|
|
||||||
displayName: 'Attachments Binary',
|
|
||||||
values: [
|
|
||||||
{
|
|
||||||
displayName: 'Property',
|
|
||||||
name: 'property',
|
|
||||||
type: 'string',
|
|
||||||
default: '',
|
|
||||||
description: 'Name of the binary properties which contain data which should be added to email as attachment',
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
displayName: 'Category',
|
displayName: 'Category',
|
||||||
|
|
|
@ -73,7 +73,6 @@ export class Twitter implements INodeType {
|
||||||
const items = this.getInputData();
|
const items = this.getInputData();
|
||||||
const returnData: IDataObject[] = [];
|
const returnData: IDataObject[] = [];
|
||||||
const length = items.length as unknown as number;
|
const length = items.length as unknown as number;
|
||||||
const qs: IDataObject = {};
|
|
||||||
let responseData;
|
let responseData;
|
||||||
const resource = this.getNodeParameter('resource', 0) as string;
|
const resource = this.getNodeParameter('resource', 0) as string;
|
||||||
const operation = this.getNodeParameter('operation', 0) as string;
|
const operation = this.getNodeParameter('operation', 0) as string;
|
||||||
|
@ -86,49 +85,43 @@ export class Twitter implements INodeType {
|
||||||
const body: ITweet = {
|
const body: ITweet = {
|
||||||
status: text,
|
status: text,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (additionalFields.attachmentsUi) {
|
if (additionalFields.attachmentsUi) {
|
||||||
const mediaIds = [];
|
const mediaIds = [];
|
||||||
const attachmentsUi = additionalFields.attachmentsUi as IDataObject;
|
const attachmentsUi = additionalFields.attachmentsUi as IDataObject;
|
||||||
const uploadUri = 'https://upload.twitter.com/1.1/media/upload.json';
|
const uploadUri = 'https://upload.twitter.com/1.1/media/upload.json';
|
||||||
if (attachmentsUi.attachmentsValues) {
|
|
||||||
const attachtments = attachmentsUi.attachmentsValues as IDataObject[];
|
if (attachmentsUi.attachment) {
|
||||||
for (const attachment of attachtments) {
|
const attachtments = attachmentsUi.attachment as IDataObject[];
|
||||||
const body = {
|
|
||||||
media_data: attachment.data,
|
|
||||||
media_category: snakeCase(attachment.category as string).toUpperCase(),
|
|
||||||
};
|
|
||||||
const response = await twitterApiRequest.call(this, 'POST', '', body, {}, uploadUri);
|
|
||||||
mediaIds.push(response.media_id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (attachmentsUi.attachmentsBinary) {
|
|
||||||
const attachtments = attachmentsUi.attachmentsBinary as IDataObject[];
|
|
||||||
for (const attachment of attachtments) {
|
for (const attachment of attachtments) {
|
||||||
|
|
||||||
const binaryData = items[i].binary as IBinaryKeyData;
|
const binaryData = items[i].binary as IBinaryKeyData;
|
||||||
const propertyName = attachment.property as string;
|
const binaryPropertyName = attachment.binaryPropertyName as string;
|
||||||
|
|
||||||
if (binaryData === undefined) {
|
if (binaryData === undefined) {
|
||||||
throw new Error('No binary data set. So file can not be written!');
|
throw new Error('No binary data set. So file can not be written!');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!binaryData[propertyName]) {
|
if (!binaryData[binaryPropertyName]) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const body = {
|
const attachmentBody = {
|
||||||
media_data: binaryData[propertyName].data,
|
media_data: binaryData[binaryPropertyName].data,
|
||||||
media_category: snakeCase(attachment.category as string).toUpperCase(),
|
media_category: snakeCase(attachment.category as string).toUpperCase(),
|
||||||
};
|
};
|
||||||
const response = await twitterApiRequest.call(this, 'POST', '', body, {}, uploadUri);
|
const response = await twitterApiRequest.call(this, 'POST', '', attachmentBody, {}, uploadUri);
|
||||||
mediaIds.push(response.media_id_string);
|
mediaIds.push(response.media_id_string);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
body.media_ids = mediaIds.join(',');
|
body.media_ids = mediaIds.join(',');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (additionalFields.possiblySensitive) {
|
if (additionalFields.possiblySensitive) {
|
||||||
body.possibly_sensitive = additionalFields.possibly_sensitive as boolean;
|
body.possibly_sensitive = additionalFields.possibly_sensitive as boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (additionalFields.locationFieldsUi) {
|
if (additionalFields.locationFieldsUi) {
|
||||||
const locationUi = additionalFields.locationFieldsUi as IDataObject;
|
const locationUi = additionalFields.locationFieldsUi as IDataObject;
|
||||||
if (locationUi.locationFieldsValues) {
|
if (locationUi.locationFieldsValues) {
|
||||||
|
@ -137,6 +130,7 @@ export class Twitter implements INodeType {
|
||||||
body.long = parseFloat(values.lalatitude as string);
|
body.long = parseFloat(values.lalatitude as string);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
responseData = await twitterApiRequest.call(this, 'POST', '/statuses/update.json', body);
|
responseData = await twitterApiRequest.call(this, 'POST', '/statuses/update.json', body);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue