mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 01:56:46 +00:00
feat(Notion Node): Fetch child blocks recursively (#7304)
Github issue / Community forum post (link here to close automatically):
This commit is contained in:
@@ -81,7 +81,6 @@ export async function notionApiRequestAllItems(
|
||||
propertyName: string,
|
||||
method: string,
|
||||
endpoint: string,
|
||||
|
||||
body: any = {},
|
||||
query: IDataObject = {},
|
||||
): Promise<any> {
|
||||
@@ -109,6 +108,48 @@ export async function notionApiRequestAllItems(
|
||||
return returnData;
|
||||
}
|
||||
|
||||
export async function notionApiRequestGetBlockChildrens(
|
||||
this: IExecuteFunctions | ILoadOptionsFunctions | IPollFunctions,
|
||||
blocks: IDataObject[],
|
||||
responseData: IDataObject[] = [],
|
||||
limit?: number,
|
||||
) {
|
||||
if (blocks.length === 0) return responseData;
|
||||
|
||||
for (const block of blocks) {
|
||||
responseData.push(block);
|
||||
|
||||
if (block.type === 'child_page') continue;
|
||||
|
||||
if (block.has_children) {
|
||||
let childrens = await notionApiRequestAllItems.call(
|
||||
this,
|
||||
'results',
|
||||
'GET',
|
||||
`/blocks/${block.id}/children`,
|
||||
);
|
||||
|
||||
childrens = (childrens || []).map((entry: IDataObject) => ({
|
||||
object: entry.object,
|
||||
parent_id: block.id,
|
||||
...entry,
|
||||
}));
|
||||
|
||||
await notionApiRequestGetBlockChildrens.call(this, childrens, responseData);
|
||||
}
|
||||
|
||||
if (limit && responseData.length === limit) {
|
||||
return responseData;
|
||||
}
|
||||
|
||||
if (limit && responseData.length > limit) {
|
||||
return responseData.slice(0, limit);
|
||||
}
|
||||
}
|
||||
|
||||
return responseData;
|
||||
}
|
||||
|
||||
export function getBlockTypes() {
|
||||
return [
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user