Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Google Drive Node): Fix regex in file RLC #6607

Merged
merged 5 commits into from
Jul 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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',
},
},
Expand Down Expand Up @@ -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',
},
},
Expand Down
19 changes: 7 additions & 12 deletions packages/nodes-base/nodes/Google/Drive/v1/GoogleDriveV1.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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',
},
},
Expand Down Expand Up @@ -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',
},
},
Expand Down Expand Up @@ -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',
},
},
Expand Down
Original file line number Diff line number Diff line change
@@ -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',
Expand All @@ -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',
},
},
Expand Down Expand Up @@ -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',
},
},
Expand Down Expand Up @@ -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',
},
},
Expand Down Expand Up @@ -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',
},
},
Expand Down Expand Up @@ -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',
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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',
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 };

Expand Down Expand Up @@ -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',
},
},
Expand Down
Original file line number Diff line number Diff line change
@@ -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 = [
// {
Expand Down Expand Up @@ -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',
},
},
Expand Down
5 changes: 5 additions & 0 deletions packages/nodes-base/nodes/Google/constants.ts
Original file line number Diff line number Diff line change
@@ -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\\-_]+)(?:\\/.*|)';