mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-18 10:31:15 +00:00
fix(Notion Node): Extract page url (#11643)
Co-authored-by: Elias Meire <elias@meire.dev>
This commit is contained in:
@@ -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('/');
|
||||
|
||||
Reference in New Issue
Block a user