n8n/packages/nodes-base/nodes/Google/YouTube/YouTube.node.ts

1161 lines
30 KiB
TypeScript
Raw Normal View History

2020-07-01 19:54:51 -07:00
import {
2020-08-09 14:39:28 -07:00
BINARY_ENCODING,
IExecuteFunctions,
2020-07-01 19:54:51 -07:00
} from 'n8n-core';
import {
IDataObject,
ILoadOptionsFunctions,
INodeExecutionData,
2020-07-01 19:54:51 -07:00
INodePropertyOptions,
INodeType,
INodeTypeDescription,
:sparkles: Improve node error handling (#1309) * Add path mapping and response error interfaces * Add error handling and throwing functionality * Refactor error handling into a single function * Re-implement error handling in Hacker News node * Fix linting details * Re-implement error handling in Spotify node * Re-implement error handling in G Suite Admin node * :construction: create basic setup NodeError * :construction: add httpCodes * :construction: add path priolist * :construction: handle statusCode in error, adjust interfaces * :construction: fixing type issues w/Ivan * :construction: add error exploration * 👔 fix linter issues * :wrench: improve object check * :construction: remove path passing from NodeApiError * :construction: add multi error + refactor findProperty method * 👔 allow any * :wrench: handle multi error message callback * :zap: change return type of callback * :zap: add customCallback to MultiError * :construction: refactor to use INode * :hammer: handle arrays, continue search after first null property found * 🚫 refactor method access * :construction: setup NodeErrorView * :zap: change timestamp to Date.now * :books: Add documentation for methods and constants * :construction: change message setting * 🚚 move NodeErrors to workflow * :sparkles: add new ErrorView for Nodes * :art: improve error notification * :art: refactor interfaces * :zap: add WorkflowOperationError, refactor error throwing * 👕 fix linter issues * :art: rename param * :bug: fix handling normal errors * :zap: add usage of NodeApiError * :art: fix throw new error instead of constructor * :art: remove unnecessary code/comments * :art: adjusted spacing + updated status messages * :art: fix tab indentation * ✨ Replace current errors with custom errors (#1576) * :zap: Introduce NodeApiError in catch blocks * :zap: Introduce NodeOperationError in nodes * :zap: Add missing errors and remove incompatible * :zap: Fix NodeOperationError in incompatible nodes * :wrench: Adjust error handling in missed nodes PayPal, FileMaker, Reddit, Taiga and Facebook Graph API nodes * :hammer: Adjust Strava Trigger node error handling * :hammer: Adjust AWS nodes error handling * :hammer: Remove duplicate instantiation of NodeApiError * :bug: fix strava trigger node error handling * Add XML parsing to NodeApiError constructor (#1633) * :bug: Remove type annotation from catch variable * :sparkles: Add XML parsing to NodeApiError * :zap: Simplify error handling in Rekognition node * :zap: Pass in XML flag in generic functions * :fire: Remove try/catch wrappers at call sites * :hammer: Refactor setting description from XML * :hammer: Refactor let to const in resource loaders * :zap: Find property in parsed XML * :zap: Change let to const * :fire: Remove unneeded try/catch block * :shirt: Fix linting issues * :bug: Fix errors from merge conflict resolution * :zap: Add custom errors to latest contributions * :shirt: Fix linting issues * :zap: Refactor MongoDB helpers for custom errors * :bug: Correct custom error type * :zap: Apply feedback to A nodes * :zap: Apply feedback to missed A node * :zap: Apply feedback to B-D nodes * :zap: Apply feedback to E-F nodes * :zap: Apply feedback to G nodes * :zap: Apply feedback to H-L nodes * :zap: Apply feedback to M nodes * :zap: Apply feedback to P nodes * :zap: Apply feedback to R nodes * :zap: Apply feedback to S nodes * :zap: Apply feedback to T nodes * :zap: Apply feedback to V-Z nodes * :zap: Add HTTP code to iterable node error * :hammer: Standardize e as error * :hammer: Standardize err as error * :zap: Fix error handling for non-standard nodes Co-authored-by: Ben Hesseldieck <b.hesseldieck@gmail.com> Co-authored-by: Ben Hesseldieck <b.hesseldieck@gmail.com> Co-authored-by: Ben Hesseldieck <1849459+BHesseldieck@users.noreply.github.com>
2021-04-16 09:33:36 -07:00
NodeOperationError,
2020-07-01 19:54:51 -07:00
} from 'n8n-workflow';
import {
googleApiRequest,
googleApiRequestAllItems,
} from './GenericFunctions';
import {
channelFields,
channelOperations,
2020-07-01 19:54:51 -07:00
} from './ChannelDescription';
2020-08-09 14:39:28 -07:00
import {
playlistFields,
playlistOperations,
2020-08-09 14:39:28 -07:00
} from './PlaylistDescription';
2020-08-15 19:36:11 -07:00
import {
playlistItemFields,
playlistItemOperations,
2020-08-15 19:36:11 -07:00
} from './PlaylistItemDescription';
2020-08-09 14:39:28 -07:00
import {
videoFields,
videoOperations,
2020-08-09 14:39:28 -07:00
} from './VideoDescription';
2020-08-11 13:07:23 -07:00
import {
videoCategoryFields,
videoCategoryOperations,
2020-08-11 13:07:23 -07:00
} from './VideoCategoryDescription';
2020-08-09 14:39:28 -07:00
import {
countriesCodes,
} from './CountryCodes';
2020-07-01 19:54:51 -07:00
export class YouTube implements INodeType {
description: INodeTypeDescription = {
displayName: 'YouTube',
2020-07-01 19:54:51 -07:00
name: 'youTube',
icon: 'file:youTube.png',
group: ['input'],
version: 1,
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
description: 'Consume YouTube API.',
defaults: {
name: 'YouTube',
color: '#FF0000',
},
inputs: ['main'],
outputs: ['main'],
credentials: [
{
name: 'youTubeOAuth2Api',
required: true,
2020-08-15 19:36:11 -07:00
},
2020-07-01 19:54:51 -07:00
],
properties: [
{
displayName: 'Resource',
name: 'resource',
type: 'options',
options: [
{
name: 'Channel',
value: 'channel',
},
2020-08-09 14:39:28 -07:00
{
name: 'Playlist',
value: 'playlist',
},
2020-08-15 19:36:11 -07:00
{
name: 'Playlist Item',
value: 'playlistItem',
},
2020-08-09 14:39:28 -07:00
{
name: 'Video',
value: 'video',
},
2020-08-11 13:07:23 -07:00
{
name: 'Video Category',
value: 'videoCategory',
},
2020-07-01 19:54:51 -07:00
],
default: 'channel',
2020-10-22 06:46:03 -07:00
description: 'The resource to operate on.',
2020-07-01 19:54:51 -07:00
},
...channelOperations,
...channelFields,
2020-08-09 14:39:28 -07:00
...playlistOperations,
...playlistFields,
2020-08-15 19:36:11 -07:00
...playlistItemOperations,
...playlistItemFields,
2020-08-09 14:39:28 -07:00
...videoOperations,
...videoFields,
2020-08-11 13:07:23 -07:00
...videoCategoryOperations,
...videoCategoryFields,
2020-07-01 19:54:51 -07:00
],
};
methods = {
loadOptions: {
// Get all the languages to display them to user so that he can
// select them easily
async getLanguages(
2020-10-22 09:00:28 -07:00
this: ILoadOptionsFunctions,
2020-07-01 19:54:51 -07:00
): Promise<INodePropertyOptions[]> {
const returnData: INodePropertyOptions[] = [];
const languages = await googleApiRequestAllItems.call(
this,
'items',
'GET',
2020-10-22 09:00:28 -07:00
'/youtube/v3/i18nLanguages',
2020-07-01 19:54:51 -07:00
);
for (const language of languages) {
const languageName = language.id.toUpperCase();
const languageId = language.id;
returnData.push({
name: languageName,
2020-10-22 06:46:03 -07:00
value: languageId,
2020-07-01 19:54:51 -07:00
});
}
return returnData;
},
2020-08-09 14:39:28 -07:00
// Get all the countries codes to display them to user so that he can
// select them easily
async getCountriesCodes(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
const returnData: INodePropertyOptions[] = [];
for (const countryCode of countriesCodes) {
const countryCodeName = `${countryCode.name} - ${countryCode.alpha2}`;
const countryCodeId = countryCode.alpha2;
returnData.push({
name: countryCodeName,
value: countryCodeId,
});
}
return returnData;
},
// Get all the video categories to display them to user so that he can
// select them easily
async getVideoCategories(
2020-10-22 09:00:28 -07:00
this: ILoadOptionsFunctions,
2020-08-09 14:39:28 -07:00
): Promise<INodePropertyOptions[]> {
2020-08-11 13:07:23 -07:00
const countryCode = this.getCurrentNodeParameter('regionCode') as string;
2020-08-09 14:39:28 -07:00
const returnData: INodePropertyOptions[] = [];
const qs: IDataObject = {};
qs.regionCode = countryCode;
qs.part = 'snippet';
const categories = await googleApiRequestAllItems.call(
this,
'items',
'GET',
'/youtube/v3/videoCategories',
{},
2020-10-22 09:00:28 -07:00
qs,
2020-08-09 14:39:28 -07:00
);
for (const category of categories) {
const categoryName = category.snippet.title;
const categoryId = category.id;
returnData.push({
name: categoryName,
2020-10-22 06:46:03 -07:00
value: categoryId,
2020-08-09 14:39:28 -07:00
});
}
return returnData;
},
2020-08-15 19:36:11 -07:00
// Get all the playlists to display them to user so that he can
// select them easily
async getPlaylists(
2020-10-22 09:00:28 -07:00
this: ILoadOptionsFunctions,
2020-08-15 19:36:11 -07:00
): Promise<INodePropertyOptions[]> {
const returnData: INodePropertyOptions[] = [];
const qs: IDataObject = {};
qs.part = 'snippet';
qs.mine = true;
const playlists = await googleApiRequestAllItems.call(
this,
'items',
'GET',
'/youtube/v3/playlists',
{},
2020-10-22 09:00:28 -07:00
qs,
2020-08-15 19:36:11 -07:00
);
for (const playlist of playlists) {
const playlistName = playlist.snippet.title;
const playlistId = playlist.id;
returnData.push({
name: playlistName,
2020-10-22 06:46:03 -07:00
value: playlistId,
2020-08-15 19:36:11 -07:00
});
}
return returnData;
},
2020-10-22 06:46:03 -07:00
},
2020-07-01 19:54:51 -07:00
};
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
const items = this.getInputData();
const returnData: IDataObject[] = [];
const length = (items.length as unknown) as number;
const qs: IDataObject = {};
let responseData;
const resource = this.getNodeParameter('resource', 0) as string;
const operation = this.getNodeParameter('operation', 0) as string;
for (let i = 0; i < length; i++) {
if (resource === 'channel') {
2020-08-11 13:07:23 -07:00
if (operation === 'get') {
//https://developers.google.com/youtube/v3/docs/channels/list
2020-08-14 15:36:47 -07:00
let part = this.getNodeParameter('part', i) as string[];
2020-08-11 13:07:23 -07:00
const channelId = this.getNodeParameter('channelId', i) as string;
2020-08-14 15:36:47 -07:00
if (part.includes('*')) {
part = [
'brandingSettings',
'contentDetails',
'contentOwnerDetails',
'id',
'localizations',
'snippet',
'statistics',
'status',
'topicDetails',
];
}
2020-08-11 13:07:23 -07:00
qs.part = part.join(',');
qs.id = channelId;
responseData = await googleApiRequest.call(
this,
'GET',
`/youtube/v3/channels`,
{},
2020-10-22 09:00:28 -07:00
qs,
2020-08-11 13:07:23 -07:00
);
responseData = responseData.items;
}
2020-07-01 19:54:51 -07:00
//https://developers.google.com/youtube/v3/docs/channels/list
if (operation === 'getAll') {
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
2020-08-14 15:36:47 -07:00
let part = this.getNodeParameter('part', i) as string[];
2020-07-01 19:54:51 -07:00
const options = this.getNodeParameter('options', i) as IDataObject;
2020-08-09 14:39:28 -07:00
const filters = this.getNodeParameter('filters', i) as IDataObject;
2020-07-01 19:54:51 -07:00
2020-08-14 15:36:47 -07:00
if (part.includes('*')) {
part = [
'brandingSettings',
'contentDetails',
'contentOwnerDetails',
'id',
'localizations',
'snippet',
'statistics',
'status',
'topicDetails',
];
}
2020-07-01 19:54:51 -07:00
qs.part = part.join(',');
2020-08-11 13:07:23 -07:00
Object.assign(qs, options, filters);
qs.mine = true;
if (qs.categoryId || qs.forUsername || qs.id || qs.managedByMe) {
delete qs.mine;
2020-07-01 19:54:51 -07:00
}
2020-08-11 13:07:23 -07:00
2020-07-01 19:54:51 -07:00
if (returnAll) {
responseData = await googleApiRequestAllItems.call(
this,
'items',
'GET',
`/youtube/v3/channels`,
{},
2020-10-22 09:00:28 -07:00
qs,
2020-07-01 19:54:51 -07:00
);
} else {
qs.maxResults = this.getNodeParameter('limit', i) as number;
responseData = await googleApiRequest.call(
this,
'GET',
`/youtube/v3/channels`,
{},
2020-10-22 09:00:28 -07:00
qs,
2020-07-01 19:54:51 -07:00
);
responseData = responseData.items;
}
}
//https://developers.google.com/youtube/v3/docs/channels/update
if (operation === 'update') {
const channelId = this.getNodeParameter('channelId', i) as string;
const updateFields = this.getNodeParameter('updateFields', i) as IDataObject;
const body: IDataObject = {
id: channelId,
brandingSettings: {
channel: {},
image: {},
},
};
qs.part = 'brandingSettings';
if (updateFields.onBehalfOfContentOwner) {
qs.onBehalfOfContentOwner = updateFields.onBehalfOfContentOwner as string;
}
if (updateFields.brandingSettingsUi) {
const channelSettingsValues = (updateFields.brandingSettingsUi as IDataObject).channelSettingsValues as IDataObject | undefined;
const channelSettings: IDataObject = {};
if (channelSettingsValues?.channel) {
const channelSettingsOptions = channelSettingsValues.channel as IDataObject;
if (channelSettingsOptions.country) {
channelSettings.country = channelSettingsOptions.country;
}
if (channelSettingsOptions.description) {
channelSettings.description = channelSettingsOptions.description;
}
if (channelSettingsOptions.defaultLanguage) {
channelSettings.defaultLanguage = channelSettingsOptions.defaultLanguage;
}
if (channelSettingsOptions.defaultTab) {
channelSettings.defaultTab = channelSettingsOptions.defaultTab;
}
if (channelSettingsOptions.featuredChannelsTitle) {
channelSettings.featuredChannelsTitle = channelSettingsOptions.featuredChannelsTitle;
}
if (channelSettingsOptions.featuredChannelsUrls) {
channelSettings.featuredChannelsUrls = channelSettingsOptions.featuredChannelsUrls;
}
if (channelSettingsOptions.keywords) {
channelSettings.keywords = channelSettingsOptions.keywords;
}
if (channelSettingsOptions.moderateComments) {
channelSettings.moderateComments = channelSettingsOptions.moderateComments as boolean;
}
if (channelSettingsOptions.profileColor) {
channelSettings.profileColor = channelSettingsOptions.profileColor as string;
}
if (channelSettingsOptions.profileColor) {
channelSettings.profileColor = channelSettingsOptions.profileColor as string;
}
if (channelSettingsOptions.showRelatedChannels) {
channelSettings.showRelatedChannels = channelSettingsOptions.showRelatedChannels as boolean;
}
if (channelSettingsOptions.showBrowseView) {
channelSettings.showBrowseView = channelSettingsOptions.showBrowseView as boolean;
}
if (channelSettingsOptions.trackingAnalyticsAccountId) {
channelSettings.trackingAnalyticsAccountId = channelSettingsOptions.trackingAnalyticsAccountId as string;
}
if (channelSettingsOptions.unsubscribedTrailer) {
channelSettings.unsubscribedTrailer = channelSettingsOptions.unsubscribedTrailer as string;
}
}
const imageSettingsValues = (updateFields.brandingSettingsUi as IDataObject).imageSettingsValues as IDataObject | undefined;
const imageSettings: IDataObject = {};
if (imageSettingsValues?.image) {
const imageSettingsOptions = imageSettings.image as IDataObject;
if (imageSettingsOptions.bannerExternalUrl) {
imageSettings.bannerExternalUrl = imageSettingsOptions.bannerExternalUrl as string;
2020-07-01 19:54:51 -07:00
}
if (imageSettingsOptions.trackingImageUrl) {
imageSettings.trackingImageUrl = imageSettingsOptions.trackingImageUrl as string;
2020-07-01 19:54:51 -07:00
}
if (imageSettingsOptions.watchIconImageUrl) {
imageSettings.watchIconImageUrl = imageSettingsOptions.watchIconImageUrl as string;
2020-07-01 19:54:51 -07:00
}
}
//@ts-ignore
body.brandingSettings.channel = channelSettings;
//@ts-ignore
body.brandingSettings.image = imageSettings;
}
responseData = await googleApiRequest.call(
this,
'PUT',
'/youtube/v3/channels',
body,
2020-10-22 09:00:28 -07:00
qs,
2020-07-01 19:54:51 -07:00
);
}
//https://developers.google.com/youtube/v3/docs/channelBanners/insert
if (operation === 'uploadBanner') {
const channelId = this.getNodeParameter('channelId', i) as string;
const binaryProperty = this.getNodeParameter('binaryProperty', i) as string;
let mimeType;
// Is binary file to upload
const item = items[i];
if (item.binary === undefined) {
:sparkles: Improve node error handling (#1309) * Add path mapping and response error interfaces * Add error handling and throwing functionality * Refactor error handling into a single function * Re-implement error handling in Hacker News node * Fix linting details * Re-implement error handling in Spotify node * Re-implement error handling in G Suite Admin node * :construction: create basic setup NodeError * :construction: add httpCodes * :construction: add path priolist * :construction: handle statusCode in error, adjust interfaces * :construction: fixing type issues w/Ivan * :construction: add error exploration * 👔 fix linter issues * :wrench: improve object check * :construction: remove path passing from NodeApiError * :construction: add multi error + refactor findProperty method * 👔 allow any * :wrench: handle multi error message callback * :zap: change return type of callback * :zap: add customCallback to MultiError * :construction: refactor to use INode * :hammer: handle arrays, continue search after first null property found * 🚫 refactor method access * :construction: setup NodeErrorView * :zap: change timestamp to Date.now * :books: Add documentation for methods and constants * :construction: change message setting * 🚚 move NodeErrors to workflow * :sparkles: add new ErrorView for Nodes * :art: improve error notification * :art: refactor interfaces * :zap: add WorkflowOperationError, refactor error throwing * 👕 fix linter issues * :art: rename param * :bug: fix handling normal errors * :zap: add usage of NodeApiError * :art: fix throw new error instead of constructor * :art: remove unnecessary code/comments * :art: adjusted spacing + updated status messages * :art: fix tab indentation * ✨ Replace current errors with custom errors (#1576) * :zap: Introduce NodeApiError in catch blocks * :zap: Introduce NodeOperationError in nodes * :zap: Add missing errors and remove incompatible * :zap: Fix NodeOperationError in incompatible nodes * :wrench: Adjust error handling in missed nodes PayPal, FileMaker, Reddit, Taiga and Facebook Graph API nodes * :hammer: Adjust Strava Trigger node error handling * :hammer: Adjust AWS nodes error handling * :hammer: Remove duplicate instantiation of NodeApiError * :bug: fix strava trigger node error handling * Add XML parsing to NodeApiError constructor (#1633) * :bug: Remove type annotation from catch variable * :sparkles: Add XML parsing to NodeApiError * :zap: Simplify error handling in Rekognition node * :zap: Pass in XML flag in generic functions * :fire: Remove try/catch wrappers at call sites * :hammer: Refactor setting description from XML * :hammer: Refactor let to const in resource loaders * :zap: Find property in parsed XML * :zap: Change let to const * :fire: Remove unneeded try/catch block * :shirt: Fix linting issues * :bug: Fix errors from merge conflict resolution * :zap: Add custom errors to latest contributions * :shirt: Fix linting issues * :zap: Refactor MongoDB helpers for custom errors * :bug: Correct custom error type * :zap: Apply feedback to A nodes * :zap: Apply feedback to missed A node * :zap: Apply feedback to B-D nodes * :zap: Apply feedback to E-F nodes * :zap: Apply feedback to G nodes * :zap: Apply feedback to H-L nodes * :zap: Apply feedback to M nodes * :zap: Apply feedback to P nodes * :zap: Apply feedback to R nodes * :zap: Apply feedback to S nodes * :zap: Apply feedback to T nodes * :zap: Apply feedback to V-Z nodes * :zap: Add HTTP code to iterable node error * :hammer: Standardize e as error * :hammer: Standardize err as error * :zap: Fix error handling for non-standard nodes Co-authored-by: Ben Hesseldieck <b.hesseldieck@gmail.com> Co-authored-by: Ben Hesseldieck <b.hesseldieck@gmail.com> Co-authored-by: Ben Hesseldieck <1849459+BHesseldieck@users.noreply.github.com>
2021-04-16 09:33:36 -07:00
throw new NodeOperationError(this.getNode(), 'No binary data exists on item!');
2020-07-01 19:54:51 -07:00
}
if (item.binary[binaryProperty] === undefined) {
:sparkles: Improve node error handling (#1309) * Add path mapping and response error interfaces * Add error handling and throwing functionality * Refactor error handling into a single function * Re-implement error handling in Hacker News node * Fix linting details * Re-implement error handling in Spotify node * Re-implement error handling in G Suite Admin node * :construction: create basic setup NodeError * :construction: add httpCodes * :construction: add path priolist * :construction: handle statusCode in error, adjust interfaces * :construction: fixing type issues w/Ivan * :construction: add error exploration * 👔 fix linter issues * :wrench: improve object check * :construction: remove path passing from NodeApiError * :construction: add multi error + refactor findProperty method * 👔 allow any * :wrench: handle multi error message callback * :zap: change return type of callback * :zap: add customCallback to MultiError * :construction: refactor to use INode * :hammer: handle arrays, continue search after first null property found * 🚫 refactor method access * :construction: setup NodeErrorView * :zap: change timestamp to Date.now * :books: Add documentation for methods and constants * :construction: change message setting * 🚚 move NodeErrors to workflow * :sparkles: add new ErrorView for Nodes * :art: improve error notification * :art: refactor interfaces * :zap: add WorkflowOperationError, refactor error throwing * 👕 fix linter issues * :art: rename param * :bug: fix handling normal errors * :zap: add usage of NodeApiError * :art: fix throw new error instead of constructor * :art: remove unnecessary code/comments * :art: adjusted spacing + updated status messages * :art: fix tab indentation * ✨ Replace current errors with custom errors (#1576) * :zap: Introduce NodeApiError in catch blocks * :zap: Introduce NodeOperationError in nodes * :zap: Add missing errors and remove incompatible * :zap: Fix NodeOperationError in incompatible nodes * :wrench: Adjust error handling in missed nodes PayPal, FileMaker, Reddit, Taiga and Facebook Graph API nodes * :hammer: Adjust Strava Trigger node error handling * :hammer: Adjust AWS nodes error handling * :hammer: Remove duplicate instantiation of NodeApiError * :bug: fix strava trigger node error handling * Add XML parsing to NodeApiError constructor (#1633) * :bug: Remove type annotation from catch variable * :sparkles: Add XML parsing to NodeApiError * :zap: Simplify error handling in Rekognition node * :zap: Pass in XML flag in generic functions * :fire: Remove try/catch wrappers at call sites * :hammer: Refactor setting description from XML * :hammer: Refactor let to const in resource loaders * :zap: Find property in parsed XML * :zap: Change let to const * :fire: Remove unneeded try/catch block * :shirt: Fix linting issues * :bug: Fix errors from merge conflict resolution * :zap: Add custom errors to latest contributions * :shirt: Fix linting issues * :zap: Refactor MongoDB helpers for custom errors * :bug: Correct custom error type * :zap: Apply feedback to A nodes * :zap: Apply feedback to missed A node * :zap: Apply feedback to B-D nodes * :zap: Apply feedback to E-F nodes * :zap: Apply feedback to G nodes * :zap: Apply feedback to H-L nodes * :zap: Apply feedback to M nodes * :zap: Apply feedback to P nodes * :zap: Apply feedback to R nodes * :zap: Apply feedback to S nodes * :zap: Apply feedback to T nodes * :zap: Apply feedback to V-Z nodes * :zap: Add HTTP code to iterable node error * :hammer: Standardize e as error * :hammer: Standardize err as error * :zap: Fix error handling for non-standard nodes Co-authored-by: Ben Hesseldieck <b.hesseldieck@gmail.com> Co-authored-by: Ben Hesseldieck <b.hesseldieck@gmail.com> Co-authored-by: Ben Hesseldieck <1849459+BHesseldieck@users.noreply.github.com>
2021-04-16 09:33:36 -07:00
throw new NodeOperationError(this.getNode(), `No binary data property "${binaryProperty}" does not exists on item!`);
2020-07-01 19:54:51 -07:00
}
if (item.binary[binaryProperty].mimeType) {
mimeType = item.binary[binaryProperty].mimeType;
}
const body = Buffer.from(item.binary[binaryProperty].data, BINARY_ENCODING);
const requestOptions = {
headers: {
'Content-Type': mimeType,
},
json: false,
};
const response = await googleApiRequest.call(this, 'POST', '/upload/youtube/v3/channelBanners/insert', body, qs, undefined, requestOptions);
2020-07-01 19:54:51 -07:00
const { url } = JSON.parse(response);
qs.part = 'brandingSettings';
2020-07-01 19:54:51 -07:00
responseData = await googleApiRequest.call(
this,
'PUT',
`/youtube/v3/channels`,
{
id: channelId,
brandingSettings: {
image: {
bannerExternalUrl: url,
},
},
},
2020-10-22 09:00:28 -07:00
qs,
2020-07-01 19:54:51 -07:00
);
}
}
2020-08-09 14:39:28 -07:00
if (resource === 'playlist') {
2020-08-11 13:07:23 -07:00
//https://developers.google.com/youtube/v3/docs/playlists/list
if (operation === 'get') {
2020-08-14 15:36:47 -07:00
let part = this.getNodeParameter('part', i) as string[];
2020-08-11 13:07:23 -07:00
const playlistId = this.getNodeParameter('playlistId', i) as string;
const options = this.getNodeParameter('options', i) as IDataObject;
2020-08-14 15:36:47 -07:00
if (part.includes('*')) {
part = [
'contentDetails',
'id',
'localizations',
'player',
'snippet',
'status',
];
}
2020-08-11 13:07:23 -07:00
qs.part = part.join(',');
qs.id = playlistId;
Object.assign(qs, options);
responseData = await googleApiRequest.call(
this,
'GET',
`/youtube/v3/playlists`,
{},
2020-10-22 09:00:28 -07:00
qs,
2020-08-11 13:07:23 -07:00
);
responseData = responseData.items;
}
2020-08-09 14:39:28 -07:00
//https://developers.google.com/youtube/v3/docs/playlists/list
if (operation === 'getAll') {
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
2020-08-14 15:36:47 -07:00
let part = this.getNodeParameter('part', i) as string[];
2020-08-09 14:39:28 -07:00
const options = this.getNodeParameter('options', i) as IDataObject;
const filters = this.getNodeParameter('filters', i) as IDataObject;
2020-08-14 15:36:47 -07:00
if (part.includes('*')) {
part = [
'contentDetails',
'id',
'localizations',
'player',
'snippet',
'status',
];
}
2020-08-09 14:39:28 -07:00
qs.part = part.join(',');
Object.assign(qs, options, filters);
2020-08-11 13:07:23 -07:00
qs.mine = true;
if (qs.channelId || qs.id) {
delete qs.mine;
}
2020-08-09 14:39:28 -07:00
if (returnAll) {
responseData = await googleApiRequestAllItems.call(
this,
'items',
'GET',
`/youtube/v3/playlists`,
{},
2020-10-22 09:00:28 -07:00
qs,
2020-08-09 14:39:28 -07:00
);
} else {
qs.maxResults = this.getNodeParameter('limit', i) as number;
responseData = await googleApiRequest.call(
this,
'GET',
`/youtube/v3/playlists`,
{},
2020-10-22 09:00:28 -07:00
qs,
2020-08-09 14:39:28 -07:00
);
responseData = responseData.items;
}
}
//https://developers.google.com/youtube/v3/docs/playlists/insert
if (operation === 'create') {
const title = this.getNodeParameter('title', i) as string;
const options = this.getNodeParameter('options', i) as IDataObject;
qs.part = 'snippet';
const body: IDataObject = {
snippet: {
title,
},
};
if (options.tags) {
//@ts-ignore
body.snippet.tags = (options.tags as string).split(',') as string[];
}
if (options.description) {
//@ts-ignore
body.snippet.privacyStatus = options.privacyStatus as string;
}
if (options.defaultLanguage) {
//@ts-ignore
body.snippet.defaultLanguage = options.defaultLanguage as string;
}
if (options.onBehalfOfContentOwner) {
qs.onBehalfOfContentOwner = options.onBehalfOfContentOwner as string;
}
if (options.onBehalfOfContentOwnerChannel) {
qs.onBehalfOfContentOwnerChannel = options.onBehalfOfContentOwnerChannel as string;
}
responseData = await googleApiRequest.call(
this,
'POST',
'/youtube/v3/playlists',
body,
2020-10-22 09:00:28 -07:00
qs,
2020-08-09 14:39:28 -07:00
);
}
//https://developers.google.com/youtube/v3/docs/playlists/update
if (operation === 'update') {
const playlistId = this.getNodeParameter('playlistId', i) as string;
2020-08-11 13:07:23 -07:00
const title = this.getNodeParameter('title', i) as string;
2020-08-09 14:39:28 -07:00
const updateFields = this.getNodeParameter('updateFields', i) as IDataObject;
2020-08-11 13:07:23 -07:00
qs.part = 'snippet, status';
2020-08-09 14:39:28 -07:00
const body: IDataObject = {
id: playlistId,
snippet: {
2020-08-11 13:07:23 -07:00
title,
},
status: {
},
2020-08-09 14:39:28 -07:00
};
if (updateFields.tags) {
//@ts-ignore
body.snippet.tags = (updateFields.tags as string).split(',') as string[];
}
2020-08-11 13:07:23 -07:00
if (updateFields.privacyStatus) {
2020-08-09 14:39:28 -07:00
//@ts-ignore
2020-08-11 13:07:23 -07:00
body.status.privacyStatus = updateFields.privacyStatus as string;
2020-08-09 14:39:28 -07:00
}
if (updateFields.description) {
//@ts-ignore
body.snippet.description = updateFields.description as string;
}
if (updateFields.defaultLanguage) {
//@ts-ignore
body.snippet.defaultLanguage = updateFields.defaultLanguage as string;
}
if (updateFields.onBehalfOfContentOwner) {
qs.onBehalfOfContentOwner = updateFields.onBehalfOfContentOwner as string;
}
responseData = await googleApiRequest.call(
this,
'PUT',
'/youtube/v3/playlists',
body,
2020-10-22 09:00:28 -07:00
qs,
2020-08-09 14:39:28 -07:00
);
}
//https://developers.google.com/youtube/v3/docs/playlists/delete
if (operation === 'delete') {
const playlistId = this.getNodeParameter('playlistId', i) as string;
const options = this.getNodeParameter('options', i) as IDataObject;
const body: IDataObject = {
id: playlistId,
};
if (options.onBehalfOfContentOwner) {
qs.onBehalfOfContentOwner = options.onBehalfOfContentOwner as string;
}
responseData = await googleApiRequest.call(
this,
'DELETE',
'/youtube/v3/playlists',
2020-10-22 09:00:28 -07:00
body,
2020-08-09 14:39:28 -07:00
);
responseData = { success: true };
}
}
2020-08-15 19:36:11 -07:00
if (resource === 'playlistItem') {
//https://developers.google.com/youtube/v3/docs/playlistItems/list
if (operation === 'get') {
let part = this.getNodeParameter('part', i) as string[];
const playlistItemId = this.getNodeParameter('playlistItemId', i) as string;
const options = this.getNodeParameter('options', i) as IDataObject;
if (part.includes('*')) {
part = [
'contentDetails',
'id',
'snippet',
'status',
];
}
qs.part = part.join(',');
qs.id = playlistItemId;
Object.assign(qs, options);
responseData = await googleApiRequest.call(
this,
'GET',
`/youtube/v3/playlistItems`,
{},
2020-10-22 09:00:28 -07:00
qs,
2020-08-15 19:36:11 -07:00
);
responseData = responseData.items;
}
//https://developers.google.com/youtube/v3/docs/playlistItems/list
if (operation === 'getAll') {
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
let part = this.getNodeParameter('part', i) as string[];
const options = this.getNodeParameter('options', i) as IDataObject;
const playlistId = this.getNodeParameter('playlistId', i) as string;
//const filters = this.getNodeParameter('filters', i) as IDataObject;
if (part.includes('*')) {
part = [
'contentDetails',
'id',
'snippet',
'status',
];
}
qs.playlistId = playlistId;
qs.part = part.join(',');
Object.assign(qs, options);
if (returnAll) {
responseData = await googleApiRequestAllItems.call(
this,
'items',
'GET',
`/youtube/v3/playlistItems`,
{},
2020-10-22 09:00:28 -07:00
qs,
2020-08-15 19:36:11 -07:00
);
} else {
qs.maxResults = this.getNodeParameter('limit', i) as number;
responseData = await googleApiRequest.call(
this,
'GET',
`/youtube/v3/playlistItems`,
{},
2020-10-22 09:00:28 -07:00
qs,
2020-08-15 19:36:11 -07:00
);
responseData = responseData.items;
}
}
//https://developers.google.com/youtube/v3/docs/playlistItems/insert
if (operation === 'add') {
const playlistId = this.getNodeParameter('playlistId', i) as string;
const videoId = this.getNodeParameter('videoId', i) as string;
const options = this.getNodeParameter('options', i) as IDataObject;
qs.part = 'snippet, contentDetails';
const body: IDataObject = {
snippet: {
playlistId,
resourceId: {
kind: 'youtube#video',
videoId,
2020-08-15 19:36:11 -07:00
},
},
contentDetails: {
},
};
if (options.position) {
//@ts-ignore
body.snippet.position = options.position as number;
}
if (options.note) {
//@ts-ignore
body.contentDetails.note = options.note as string;
}
if (options.startAt) {
//@ts-ignore
body.contentDetails.startAt = options.startAt as string;
}
if (options.endAt) {
//@ts-ignore
body.contentDetails.endAt = options.endAt as string;
}
if (options.onBehalfOfContentOwner) {
qs.onBehalfOfContentOwner = options.onBehalfOfContentOwner as string;
}
responseData = await googleApiRequest.call(
this,
'POST',
'/youtube/v3/playlistItems',
body,
2020-10-22 09:00:28 -07:00
qs,
2020-08-15 19:36:11 -07:00
);
}
//https://developers.google.com/youtube/v3/docs/playlistItems/delete
if (operation === 'delete') {
const playlistItemId = this.getNodeParameter('playlistItemId', i) as string;
const options = this.getNodeParameter('options', i) as IDataObject;
const body: IDataObject = {
id: playlistItemId,
};
if (options.onBehalfOfContentOwner) {
qs.onBehalfOfContentOwner = options.onBehalfOfContentOwner as string;
}
responseData = await googleApiRequest.call(
this,
'DELETE',
'/youtube/v3/playlistItems',
2020-10-22 09:00:28 -07:00
body,
2020-08-15 19:36:11 -07:00
);
responseData = { success: true };
}
}
2020-08-09 14:39:28 -07:00
if (resource === 'video') {
2020-08-14 15:36:47 -07:00
//https://developers.google.com/youtube/v3/docs/search/list
2020-08-09 14:39:28 -07:00
if (operation === 'getAll') {
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
const options = this.getNodeParameter('options', i) as IDataObject;
const filters = this.getNodeParameter('filters', i) as IDataObject;
2020-08-14 15:36:47 -07:00
qs.part = 'snippet';
qs.type = 'video';
2020-08-09 14:39:28 -07:00
2020-08-14 15:36:47 -07:00
qs.forMine = true;
2020-08-09 14:39:28 -07:00
Object.assign(qs, options, filters);
2020-08-14 15:36:47 -07:00
if (Object.keys(filters).length > 0) {
delete qs.forMine;
}
if (qs.relatedToVideoId && qs.forDeveloper !== undefined) {
:sparkles: Improve node error handling (#1309) * Add path mapping and response error interfaces * Add error handling and throwing functionality * Refactor error handling into a single function * Re-implement error handling in Hacker News node * Fix linting details * Re-implement error handling in Spotify node * Re-implement error handling in G Suite Admin node * :construction: create basic setup NodeError * :construction: add httpCodes * :construction: add path priolist * :construction: handle statusCode in error, adjust interfaces * :construction: fixing type issues w/Ivan * :construction: add error exploration * 👔 fix linter issues * :wrench: improve object check * :construction: remove path passing from NodeApiError * :construction: add multi error + refactor findProperty method * 👔 allow any * :wrench: handle multi error message callback * :zap: change return type of callback * :zap: add customCallback to MultiError * :construction: refactor to use INode * :hammer: handle arrays, continue search after first null property found * 🚫 refactor method access * :construction: setup NodeErrorView * :zap: change timestamp to Date.now * :books: Add documentation for methods and constants * :construction: change message setting * 🚚 move NodeErrors to workflow * :sparkles: add new ErrorView for Nodes * :art: improve error notification * :art: refactor interfaces * :zap: add WorkflowOperationError, refactor error throwing * 👕 fix linter issues * :art: rename param * :bug: fix handling normal errors * :zap: add usage of NodeApiError * :art: fix throw new error instead of constructor * :art: remove unnecessary code/comments * :art: adjusted spacing + updated status messages * :art: fix tab indentation * ✨ Replace current errors with custom errors (#1576) * :zap: Introduce NodeApiError in catch blocks * :zap: Introduce NodeOperationError in nodes * :zap: Add missing errors and remove incompatible * :zap: Fix NodeOperationError in incompatible nodes * :wrench: Adjust error handling in missed nodes PayPal, FileMaker, Reddit, Taiga and Facebook Graph API nodes * :hammer: Adjust Strava Trigger node error handling * :hammer: Adjust AWS nodes error handling * :hammer: Remove duplicate instantiation of NodeApiError * :bug: fix strava trigger node error handling * Add XML parsing to NodeApiError constructor (#1633) * :bug: Remove type annotation from catch variable * :sparkles: Add XML parsing to NodeApiError * :zap: Simplify error handling in Rekognition node * :zap: Pass in XML flag in generic functions * :fire: Remove try/catch wrappers at call sites * :hammer: Refactor setting description from XML * :hammer: Refactor let to const in resource loaders * :zap: Find property in parsed XML * :zap: Change let to const * :fire: Remove unneeded try/catch block * :shirt: Fix linting issues * :bug: Fix errors from merge conflict resolution * :zap: Add custom errors to latest contributions * :shirt: Fix linting issues * :zap: Refactor MongoDB helpers for custom errors * :bug: Correct custom error type * :zap: Apply feedback to A nodes * :zap: Apply feedback to missed A node * :zap: Apply feedback to B-D nodes * :zap: Apply feedback to E-F nodes * :zap: Apply feedback to G nodes * :zap: Apply feedback to H-L nodes * :zap: Apply feedback to M nodes * :zap: Apply feedback to P nodes * :zap: Apply feedback to R nodes * :zap: Apply feedback to S nodes * :zap: Apply feedback to T nodes * :zap: Apply feedback to V-Z nodes * :zap: Add HTTP code to iterable node error * :hammer: Standardize e as error * :hammer: Standardize err as error * :zap: Fix error handling for non-standard nodes Co-authored-by: Ben Hesseldieck <b.hesseldieck@gmail.com> Co-authored-by: Ben Hesseldieck <b.hesseldieck@gmail.com> Co-authored-by: Ben Hesseldieck <1849459+BHesseldieck@users.noreply.github.com>
2021-04-16 09:33:36 -07:00
throw new NodeOperationError(this.getNode(), `When using the parameter 'related to video' the parameter 'for developer' cannot be set`);
2020-08-11 13:07:23 -07:00
}
2020-08-09 14:39:28 -07:00
if (returnAll) {
responseData = await googleApiRequestAllItems.call(
this,
'items',
'GET',
2020-08-14 15:36:47 -07:00
`/youtube/v3/search`,
2020-08-09 14:39:28 -07:00
{},
2020-10-22 09:00:28 -07:00
qs,
2020-08-09 14:39:28 -07:00
);
} else {
qs.maxResults = this.getNodeParameter('limit', i) as number;
responseData = await googleApiRequest.call(
this,
'GET',
2020-08-14 15:36:47 -07:00
`/youtube/v3/search`,
2020-08-09 14:39:28 -07:00
{},
2020-10-22 09:00:28 -07:00
qs,
2020-08-09 14:39:28 -07:00
);
responseData = responseData.items;
}
}
//https://developers.google.com/youtube/v3/docs/videos/list?hl=en
if (operation === 'get') {
2020-08-14 15:36:47 -07:00
let part = this.getNodeParameter('part', i) as string[];
2020-08-09 14:39:28 -07:00
const videoId = this.getNodeParameter('videoId', i) as string;
const options = this.getNodeParameter('options', i) as IDataObject;
2020-08-14 15:36:47 -07:00
if (part.includes('*')) {
part = [
'contentDetails',
'id',
'liveStreamingDetails',
'localizations',
'player',
'recordingDetails',
'snippet',
'statistics',
'status',
'topicDetails',
];
}
2020-08-09 14:39:28 -07:00
qs.part = part.join(',');
qs.id = videoId;
Object.assign(qs, options);
responseData = await googleApiRequest.call(
this,
'GET',
`/youtube/v3/videos`,
{},
2020-10-22 09:00:28 -07:00
qs,
2020-08-09 14:39:28 -07:00
);
responseData = responseData.items;
}
//https://developers.google.com/youtube/v3/guides/uploading_a_video?hl=en
if (operation === 'upload') {
const title = this.getNodeParameter('title', i) as string;
const categoryId = this.getNodeParameter('categoryId', i) as string;
const options = this.getNodeParameter('options', i) as IDataObject;
const binaryProperty = this.getNodeParameter('binaryProperty', i) as string;
let mimeType;
// Is binary file to upload
const item = items[i];
if (item.binary === undefined) {
:sparkles: Improve node error handling (#1309) * Add path mapping and response error interfaces * Add error handling and throwing functionality * Refactor error handling into a single function * Re-implement error handling in Hacker News node * Fix linting details * Re-implement error handling in Spotify node * Re-implement error handling in G Suite Admin node * :construction: create basic setup NodeError * :construction: add httpCodes * :construction: add path priolist * :construction: handle statusCode in error, adjust interfaces * :construction: fixing type issues w/Ivan * :construction: add error exploration * 👔 fix linter issues * :wrench: improve object check * :construction: remove path passing from NodeApiError * :construction: add multi error + refactor findProperty method * 👔 allow any * :wrench: handle multi error message callback * :zap: change return type of callback * :zap: add customCallback to MultiError * :construction: refactor to use INode * :hammer: handle arrays, continue search after first null property found * 🚫 refactor method access * :construction: setup NodeErrorView * :zap: change timestamp to Date.now * :books: Add documentation for methods and constants * :construction: change message setting * 🚚 move NodeErrors to workflow * :sparkles: add new ErrorView for Nodes * :art: improve error notification * :art: refactor interfaces * :zap: add WorkflowOperationError, refactor error throwing * 👕 fix linter issues * :art: rename param * :bug: fix handling normal errors * :zap: add usage of NodeApiError * :art: fix throw new error instead of constructor * :art: remove unnecessary code/comments * :art: adjusted spacing + updated status messages * :art: fix tab indentation * ✨ Replace current errors with custom errors (#1576) * :zap: Introduce NodeApiError in catch blocks * :zap: Introduce NodeOperationError in nodes * :zap: Add missing errors and remove incompatible * :zap: Fix NodeOperationError in incompatible nodes * :wrench: Adjust error handling in missed nodes PayPal, FileMaker, Reddit, Taiga and Facebook Graph API nodes * :hammer: Adjust Strava Trigger node error handling * :hammer: Adjust AWS nodes error handling * :hammer: Remove duplicate instantiation of NodeApiError * :bug: fix strava trigger node error handling * Add XML parsing to NodeApiError constructor (#1633) * :bug: Remove type annotation from catch variable * :sparkles: Add XML parsing to NodeApiError * :zap: Simplify error handling in Rekognition node * :zap: Pass in XML flag in generic functions * :fire: Remove try/catch wrappers at call sites * :hammer: Refactor setting description from XML * :hammer: Refactor let to const in resource loaders * :zap: Find property in parsed XML * :zap: Change let to const * :fire: Remove unneeded try/catch block * :shirt: Fix linting issues * :bug: Fix errors from merge conflict resolution * :zap: Add custom errors to latest contributions * :shirt: Fix linting issues * :zap: Refactor MongoDB helpers for custom errors * :bug: Correct custom error type * :zap: Apply feedback to A nodes * :zap: Apply feedback to missed A node * :zap: Apply feedback to B-D nodes * :zap: Apply feedback to E-F nodes * :zap: Apply feedback to G nodes * :zap: Apply feedback to H-L nodes * :zap: Apply feedback to M nodes * :zap: Apply feedback to P nodes * :zap: Apply feedback to R nodes * :zap: Apply feedback to S nodes * :zap: Apply feedback to T nodes * :zap: Apply feedback to V-Z nodes * :zap: Add HTTP code to iterable node error * :hammer: Standardize e as error * :hammer: Standardize err as error * :zap: Fix error handling for non-standard nodes Co-authored-by: Ben Hesseldieck <b.hesseldieck@gmail.com> Co-authored-by: Ben Hesseldieck <b.hesseldieck@gmail.com> Co-authored-by: Ben Hesseldieck <1849459+BHesseldieck@users.noreply.github.com>
2021-04-16 09:33:36 -07:00
throw new NodeOperationError(this.getNode(), 'No binary data exists on item!');
2020-08-09 14:39:28 -07:00
}
if (item.binary[binaryProperty] === undefined) {
:sparkles: Improve node error handling (#1309) * Add path mapping and response error interfaces * Add error handling and throwing functionality * Refactor error handling into a single function * Re-implement error handling in Hacker News node * Fix linting details * Re-implement error handling in Spotify node * Re-implement error handling in G Suite Admin node * :construction: create basic setup NodeError * :construction: add httpCodes * :construction: add path priolist * :construction: handle statusCode in error, adjust interfaces * :construction: fixing type issues w/Ivan * :construction: add error exploration * 👔 fix linter issues * :wrench: improve object check * :construction: remove path passing from NodeApiError * :construction: add multi error + refactor findProperty method * 👔 allow any * :wrench: handle multi error message callback * :zap: change return type of callback * :zap: add customCallback to MultiError * :construction: refactor to use INode * :hammer: handle arrays, continue search after first null property found * 🚫 refactor method access * :construction: setup NodeErrorView * :zap: change timestamp to Date.now * :books: Add documentation for methods and constants * :construction: change message setting * 🚚 move NodeErrors to workflow * :sparkles: add new ErrorView for Nodes * :art: improve error notification * :art: refactor interfaces * :zap: add WorkflowOperationError, refactor error throwing * 👕 fix linter issues * :art: rename param * :bug: fix handling normal errors * :zap: add usage of NodeApiError * :art: fix throw new error instead of constructor * :art: remove unnecessary code/comments * :art: adjusted spacing + updated status messages * :art: fix tab indentation * ✨ Replace current errors with custom errors (#1576) * :zap: Introduce NodeApiError in catch blocks * :zap: Introduce NodeOperationError in nodes * :zap: Add missing errors and remove incompatible * :zap: Fix NodeOperationError in incompatible nodes * :wrench: Adjust error handling in missed nodes PayPal, FileMaker, Reddit, Taiga and Facebook Graph API nodes * :hammer: Adjust Strava Trigger node error handling * :hammer: Adjust AWS nodes error handling * :hammer: Remove duplicate instantiation of NodeApiError * :bug: fix strava trigger node error handling * Add XML parsing to NodeApiError constructor (#1633) * :bug: Remove type annotation from catch variable * :sparkles: Add XML parsing to NodeApiError * :zap: Simplify error handling in Rekognition node * :zap: Pass in XML flag in generic functions * :fire: Remove try/catch wrappers at call sites * :hammer: Refactor setting description from XML * :hammer: Refactor let to const in resource loaders * :zap: Find property in parsed XML * :zap: Change let to const * :fire: Remove unneeded try/catch block * :shirt: Fix linting issues * :bug: Fix errors from merge conflict resolution * :zap: Add custom errors to latest contributions * :shirt: Fix linting issues * :zap: Refactor MongoDB helpers for custom errors * :bug: Correct custom error type * :zap: Apply feedback to A nodes * :zap: Apply feedback to missed A node * :zap: Apply feedback to B-D nodes * :zap: Apply feedback to E-F nodes * :zap: Apply feedback to G nodes * :zap: Apply feedback to H-L nodes * :zap: Apply feedback to M nodes * :zap: Apply feedback to P nodes * :zap: Apply feedback to R nodes * :zap: Apply feedback to S nodes * :zap: Apply feedback to T nodes * :zap: Apply feedback to V-Z nodes * :zap: Add HTTP code to iterable node error * :hammer: Standardize e as error * :hammer: Standardize err as error * :zap: Fix error handling for non-standard nodes Co-authored-by: Ben Hesseldieck <b.hesseldieck@gmail.com> Co-authored-by: Ben Hesseldieck <b.hesseldieck@gmail.com> Co-authored-by: Ben Hesseldieck <1849459+BHesseldieck@users.noreply.github.com>
2021-04-16 09:33:36 -07:00
throw new NodeOperationError(this.getNode(), `No binary data property "${binaryProperty}" does not exists on item!`);
2020-08-09 14:39:28 -07:00
}
if (item.binary[binaryProperty].mimeType) {
mimeType = item.binary[binaryProperty].mimeType;
}
const body = Buffer.from(item.binary[binaryProperty].data, BINARY_ENCODING);
const requestOptions = {
headers: {
'Content-Type': mimeType,
},
json: false,
};
const response = await googleApiRequest.call(this, 'POST', '/upload/youtube/v3/videos', body, qs, undefined, requestOptions);
2020-08-09 14:39:28 -07:00
const { id } = JSON.parse(response);
qs.part = 'snippet, status, recordingDetails';
const data = {
id,
snippet: {
title,
categoryId,
},
status: {
},
recordingDetails: {
},
};
2020-08-09 14:39:28 -07:00
if (options.description) {
//@ts-ignore
data.snippet.description = options.description as string;
}
if (options.privacyStatus) {
//@ts-ignore
data.status.privacyStatus = options.privacyStatus as string;
}
if (options.tags) {
//@ts-ignore
data.snippet.tags = (options.tags as string).split(',') as string[];
}
if (options.embeddable) {
//@ts-ignore
data.status.embeddable = options.embeddable as boolean;
}
if (options.publicStatsViewable) {
//@ts-ignore
data.status.publicStatsViewable = options.publicStatsViewable as boolean;
}
if (options.publishAt) {
//@ts-ignore
data.status.publishAt = options.publishAt as string;
}
if (options.recordingDate) {
//@ts-ignore
data.recordingDetails.recordingDate = options.recordingDate as string;
}
if (options.selfDeclaredMadeForKids) {
//@ts-ignore
data.status.selfDeclaredMadeForKids = options.selfDeclaredMadeForKids as boolean;
}
if (options.license) {
//@ts-ignore
data.status.license = options.license as string;
}
if (options.defaultLanguage) {
//@ts-ignore
data.snippet.defaultLanguage = options.defaultLanguage as string;
}
if (options.notifySubscribers) {
qs.notifySubscribers = options.notifySubscribers;
delete options.notifySubscribers;
}
responseData = await googleApiRequest.call(
this,
'PUT',
`/youtube/v3/videos`,
data,
2020-10-22 09:00:28 -07:00
qs,
2020-08-09 14:39:28 -07:00
);
}
//https://developers.google.com/youtube/v3/docs/playlists/update
if (operation === 'update') {
const id = this.getNodeParameter('videoId', i) as string;
2020-08-11 13:07:23 -07:00
const title = this.getNodeParameter('title', i) as string;
const categoryId = this.getNodeParameter('categoryId', i) as string;
2020-08-09 14:39:28 -07:00
const updateFields = this.getNodeParameter('updateFields', i) as IDataObject;
qs.part = 'snippet, status, recordingDetails';
const body = {
id,
snippet: {
2020-08-11 13:07:23 -07:00
title,
categoryId,
2020-08-09 14:39:28 -07:00
},
status: {
},
recordingDetails: {
},
};
2020-08-09 14:39:28 -07:00
if (updateFields.description) {
//@ts-ignore
2020-08-11 13:07:23 -07:00
body.snippet.description = updateFields.description as string;
2020-08-09 14:39:28 -07:00
}
if (updateFields.privacyStatus) {
//@ts-ignore
2020-08-11 13:07:23 -07:00
body.status.privacyStatus = updateFields.privacyStatus as string;
2020-08-09 14:39:28 -07:00
}
if (updateFields.tags) {
//@ts-ignore
2020-08-11 13:07:23 -07:00
body.snippet.tags = (updateFields.tags as string).split(',') as string[];
2020-08-09 14:39:28 -07:00
}
if (updateFields.embeddable) {
//@ts-ignore
2020-08-11 13:07:23 -07:00
body.status.embeddable = updateFields.embeddable as boolean;
2020-08-09 14:39:28 -07:00
}
if (updateFields.publicStatsViewable) {
//@ts-ignore
2020-08-11 13:07:23 -07:00
body.status.publicStatsViewable = updateFields.publicStatsViewable as boolean;
2020-08-09 14:39:28 -07:00
}
if (updateFields.publishAt) {
//@ts-ignore
2020-08-11 13:07:23 -07:00
body.status.publishAt = updateFields.publishAt as string;
2020-08-09 14:39:28 -07:00
}
2020-08-11 13:07:23 -07:00
if (updateFields.selfDeclaredMadeForKids) {
2020-08-09 14:39:28 -07:00
//@ts-ignore
2020-08-11 13:07:23 -07:00
body.status.selfDeclaredMadeForKids = updateFields.selfDeclaredMadeForKids as boolean;
2020-08-09 14:39:28 -07:00
}
2020-08-11 13:07:23 -07:00
if (updateFields.recordingDate) {
2020-08-09 14:39:28 -07:00
//@ts-ignore
2020-08-11 13:07:23 -07:00
body.recordingDetails.recordingDate = updateFields.recordingDate as string;
2020-08-09 14:39:28 -07:00
}
if (updateFields.license) {
//@ts-ignore
2020-08-11 13:07:23 -07:00
body.status.license = updateFields.license as string;
2020-08-09 14:39:28 -07:00
}
if (updateFields.defaultLanguage) {
//@ts-ignore
2020-08-11 13:07:23 -07:00
body.snippet.defaultLanguage = updateFields.defaultLanguage as string;
2020-08-09 14:39:28 -07:00
}
responseData = await googleApiRequest.call(
this,
'PUT',
'/youtube/v3/videos',
body,
2020-10-22 09:00:28 -07:00
qs,
2020-08-09 14:39:28 -07:00
);
}
//https://developers.google.com/youtube/v3/docs/videos/delete?hl=en
if (operation === 'delete') {
const videoId = this.getNodeParameter('videoId', i) as string;
const options = this.getNodeParameter('options', i) as IDataObject;
const body: IDataObject = {
id: videoId,
};
if (options.onBehalfOfContentOwner) {
qs.onBehalfOfContentOwner = options.onBehalfOfContentOwner as string;
}
responseData = await googleApiRequest.call(
this,
'DELETE',
2020-08-14 15:36:47 -07:00
'/youtube/v3/videos',
2020-10-22 09:00:28 -07:00
body,
2020-08-09 14:39:28 -07:00
);
responseData = { success: true };
}
//https://developers.google.com/youtube/v3/docs/videos/rate?hl=en
if (operation === 'rate') {
const videoId = this.getNodeParameter('videoId', i) as string;
const rating = this.getNodeParameter('rating', i) as string;
const body: IDataObject = {
id: videoId,
rating,
};
responseData = await googleApiRequest.call(
this,
'POST',
'/youtube/v3/videos/rate',
2020-10-22 09:00:28 -07:00
body,
2020-08-09 14:39:28 -07:00
);
responseData = { success: true };
}
}
2020-08-11 13:07:23 -07:00
if (resource === 'videoCategory') {
//https://developers.google.com/youtube/v3/docs/videoCategories/list
if (operation === 'getAll') {
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
const regionCode = this.getNodeParameter('regionCode', i) as string;
qs.regionCode = regionCode;
qs.part = 'snippet';
responseData = await googleApiRequest.call(
this,
'GET',
`/youtube/v3/videoCategories`,
{},
2020-10-22 09:00:28 -07:00
qs,
2020-08-11 13:07:23 -07:00
);
responseData = responseData.items;
if (returnAll === false) {
const limit = this.getNodeParameter('limit', i) as number;
responseData = responseData.splice(0, limit);
}
}
}
2020-07-01 19:54:51 -07:00
}
if (Array.isArray(responseData)) {
returnData.push.apply(returnData, responseData as IDataObject[]);
} else if (responseData !== undefined) {
returnData.push(responseData as IDataObject);
}
return [this.helpers.returnJsonArray(returnData)];
}
}