fix(Notion Node): Extract page url (#11643)

Co-authored-by: Elias Meire <elias@meire.dev>
This commit is contained in:
Michael Kret
2024-11-11 15:03:12 +02:00
committed by GitHub
parent b0ba24cbbc
commit cbdd535fe0
3 changed files with 149 additions and 15 deletions

View File

@@ -8,6 +8,7 @@ import type {
ILoadOptionsFunctions,
INode,
INodeExecutionData,
INodeParameterResourceLocator,
INodeProperties,
IPairedItemData,
IPollFunctions,
@@ -23,7 +24,7 @@ import moment from 'moment-timezone';
import { validate as uuidValidate } from 'uuid';
import set from 'lodash/set';
import { filters } from './descriptions/Filters';
import { blockUrlExtractionRegexp } from './constants';
import { blockUrlExtractionRegexp, databasePageUrlValidationRegexp } from './constants';
function uuidValidateWithoutDashes(this: IExecuteFunctions, value: string) {
if (uuidValidate(value)) return true;
@@ -916,6 +917,32 @@ export function extractPageId(page = '') {
return page;
}
export function getPageId(this: IExecuteFunctions, i: number) {
const page = this.getNodeParameter('pageId', i, {}) as INodeParameterResourceLocator;
let pageId = '';
if (page.value && typeof page.value === 'string') {
if (page.mode === 'id') {
pageId = page.value;
} else if (page.value.includes('p=')) {
// e.g https://www.notion.so/xxxxx?v=xxxxx&p=xxxxx&pm=s
pageId = new URLSearchParams(page.value).get('p') || '';
} else {
// e.g https://www.notion.so/page_name-xxxxx
pageId = page.value.match(databasePageUrlValidationRegexp)?.[1] || '';
}
}
if (!pageId) {
throw new NodeOperationError(
this.getNode(),
'Could not extract page ID from URL: ' + page.value,
);
}
return pageId;
}
export function extractDatabaseId(database: string) {
if (database.includes('?v=')) {
const data = database.split('?v=')[0].split('/');