zap: Improvements

This commit is contained in:
ricardo 2020-08-14 18:36:47 -04:00
parent 8c24858f99
commit 091659df29
5 changed files with 215 additions and 114 deletions

View file

@ -50,6 +50,10 @@ export const channelFields = [
name: 'part', name: 'part',
type: 'multiOptions', type: 'multiOptions',
options: [ options: [
{
name: '*',
value: '*',
},
{ {
name: 'Branding Settings', name: 'Branding Settings',
value: 'brandingSettings', value: 'brandingSettings',
@ -137,9 +141,9 @@ export const channelFields = [
}, },
typeOptions: { typeOptions: {
minValue: 1, minValue: 1,
maxValue: 500, maxValue: 50,
}, },
default: 100, default: 25,
description: 'How many results to return.', description: 'How many results to return.',
}, },
{ {
@ -243,6 +247,7 @@ export const channelFields = [
], ],
}, },
}, },
description: 'ID of the video',
default: '', default: '',
}, },
{ {
@ -250,6 +255,10 @@ export const channelFields = [
name: 'part', name: 'part',
type: 'multiOptions', type: 'multiOptions',
options: [ options: [
{
name: '*',
value: '*',
},
{ {
name: 'Branding Settings', name: 'Branding Settings',
value: 'brandingSettings', value: 'brandingSettings',
@ -554,6 +563,7 @@ export const channelFields = [
], ],
}, },
}, },
description: 'ID of the channel',
default: '', default: '',
}, },
{ {

View file

@ -173,6 +173,10 @@ export const playlistFields = [
name: 'part', name: 'part',
type: 'multiOptions', type: 'multiOptions',
options: [ options: [
{
name: '*',
value: '*',
},
{ {
name: 'Content Details', name: 'Content Details',
value: 'contentDetails', value: 'contentDetails',
@ -301,6 +305,10 @@ export const playlistFields = [
name: 'part', name: 'part',
type: 'multiOptions', type: 'multiOptions',
options: [ options: [
{
name: '*',
value: '*',
},
{ {
name: 'Content Details', name: 'Content Details',
value: 'contentDetails', value: 'contentDetails',
@ -376,9 +384,9 @@ export const playlistFields = [
}, },
typeOptions: { typeOptions: {
minValue: 1, minValue: 1,
maxValue: 500, maxValue: 50,
}, },
default: 100, default: 25,
description: 'How many results to return.', description: 'How many results to return.',
}, },
{ {

View file

@ -87,9 +87,9 @@ export const videoCategoryFields = [
}, },
typeOptions: { typeOptions: {
minValue: 1, minValue: 1,
maxValue: 500, maxValue: 50,
}, },
default: 100, default: 25,
description: 'How many results to return.', description: 'How many results to return.',
}, },
] as INodeProperties[]; ] as INodeProperties[];

View file

@ -1,6 +1,7 @@
import { import {
INodeProperties, INodeProperties,
} from 'n8n-workflow'; } from 'n8n-workflow';
import { id } from 'rhea';
export const videoOperations = [ export const videoOperations = [
{ {
@ -271,6 +272,7 @@ export const videoFields = [
], ],
}, },
}, },
description: 'ID of the video',
default: '', default: '',
}, },
{ {
@ -325,6 +327,10 @@ export const videoFields = [
name: 'part', name: 'part',
type: 'multiOptions', type: 'multiOptions',
options: [ options: [
{
name: '*',
value: '*',
},
{ {
name: 'Content Details', name: 'Content Details',
value: 'contentDetails', value: 'contentDetails',
@ -361,10 +367,6 @@ export const videoFields = [
name: 'Status', name: 'Status',
value: 'status', value: 'status',
}, },
{
name: 'Suggestions',
value: 'suggestions',
},
{ {
name: 'Topic Details', name: 'Topic Details',
value: 'topicDetails', value: 'topicDetails',
@ -414,70 +416,6 @@ export const videoFields = [
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* video:getAll */ /* video:getAll */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
{
displayName: 'Fields',
name: 'part',
type: 'multiOptions',
options: [
{
name: 'Content Details',
value: 'contentDetails',
},
{
name: 'ID',
value: 'id',
},
{
name: 'Live Streaming Details',
value: 'liveStreamingDetails',
},
{
name: 'Localizations',
value: 'localizations',
},
{
name: 'Player',
value: 'player',
},
{
name: 'Recording Details',
value: 'recordingDetails',
},
{
name: 'Snippet',
value: 'snippet',
},
{
name: 'Statistics',
value: 'statistics',
},
{
name: 'Status',
value: 'status',
},
{
name: 'Suggestions',
value: 'suggestions',
},
{
name: 'Topic Details',
value: 'topicDetails',
},
],
required: true,
displayOptions: {
show: {
operation: [
'getAll',
],
resource: [
'video',
],
},
},
description: 'The fields parameter specifies a comma-separated list of one or more video resource properties that the API response will include.',
default: ''
},
{ {
displayName: 'Return All', displayName: 'Return All',
name: 'returnAll', name: 'returnAll',
@ -514,9 +452,9 @@ export const videoFields = [
}, },
typeOptions: { typeOptions: {
minValue: 1, minValue: 1,
maxValue: 500, maxValue: 50,
}, },
default: 100, default: 25,
description: 'How many results to return.', description: 'How many results to return.',
}, },
{ {
@ -537,28 +475,39 @@ export const videoFields = [
}, },
options: [ options: [
{ {
displayName: 'ID', displayName: 'Channel ID',
name: 'id', name: 'channelId',
type: 'string', type: 'string',
default: '', default: '',
description: `The id parameter specifies a comma-separated list of the YouTube video ID(s) for the resource(s) that are being retrieved. In a video resource, the id property specifies the video's YouTube video ID.`, description: `The channelId parameter indicates that the API response should only contain resources created by the channel.`,
}, },
{ {
displayName: 'My Rating', displayName: 'For Developer',
name: 'myRating', name: 'forDeveloper',
type: 'options', type: 'boolean',
options: [ default: false,
{ description: `The forDeveloper parameter restricts the search to only retrieve videos uploaded via the developer's application or website`,
name: 'Dislike', },
value: 'dislike', {
}, displayName: 'Published After',
{ name: 'publishedAfter',
name: 'Like', type: 'dateTime',
value: 'like',
},
],
default: '', default: '',
description: `Set this parameter's value to like or dislike to instruct the API to only return videos liked or disliked by the authenticated user.`, description: `The publishedAfter parameter indicates that the API response should only contain resources created at or after the specified time.`,
},
{
displayName: 'Published Before',
name: 'publishedBefore',
type: 'dateTime',
default: '',
description: `The publishedBefore parameter indicates that the API response should only contain resources created before or at the specified time.`,
},
{
displayName: 'Query',
name: 'q',
type: 'string',
default: '',
description: `The q parameter specifies the query term to search for.`,
}, },
{ {
displayName: 'Region Code', displayName: 'Region Code',
@ -570,6 +519,13 @@ export const videoFields = [
default: '', default: '',
description: `The regionCode parameter instructs the API to select a video chart available in the specified region.`, description: `The regionCode parameter instructs the API to select a video chart available in the specified region.`,
}, },
{
displayName: 'Related To Video ID',
name: 'relatedToVideoId',
type: 'string',
default: '',
description: 'The relatedToVideoId parameter retrieves a list of videos that are related to the video that the parameter value identifies',
},
{ {
displayName: 'Video Category ID', displayName: 'Video Category ID',
name: 'videoCategoryId', name: 'videoCategoryId',
@ -577,6 +533,34 @@ export const videoFields = [
default: '', default: '',
description: `The videoCategoryId parameter identifies the video category for which the chart should be retrieved.`, description: `The videoCategoryId parameter identifies the video category for which the chart should be retrieved.`,
}, },
{
displayName: 'Video Syndicated ',
name: 'videoSyndicated',
type: 'boolean',
default: false,
description: `The videoSyndicated parameter lets you to restrict a search to only videos that can be played outside youtube.com.`,
},
{
displayName: 'Video Type',
name: 'videoType',
type: 'options',
options: [
{
name: 'Any',
value: 'any',
},
{
name: 'Episode',
value: 'episode',
},
{
name: 'Movie',
value: 'movie',
},
],
default: '',
description: `The videoType parameter lets you restrict a search to a particular type of videos`,
},
], ],
}, },
{ {
@ -597,12 +581,43 @@ export const videoFields = [
}, },
options: [ options: [
{ {
displayName: 'On Behalf Of Content Owner', displayName: 'Order',
name: 'onBehalfOfContentOwner', name: 'order',
type: 'string', type: 'options',
options: [
{
name: 'Date',
value: 'date',
},
{
name: 'Relevance',
value: 'relevance',
},
],
default: 'relevance',
},
{
displayName: 'Safe Search',
name: 'safeSearch',
type: 'options',
options: [
{
name: 'Moderate',
value: 'moderate',
description: 'YouTube will filter some content from search results and, at the least, will filter content that is restricted in your locale',
},
{
name: 'none',
value: 'none',
description: 'YouTube will not filter the search result set',
},
{
name: 'Strict',
value: 'strict',
description: 'YouTube will try to exclude all restricted content from the search result set',
},
],
default: '', default: '',
description: `The onBehalfOfContentOwner parameter indicates that the request's authorization credentials identify<br>
a YouTube CMS user who is acting on behalf of the content owner specified in the parameter value`,
}, },
], ],
}, },

View file

@ -184,9 +184,23 @@ export class YouTube implements INodeType {
if (resource === 'channel') { if (resource === 'channel') {
if (operation === 'get') { if (operation === 'get') {
//https://developers.google.com/youtube/v3/docs/channels/list //https://developers.google.com/youtube/v3/docs/channels/list
const part = this.getNodeParameter('part', i) as string[]; let part = this.getNodeParameter('part', i) as string[];
const channelId = this.getNodeParameter('channelId', i) as string; const channelId = this.getNodeParameter('channelId', i) as string;
if (part.includes('*')) {
part = [
'brandingSettings',
'contentDetails',
'contentOwnerDetails',
'id',
'localizations',
'snippet',
'statistics',
'status',
'topicDetails',
];
}
qs.part = part.join(','); qs.part = part.join(',');
qs.id = channelId; qs.id = channelId;
@ -204,10 +218,24 @@ export class YouTube implements INodeType {
//https://developers.google.com/youtube/v3/docs/channels/list //https://developers.google.com/youtube/v3/docs/channels/list
if (operation === 'getAll') { if (operation === 'getAll') {
const returnAll = this.getNodeParameter('returnAll', i) as boolean; const returnAll = this.getNodeParameter('returnAll', i) as boolean;
const part = this.getNodeParameter('part', i) as string[]; let part = this.getNodeParameter('part', i) as string[];
const options = this.getNodeParameter('options', i) as IDataObject; const options = this.getNodeParameter('options', i) as IDataObject;
const filters = this.getNodeParameter('filters', i) as IDataObject; const filters = this.getNodeParameter('filters', i) as IDataObject;
if (part.includes('*')) {
part = [
'brandingSettings',
'contentDetails',
'contentOwnerDetails',
'id',
'localizations',
'snippet',
'statistics',
'status',
'topicDetails',
];
}
qs.part = part.join(','); qs.part = part.join(',');
Object.assign(qs, options, filters); Object.assign(qs, options, filters);
@ -392,10 +420,21 @@ export class YouTube implements INodeType {
if (resource === 'playlist') { if (resource === 'playlist') {
//https://developers.google.com/youtube/v3/docs/playlists/list //https://developers.google.com/youtube/v3/docs/playlists/list
if (operation === 'get') { if (operation === 'get') {
const part = this.getNodeParameter('part', i) as string[]; let part = this.getNodeParameter('part', i) as string[];
const playlistId = this.getNodeParameter('playlistId', i) as string; const playlistId = this.getNodeParameter('playlistId', i) as string;
const options = this.getNodeParameter('options', i) as IDataObject; const options = this.getNodeParameter('options', i) as IDataObject;
if (part.includes('*')) {
part = [
'contentDetails',
'id',
'localizations',
'player',
'snippet',
'status',
];
}
qs.part = part.join(','); qs.part = part.join(',');
qs.id = playlistId; qs.id = playlistId;
@ -415,10 +454,21 @@ export class YouTube implements INodeType {
//https://developers.google.com/youtube/v3/docs/playlists/list //https://developers.google.com/youtube/v3/docs/playlists/list
if (operation === 'getAll') { if (operation === 'getAll') {
const returnAll = this.getNodeParameter('returnAll', i) as boolean; const returnAll = this.getNodeParameter('returnAll', i) as boolean;
const part = this.getNodeParameter('part', i) as string[]; let part = this.getNodeParameter('part', i) as string[];
const options = this.getNodeParameter('options', i) as IDataObject; const options = this.getNodeParameter('options', i) as IDataObject;
const filters = this.getNodeParameter('filters', i) as IDataObject; const filters = this.getNodeParameter('filters', i) as IDataObject;
if (part.includes('*')) {
part = [
'contentDetails',
'id',
'localizations',
'player',
'snippet',
'status',
];
}
qs.part = part.join(','); qs.part = part.join(',');
Object.assign(qs, options, filters); Object.assign(qs, options, filters);
@ -567,21 +617,26 @@ export class YouTube implements INodeType {
} }
} }
if (resource === 'video') { if (resource === 'video') {
//https://developers.google.com/youtube/v3/docs/videos/list?hl=en //https://developers.google.com/youtube/v3/docs/search/list
if (operation === 'getAll') { if (operation === 'getAll') {
const returnAll = this.getNodeParameter('returnAll', i) as boolean; const returnAll = this.getNodeParameter('returnAll', i) as boolean;
const part = this.getNodeParameter('part', i) as string[];
const options = this.getNodeParameter('options', i) as IDataObject; const options = this.getNodeParameter('options', i) as IDataObject;
const filters = this.getNodeParameter('filters', i) as IDataObject; const filters = this.getNodeParameter('filters', i) as IDataObject;
qs.part = part.join(','); qs.part = 'snippet';
qs.chart = 'mostPopular'; qs.type = 'video';
qs.forMine = true;
Object.assign(qs, options, filters); Object.assign(qs, options, filters);
if (qs.myRating) { if (Object.keys(filters).length > 0) {
delete qs.chart; delete qs.forMine;
}
if (qs.relatedToVideoId && qs.forDeveloper !== undefined) {
throw new Error(`When using the parameter 'related to video' the parameter 'for developer' cannot be set`);
} }
if (returnAll) { if (returnAll) {
@ -589,7 +644,7 @@ export class YouTube implements INodeType {
this, this,
'items', 'items',
'GET', 'GET',
`/youtube/v3/videos`, `/youtube/v3/search`,
{}, {},
qs qs
); );
@ -598,7 +653,7 @@ export class YouTube implements INodeType {
responseData = await googleApiRequest.call( responseData = await googleApiRequest.call(
this, this,
'GET', 'GET',
`/youtube/v3/videos`, `/youtube/v3/search`,
{}, {},
qs qs
); );
@ -607,10 +662,25 @@ export class YouTube implements INodeType {
} }
//https://developers.google.com/youtube/v3/docs/videos/list?hl=en //https://developers.google.com/youtube/v3/docs/videos/list?hl=en
if (operation === 'get') { if (operation === 'get') {
const part = this.getNodeParameter('part', i) as string[]; let part = this.getNodeParameter('part', i) as string[];
const videoId = this.getNodeParameter('videoId', i) as string; const videoId = this.getNodeParameter('videoId', i) as string;
const options = this.getNodeParameter('options', i) as IDataObject; const options = this.getNodeParameter('options', i) as IDataObject;
if (part.includes('*')) {
part = [
'contentDetails',
'id',
'liveStreamingDetails',
'localizations',
'player',
'recordingDetails',
'snippet',
'statistics',
'status',
'topicDetails',
];
}
qs.part = part.join(','); qs.part = part.join(',');
qs.id = videoId; qs.id = videoId;
@ -812,8 +882,6 @@ export class YouTube implements INodeType {
body.snippet.defaultLanguage = updateFields.defaultLanguage as string; body.snippet.defaultLanguage = updateFields.defaultLanguage as string;
} }
console.log(body)
responseData = await googleApiRequest.call( responseData = await googleApiRequest.call(
this, this,
'PUT', 'PUT',
@ -838,7 +906,7 @@ export class YouTube implements INodeType {
responseData = await googleApiRequest.call( responseData = await googleApiRequest.call(
this, this,
'DELETE', 'DELETE',
'/youtube/v3/video', '/youtube/v3/videos',
body, body,
); );