2020-10-19 04:45:33 -07:00
|
|
|
|
|
|
|
import {
|
|
|
|
IExecuteFunctions,
|
|
|
|
} from 'n8n-core';
|
|
|
|
|
|
|
|
import {
|
|
|
|
INodeExecutionData,
|
|
|
|
INodeType,
|
|
|
|
INodeTypeDescription,
|
|
|
|
} from 'n8n-workflow';
|
|
|
|
|
|
|
|
import {
|
|
|
|
googleApiRequest,
|
|
|
|
} from './GenericFunctions';
|
|
|
|
|
|
|
|
export interface IGoogleAuthCredentials {
|
|
|
|
email: string;
|
|
|
|
privateKey: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export class GoogleSlides implements INodeType {
|
|
|
|
description: INodeTypeDescription = {
|
|
|
|
displayName: 'Google Slides',
|
|
|
|
name: 'googleSlides',
|
|
|
|
icon: 'file:googleslides.svg',
|
|
|
|
group: ['input', 'output'],
|
|
|
|
version: 1,
|
2020-10-20 01:13:36 -07:00
|
|
|
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
|
2020-10-19 04:45:33 -07:00
|
|
|
description: 'Read data from Google Slides',
|
|
|
|
defaults: {
|
|
|
|
name: 'Google Slides',
|
2020-10-20 01:13:36 -07:00
|
|
|
color: '#edba25',
|
2020-10-19 04:45:33 -07:00
|
|
|
},
|
|
|
|
inputs: ['main'],
|
|
|
|
outputs: ['main'],
|
|
|
|
credentials: [
|
|
|
|
{
|
|
|
|
name: 'googleApi',
|
|
|
|
required: true,
|
|
|
|
displayOptions: {
|
|
|
|
show: {
|
|
|
|
authentication: [
|
|
|
|
'serviceAccount',
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'googleSlidesOAuth2Api',
|
|
|
|
required: true,
|
|
|
|
displayOptions: {
|
|
|
|
show: {
|
|
|
|
authentication: [
|
|
|
|
'oAuth2',
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
properties: [
|
|
|
|
{
|
|
|
|
displayName: 'Authentication',
|
|
|
|
name: 'authentication',
|
|
|
|
type: 'options',
|
|
|
|
options: [
|
|
|
|
{
|
|
|
|
name: 'Service Account',
|
|
|
|
value: 'serviceAccount',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'OAuth2',
|
|
|
|
value: 'oAuth2',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
default: 'serviceAccount',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
displayName: 'Resource',
|
|
|
|
name: 'resource',
|
|
|
|
type: 'options',
|
|
|
|
options: [
|
|
|
|
{
|
2020-10-20 01:13:36 -07:00
|
|
|
name: 'Presentation',
|
|
|
|
value: 'presentation',
|
2020-10-19 04:45:33 -07:00
|
|
|
},
|
|
|
|
{
|
2020-10-20 01:13:36 -07:00
|
|
|
name: 'Page',
|
|
|
|
value: 'page',
|
2020-10-19 04:45:33 -07:00
|
|
|
},
|
|
|
|
],
|
2020-10-20 01:13:36 -07:00
|
|
|
default: 'presentation',
|
2020-10-19 04:45:33 -07:00
|
|
|
description: 'The resource to operate on',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
displayName: 'Operation',
|
|
|
|
name: 'operation',
|
|
|
|
type: 'options',
|
|
|
|
options: [
|
|
|
|
{
|
|
|
|
name: 'Create',
|
|
|
|
value: 'create',
|
|
|
|
description: 'Create a presentation',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Get',
|
|
|
|
value: 'get',
|
|
|
|
description: 'Get a presentation',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
displayOptions: {
|
|
|
|
show: {
|
|
|
|
resource: [
|
2020-10-20 01:13:36 -07:00
|
|
|
'presentation',
|
2020-10-19 04:45:33 -07:00
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
default: 'create',
|
|
|
|
description: 'The operation to perform',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
displayName: 'Operation',
|
|
|
|
name: 'operation',
|
|
|
|
type: 'options',
|
|
|
|
options: [
|
|
|
|
{
|
|
|
|
name: 'Get',
|
|
|
|
value: 'get',
|
|
|
|
description: 'Get a page',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Get Thumbnail',
|
|
|
|
value: 'getThumbnail',
|
|
|
|
description: 'Get a thumbnail',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
displayOptions: {
|
|
|
|
show: {
|
|
|
|
resource: [
|
2020-10-20 01:13:36 -07:00
|
|
|
'page',
|
2020-10-19 04:45:33 -07:00
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
default: 'get',
|
|
|
|
description: 'The operation to perform',
|
|
|
|
},
|
|
|
|
|
|
|
|
// ----------------------------------
|
|
|
|
// All
|
|
|
|
// ----------------------------------
|
|
|
|
{
|
|
|
|
displayName: 'Title',
|
|
|
|
name: 'title',
|
|
|
|
type: 'string',
|
|
|
|
default: '',
|
|
|
|
required: true,
|
|
|
|
displayOptions: {
|
|
|
|
show: {
|
|
|
|
operation: [
|
|
|
|
'create',
|
|
|
|
],
|
|
|
|
resource: [
|
2020-10-20 01:13:36 -07:00
|
|
|
'presentation',
|
2020-10-19 04:45:33 -07:00
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
displayName: 'Presentation ID',
|
|
|
|
name: 'presentationId',
|
|
|
|
type: 'string',
|
|
|
|
default: '',
|
|
|
|
required: true,
|
|
|
|
displayOptions: {
|
|
|
|
show: {
|
|
|
|
operation: [
|
|
|
|
'get',
|
|
|
|
'getThumbnail'
|
|
|
|
],
|
|
|
|
resource: [
|
2020-10-20 01:13:36 -07:00
|
|
|
'presentation',
|
|
|
|
'page',
|
2020-10-19 04:45:33 -07:00
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
displayName: 'Page Object ID',
|
|
|
|
name: 'pageObjectId',
|
|
|
|
type: 'string',
|
|
|
|
default: '',
|
|
|
|
required: true,
|
|
|
|
displayOptions: {
|
|
|
|
show: {
|
|
|
|
operation: [
|
|
|
|
'get',
|
|
|
|
'getThumbnail',
|
|
|
|
],
|
|
|
|
resource: [
|
2020-10-20 01:13:36 -07:00
|
|
|
'page',
|
2020-10-19 04:45:33 -07:00
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
|
|
|
const items = this.getInputData();
|
|
|
|
const length = items.length as unknown as number;
|
|
|
|
|
|
|
|
const resource = this.getNodeParameter('resource', 0) as string;
|
|
|
|
const operation = this.getNodeParameter('operation', 0) as string;
|
|
|
|
const responseData = [];
|
|
|
|
|
|
|
|
for (let i=0; i < length; i++) {
|
2020-10-20 01:13:36 -07:00
|
|
|
if (resource === 'presentation') {
|
2020-10-19 04:45:33 -07:00
|
|
|
if (operation === 'create') {
|
|
|
|
const title = this.getNodeParameter('title', i) as string;
|
|
|
|
let body = {
|
|
|
|
"title": title
|
|
|
|
};
|
|
|
|
|
|
|
|
const response = await googleApiRequest.call(this, 'POST', `/v1/presentations`, body);
|
|
|
|
responseData.push(response);
|
|
|
|
} else if (operation === 'get') {
|
|
|
|
const presentationId = this.getNodeParameter('presentationId', i) as string;
|
|
|
|
|
|
|
|
const response = await googleApiRequest.call(this, 'GET', `/v1/presentations/${presentationId}`, {});
|
|
|
|
responseData.push(response);
|
|
|
|
}
|
2020-10-20 01:13:36 -07:00
|
|
|
} else if (resource === 'page') {
|
2020-10-19 04:45:33 -07:00
|
|
|
if (operation === 'get') {
|
|
|
|
const presentationId = this.getNodeParameter('presentationId', i) as string;
|
|
|
|
const pageObjectId = this.getNodeParameter('pageObjectId', i) as string;
|
|
|
|
|
|
|
|
const response = await googleApiRequest.call(this, 'GET', `/v1/presentations/${presentationId}/pages/${pageObjectId}`, {});
|
|
|
|
responseData.push(response);
|
|
|
|
} else if (operation === 'getThumbnail') {
|
|
|
|
const presentationId = this.getNodeParameter('presentationId', i) as string;
|
|
|
|
const pageObjectId = this.getNodeParameter('pageObjectId', i) as string;
|
|
|
|
|
|
|
|
const response = await googleApiRequest.call(this, 'GET', `/v1/presentations/${presentationId}/pages/${pageObjectId}/thumbnail`, {});
|
|
|
|
responseData.push(response);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return [this.helpers.returnJsonArray(responseData)];
|
|
|
|
}
|
|
|
|
}
|