From 56721468dff51bb60ececc0472e2b9ca0740fcb1 Mon Sep 17 00:00:00 2001 From: Michael Kret <88898367+michael-radency@users.noreply.github.com> Date: Wed, 5 Jul 2023 23:15:13 +0300 Subject: [PATCH] fix(Google Drive Node): Fix regex in file RLC (#6607) --- .../Google/Drive/GoogleDriveTrigger.node.ts | 13 +++----- .../Google/Drive/v1/GoogleDriveV1.node.ts | 19 +++++------- .../Drive/v2/actions/common.descriptions.ts | 31 +++++++------------ .../Google/Sheet/GoogleSheetsTrigger.node.ts | 7 ++--- .../Sheet/v2/actions/sheet/Sheet.resource.ts | 7 ++--- .../actions/spreadsheet/delete.operation.ts | 7 ++--- packages/nodes-base/nodes/Google/constants.ts | 5 +++ 7 files changed, 37 insertions(+), 52 deletions(-) create mode 100644 packages/nodes-base/nodes/Google/constants.ts diff --git a/packages/nodes-base/nodes/Google/Drive/GoogleDriveTrigger.node.ts b/packages/nodes-base/nodes/Google/Drive/GoogleDriveTrigger.node.ts index 093b0a5ca..37e820cfc 100644 --- a/packages/nodes-base/nodes/Google/Drive/GoogleDriveTrigger.node.ts +++ b/packages/nodes-base/nodes/Google/Drive/GoogleDriveTrigger.node.ts @@ -13,6 +13,7 @@ import { extractId, googleApiRequest, googleApiRequestAllItems } from './v1/Gene import moment from 'moment'; import { fileSearch, folderSearch } from './v1/SearchFunctions'; +import { GOOGLE_DRIVE_FILE_URL_REGEX, GOOGLE_DRIVE_FOLDER_URL_REGEX } from '../constants'; export class GoogleDriveTrigger implements INodeType { description: INodeTypeDescription = { @@ -112,15 +113,13 @@ export class GoogleDriveTrigger implements INodeType { placeholder: 'https://drive.google.com/file/d/1wroCSfK-hupQIYf_xzeoUEzOhvfTFH2P/edit', extractValue: { type: 'regex', - regex: - 'https:\\/\\/(?:drive|docs)\\.google\\.com(?:\\/.*|)\\/d\\/([0-9a-zA-Z\\-_]+)(?:\\/.*|)', + regex: GOOGLE_DRIVE_FILE_URL_REGEX, }, validation: [ { type: 'regex', properties: { - regex: - 'https:\\/\\/(?:drive|docs)\\.google.com(?:\\/.*|)\\/d\\/([0-9a-zA-Z\\-_]+)(?:\\/.*|)', + regex: GOOGLE_DRIVE_FILE_URL_REGEX, errorMessage: 'Not a valid Google Drive File URL', }, }, @@ -192,15 +191,13 @@ export class GoogleDriveTrigger implements INodeType { placeholder: 'https://drive.google.com/drive/folders/1Tx9WHbA3wBpPB4C_HcoZDH9WZFWYxAMU', extractValue: { type: 'regex', - regex: - 'https:\\/\\/drive\\.google\\.com(?:\\/.*|)\\/folders\\/([0-9a-zA-Z\\-_]+)(?:\\/.*|)', + regex: GOOGLE_DRIVE_FOLDER_URL_REGEX, }, validation: [ { type: 'regex', properties: { - regex: - 'https:\\/\\/drive\\.google\\.com(?:\\/.*|)\\/folders\\/([0-9a-zA-Z\\-_]+)(?:\\/.*|)', + regex: GOOGLE_DRIVE_FOLDER_URL_REGEX, errorMessage: 'Not a valid Google Drive Folder URL', }, }, diff --git a/packages/nodes-base/nodes/Google/Drive/v1/GoogleDriveV1.node.ts b/packages/nodes-base/nodes/Google/Drive/v1/GoogleDriveV1.node.ts index 08c254daa..1fc7503b7 100644 --- a/packages/nodes-base/nodes/Google/Drive/v1/GoogleDriveV1.node.ts +++ b/packages/nodes-base/nodes/Google/Drive/v1/GoogleDriveV1.node.ts @@ -17,6 +17,7 @@ import type { Readable } from 'stream'; import { driveSearch, fileSearch, folderSearch } from './SearchFunctions'; import { oldVersionNotice } from '@utils/descriptions'; +import { GOOGLE_DRIVE_FILE_URL_REGEX, GOOGLE_DRIVE_FOLDER_URL_REGEX } from '../../constants'; const UPLOAD_CHUNK_SIZE = 256 * 1024; @@ -242,15 +243,13 @@ const versionDescription: INodeTypeDescription = { 'https://drive.google.com/file/d/1anGBg0b5re2VtF2bKu201_a-Vnz5BHq9Y4r-yBDAj5A/edit', extractValue: { type: 'regex', - regex: - 'https:\\/\\/(?:drive|docs)\\.google\\.com\\/\\w+\\/d\\/([0-9a-zA-Z\\-_]+)(?:\\/.*|)', + regex: GOOGLE_DRIVE_FILE_URL_REGEX, }, validation: [ { type: 'regex', properties: { - regex: - 'https:\\/\\/(?:drive|docs)\\.google.com\\/\\w+\\/d\\/([0-9a-zA-Z\\-_]+)(?:\\/.*|)', + regex: GOOGLE_DRIVE_FILE_URL_REGEX, errorMessage: 'Not a valid Google Drive File URL', }, }, @@ -306,15 +305,13 @@ const versionDescription: INodeTypeDescription = { placeholder: 'https://drive.google.com/drive/folders/1Tx9WHbA3wBpPB4C_HcoZDH9WZFWYxAMU', extractValue: { type: 'regex', - regex: - 'https:\\/\\/drive\\.google\\.com\\/\\w+\\/folders\\/([0-9a-zA-Z\\-_]+)(?:\\/.*|)', + regex: GOOGLE_DRIVE_FOLDER_URL_REGEX, }, validation: [ { type: 'regex', properties: { - regex: - 'https:\\/\\/drive\\.google\\.com\\/\\w+\\/folders\\/([0-9a-zA-Z\\-_]+)(?:\\/.*|)', + regex: GOOGLE_DRIVE_FOLDER_URL_REGEX, errorMessage: 'Not a valid Google Drive Folder URL', }, }, @@ -1489,15 +1486,13 @@ const versionDescription: INodeTypeDescription = { placeholder: 'https://drive.google.com/drive/folders/0AaaaaAAAAAAAaa', extractValue: { type: 'regex', - regex: - 'https:\\/\\/drive\\.google\\.com\\/\\w+\\/folders\\/([0-9a-zA-Z\\-_]+)(?:\\/.*|)', + regex: GOOGLE_DRIVE_FOLDER_URL_REGEX, }, validation: [ { type: 'regex', properties: { - regex: - 'https:\\/\\/drive\\.google\\.com\\/\\w+\\/folders\\/([0-9a-zA-Z\\-_]+)(?:\\/.*|)', + regex: GOOGLE_DRIVE_FOLDER_URL_REGEX, errorMessage: 'Not a valid Google Drive Drive URL', }, }, diff --git a/packages/nodes-base/nodes/Google/Drive/v2/actions/common.descriptions.ts b/packages/nodes-base/nodes/Google/Drive/v2/actions/common.descriptions.ts index d9179ff18..1cb6d0591 100644 --- a/packages/nodes-base/nodes/Google/Drive/v2/actions/common.descriptions.ts +++ b/packages/nodes-base/nodes/Google/Drive/v2/actions/common.descriptions.ts @@ -1,5 +1,6 @@ import type { INodeProperties } from 'n8n-workflow'; import { DRIVE, RLC_DRIVE_DEFAULT } from '../helpers/interfaces'; +import { GOOGLE_DRIVE_FILE_URL_REGEX, GOOGLE_DRIVE_FOLDER_URL_REGEX } from '../../../constants'; export const fileRLC: INodeProperties = { displayName: 'File', @@ -26,15 +27,13 @@ export const fileRLC: INodeProperties = { 'e.g. https://drive.google.com/file/d/1anGBg0b5re2VtF2bKu201_a-Vnz5BHq9Y4r-yBDAj5A/edit', extractValue: { type: 'regex', - regex: - 'https:\\/\\/(?:drive|docs)\\.google\\.com\\/\\w+\\/d\\/([0-9a-zA-Z\\-_]+)(?:\\/.*|)', + regex: GOOGLE_DRIVE_FILE_URL_REGEX, }, validation: [ { type: 'regex', properties: { - regex: - 'https:\\/\\/(?:drive|docs)\\.google.com\\/\\w+\\/d\\/([0-9a-zA-Z\\-_]+)(?:\\/.*|)', + regex: GOOGLE_DRIVE_FILE_URL_REGEX, errorMessage: 'Not a valid Google Drive File URL', }, }, @@ -84,15 +83,13 @@ export const folderNoRootRLC: INodeProperties = { placeholder: 'e.g. https://drive.google.com/drive/folders/1Tx9WHbA3wBpPB4C_HcoZDH9WZFWYxAMU', extractValue: { type: 'regex', - regex: - 'https:\\/\\/drive\\.google\\.com(?:\\/.*|)\\/folders\\/([0-9a-zA-Z\\-_]+)(?:\\/.*|)', + regex: GOOGLE_DRIVE_FOLDER_URL_REGEX, }, validation: [ { type: 'regex', properties: { - regex: - 'https:\\/\\/drive\\.google\\.com(?:\\/.*|)\\/folders\\/([0-9a-zA-Z\\-_]+)(?:\\/.*|)', + regex: GOOGLE_DRIVE_FOLDER_URL_REGEX, errorMessage: 'Not a valid Google Drive Folder URL', }, }, @@ -142,15 +139,13 @@ export const folderRLC: INodeProperties = { placeholder: 'e.g. https://drive.google.com/drive/folders/1Tx9WHbA3wBpPB4C_HcoZDH9WZFWYxAMU', extractValue: { type: 'regex', - regex: - 'https:\\/\\/drive\\.google\\.com(?:\\/.*|)\\/folders\\/([0-9a-zA-Z\\-_]+)(?:\\/.*|)', + regex: GOOGLE_DRIVE_FOLDER_URL_REGEX, }, validation: [ { type: 'regex', properties: { - regex: - 'https:\\/\\/drive\\.google\\.com(?:\\/.*|)\\/folders\\/([0-9a-zA-Z\\-_]+)(?:\\/.*|)', + regex: GOOGLE_DRIVE_FOLDER_URL_REGEX, errorMessage: 'Not a valid Google Drive Folder URL', }, }, @@ -200,15 +195,13 @@ export const driveRLC: INodeProperties = { placeholder: 'https://drive.google.com/drive/folders/0AaaaaAAAAAAAaa', extractValue: { type: 'regex', - regex: - 'https:\\/\\/drive\\.google\\.com(?:\\/.*|)\\/folders\\/([0-9a-zA-Z\\-_]+)(?:\\/.*|)', + regex: GOOGLE_DRIVE_FOLDER_URL_REGEX, }, validation: [ { type: 'regex', properties: { - regex: - 'https:\\/\\/drive\\.google\\.com(?:\\/.*|)\\/folders\\/([0-9a-zA-Z\\-_]+)(?:\\/.*|)', + regex: GOOGLE_DRIVE_FOLDER_URL_REGEX, errorMessage: 'Not a valid Google Drive Drive URL', }, }, @@ -258,15 +251,13 @@ export const sharedDriveRLC: INodeProperties = { placeholder: 'e.g. https://drive.google.com/drive/u/1/folders/0AIjtcbwnjtcbwn9PVA', extractValue: { type: 'regex', - regex: - 'https:\\/\\/drive\\.google\\.com(?:\\/.*|)\\/folders\\/([0-9a-zA-Z\\-_]+)(?:\\/.*|)', + regex: GOOGLE_DRIVE_FOLDER_URL_REGEX, }, validation: [ { type: 'regex', properties: { - regex: - 'https:\\/\\/drive\\.google\\.com(?:\\/.*|)\\/folders\\/([0-9a-zA-Z\\-_]+)(?:\\/.*|)', + regex: GOOGLE_DRIVE_FOLDER_URL_REGEX, errorMessage: 'Not a valid Google Drive Drive URL', }, }, diff --git a/packages/nodes-base/nodes/Google/Sheet/GoogleSheetsTrigger.node.ts b/packages/nodes-base/nodes/Google/Sheet/GoogleSheetsTrigger.node.ts index 71095c94f..390e8773a 100644 --- a/packages/nodes-base/nodes/Google/Sheet/GoogleSheetsTrigger.node.ts +++ b/packages/nodes-base/nodes/Google/Sheet/GoogleSheetsTrigger.node.ts @@ -20,6 +20,7 @@ import { getRevisionFile, sheetBinaryToArrayOfArrays, } from './GoogleSheetsTrigger.utils'; +import { GOOGLE_DRIVE_FILE_URL_REGEX } from '../constants'; export class GoogleSheetsTrigger implements INodeType { description: INodeTypeDescription = { @@ -84,15 +85,13 @@ export class GoogleSheetsTrigger implements INodeType { type: 'string', extractValue: { type: 'regex', - regex: - 'https:\\/\\/(?:drive|docs)\\.google\\.com(?:\\/.*|)\\/d\\/([0-9a-zA-Z\\-_]+)(?:\\/.*|)', + regex: GOOGLE_DRIVE_FILE_URL_REGEX, }, validation: [ { type: 'regex', properties: { - regex: - 'https:\\/\\/(?:drive|docs)\\.google.com(?:\\/.*|)\\/d\\/([0-9a-zA-Z\\-_]+)(?:\\/.*|)', + regex: GOOGLE_DRIVE_FILE_URL_REGEX, errorMessage: 'Not a valid Google Drive File URL', }, }, diff --git a/packages/nodes-base/nodes/Google/Sheet/v2/actions/sheet/Sheet.resource.ts b/packages/nodes-base/nodes/Google/Sheet/v2/actions/sheet/Sheet.resource.ts index 6e67e3a0e..0be8b33ee 100644 --- a/packages/nodes-base/nodes/Google/Sheet/v2/actions/sheet/Sheet.resource.ts +++ b/packages/nodes-base/nodes/Google/Sheet/v2/actions/sheet/Sheet.resource.ts @@ -7,6 +7,7 @@ import * as del from './delete.operation'; import * as read from './read.operation'; import * as remove from './remove.operation'; import * as update from './update.operation'; +import { GOOGLE_DRIVE_FILE_URL_REGEX } from '../../../../constants'; export { append, appendOrUpdate, clear, create, del as delete, read, remove, update }; @@ -96,15 +97,13 @@ export const descriptions: INodeProperties[] = [ type: 'string', extractValue: { type: 'regex', - regex: - 'https:\\/\\/(?:drive|docs)\\.google\\.com(?:\\/.*|)\\/d\\/([0-9a-zA-Z\\-_]+)(?:\\/.*|)', + regex: GOOGLE_DRIVE_FILE_URL_REGEX, }, validation: [ { type: 'regex', properties: { - regex: - 'https:\\/\\/(?:drive|docs)\\.google.com(?:\\/.*|)\\/d\\/([0-9a-zA-Z\\-_]+)(?:\\/.*|)', + regex: GOOGLE_DRIVE_FILE_URL_REGEX, errorMessage: 'Not a valid Google Drive File URL', }, }, diff --git a/packages/nodes-base/nodes/Google/Sheet/v2/actions/spreadsheet/delete.operation.ts b/packages/nodes-base/nodes/Google/Sheet/v2/actions/spreadsheet/delete.operation.ts index d8008bd40..9157e941c 100644 --- a/packages/nodes-base/nodes/Google/Sheet/v2/actions/spreadsheet/delete.operation.ts +++ b/packages/nodes-base/nodes/Google/Sheet/v2/actions/spreadsheet/delete.operation.ts @@ -1,6 +1,7 @@ import type { IExecuteFunctions, IDataObject, INodeExecutionData } from 'n8n-workflow'; import type { SpreadSheetProperties } from '../../helpers/GoogleSheets.types'; import { apiRequest } from '../../transport'; +import { GOOGLE_DRIVE_FILE_URL_REGEX } from '../../../../constants'; export const description: SpreadSheetProperties = [ // { @@ -37,15 +38,13 @@ export const description: SpreadSheetProperties = [ type: 'string', extractValue: { type: 'regex', - regex: - 'https:\\/\\/(?:drive|docs)\\.google\\.com(?:\\/.*|)\\/d\\/([0-9a-zA-Z\\-_]+)(?:\\/.*|)', + regex: GOOGLE_DRIVE_FILE_URL_REGEX, }, validation: [ { type: 'regex', properties: { - regex: - 'https:\\/\\/(?:drive|docs)\\.google.com(?:\\/.*|)\\/d\\/([0-9a-zA-Z\\-_]+)(?:\\/.*|)', + regex: GOOGLE_DRIVE_FILE_URL_REGEX, errorMessage: 'Not a valid Google Drive File URL', }, }, diff --git a/packages/nodes-base/nodes/Google/constants.ts b/packages/nodes-base/nodes/Google/constants.ts new file mode 100644 index 000000000..374cb345b --- /dev/null +++ b/packages/nodes-base/nodes/Google/constants.ts @@ -0,0 +1,5 @@ +export const GOOGLE_DRIVE_FILE_URL_REGEX = + 'https:\\/\\/(?:drive|docs)\\.google\\.com(?:\\/.*|)\\/d\\/([0-9a-zA-Z\\-_]+)(?:\\/.*|)'; + +export const GOOGLE_DRIVE_FOLDER_URL_REGEX = + 'https:\\/\\/drive\\.google\\.com(?:\\/.*|)\\/folders\\/([0-9a-zA-Z\\-_]+)(?:\\/.*|)';