1
1
mirror of https://github.com/n8n-io/n8n.git synced 2024-10-07 18:18:19 +03:00

feat(Notion Node): Add image block (#5237)

This commit is contained in:
Ricardo Espinoza 2023-01-31 04:17:45 -05:00 committed by GitHub
parent a8637a0bc6
commit 36b1e6ef15
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 3 deletions

View File

@ -471,6 +471,21 @@ const textContent = (displayOptions: IDisplayOptions): INodeProperties[] => [
},
];
const imageBlock = (type: string): INodeProperties[] => [
{
displayName: 'Image URL',
name: 'url',
type: 'string',
displayOptions: {
show: {
type: [type],
},
},
default: '',
description: 'Image file reference',
},
];
const block = (blockType: string): INodeProperties[] => {
const data: INodeProperties[] = [];
switch (blockType) {
@ -503,6 +518,9 @@ const block = (blockType: string): INodeProperties[] => {
case 'child_page':
data.push(...title(blockType));
break;
case 'image':
data.push(...imageBlock(blockType));
break;
default:
data.push(
...richText({
@ -573,6 +591,7 @@ export const blocks = (resource: string, operation: string): INodeProperties[] =
...block('child_page'),
...block('bulleted_list_item'),
...block('numbered_list_item'),
...block('image'),
],
},
],

View File

@ -154,6 +154,10 @@ export function getBlockTypes() {
name: 'Numbered List Item',
value: 'numbered_list_item',
},
{
name: 'Image',
value: 'image',
},
];
}
@ -252,6 +256,15 @@ function getTexts(
return results;
}
function getTextBlocks(block: IDataObject) {
return {
text:
block.richText === false
? formatText(block.textContent as string).text
: getTexts(((block.text as IDataObject).text as any) || []),
};
}
export function formatBlocks(blocks: IDataObject[]) {
const results = [];
for (const block of blocks) {
@ -260,9 +273,9 @@ export function formatBlocks(blocks: IDataObject[]) {
type: block.type,
[block.type as string]: {
...(block.type === 'to_do' ? { checked: block.checked } : {}),
// prettier-ignore
text: (block.richText === false) ? formatText(block.textContent as string).text : getTexts((block.text as IDataObject).text as any || []),
...(block.type === 'image' ? { type: 'external', external: { url: block.url } } : {}),
// prettier-ignore,
...(!['to_do', 'image'].includes(block.type as string) ? getTextBlocks(block) : {}),
},
});
}