mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
feat(Google Drive Trigger Node): Use resource locator component (#5148)
* ♻️ move GoogleDrive.node.ts search methods to SearchFuntions.ts * ⚡️parameter Folder RLC * ⚡️parameter File RLC * 🎨 File RLC placeholder use 'drive.google.com/xxx' urls
This commit is contained in:
@@ -2,9 +2,7 @@ import { BINARY_ENCODING, IExecuteFunctions } from 'n8n-core';
|
||||
|
||||
import {
|
||||
IDataObject,
|
||||
ILoadOptionsFunctions,
|
||||
INodeExecutionData,
|
||||
INodeListSearchResult,
|
||||
INodeType,
|
||||
INodeTypeDescription,
|
||||
NodeOperationError,
|
||||
@@ -14,21 +12,10 @@ import { googleApiRequest, googleApiRequestAllItems } from './GenericFunctions';
|
||||
|
||||
import { v4 as uuid } from 'uuid';
|
||||
import type { Readable } from 'stream';
|
||||
import { driveSearch, fileSearch, folderSearch } from './SearchFunctions';
|
||||
|
||||
const UPLOAD_CHUNK_SIZE = 256 * 1024;
|
||||
|
||||
interface GoogleDriveFilesItem {
|
||||
id: string;
|
||||
name: string;
|
||||
mimeType: string;
|
||||
webViewLink: string;
|
||||
}
|
||||
|
||||
interface GoogleDriveDriveItem {
|
||||
id: string;
|
||||
name: string;
|
||||
}
|
||||
|
||||
export class GoogleDrive implements INodeType {
|
||||
description: INodeTypeDescription = {
|
||||
displayName: 'Google Drive',
|
||||
@@ -248,7 +235,7 @@ export class GoogleDrive implements INodeType {
|
||||
name: 'url',
|
||||
type: 'string',
|
||||
placeholder:
|
||||
'https://docs.google.com/spreadsheets/d/1-i6Vx0NN-3333eeeeeeeeee333333333/edit',
|
||||
'https://drive.google.com/file/d/1anGBg0b5re2VtF2bKu201_a-Vnz5BHq9Y4r-yBDAj5A/edit',
|
||||
extractValue: {
|
||||
type: 'regex',
|
||||
regex:
|
||||
@@ -2035,73 +2022,9 @@ export class GoogleDrive implements INodeType {
|
||||
|
||||
methods = {
|
||||
listSearch: {
|
||||
async fileSearch(
|
||||
this: ILoadOptionsFunctions,
|
||||
filter?: string,
|
||||
paginationToken?: string,
|
||||
): Promise<INodeListSearchResult> {
|
||||
const query: string[] = [];
|
||||
if (filter) {
|
||||
query.push(`name contains '${filter.replace("'", "\\'")}'`);
|
||||
}
|
||||
query.push("mimeType != 'application/vnd.google-apps.folder'");
|
||||
const res = await googleApiRequest.call(this, 'GET', '/drive/v3/files', undefined, {
|
||||
q: query.join(' and '),
|
||||
pageToken: paginationToken,
|
||||
fields: 'nextPageToken,files(id,name,mimeType,webViewLink)',
|
||||
orderBy: 'name_natural',
|
||||
});
|
||||
return {
|
||||
results: res.files.map((i: GoogleDriveFilesItem) => ({
|
||||
name: i.name,
|
||||
value: i.id,
|
||||
url: i.webViewLink,
|
||||
})),
|
||||
paginationToken: res.nextPageToken,
|
||||
};
|
||||
},
|
||||
async folderSearch(
|
||||
this: ILoadOptionsFunctions,
|
||||
filter?: string,
|
||||
paginationToken?: string,
|
||||
): Promise<INodeListSearchResult> {
|
||||
const query: string[] = [];
|
||||
if (filter) {
|
||||
query.push(`name contains '${filter.replace("'", "\\'")}'`);
|
||||
}
|
||||
query.push("mimeType = 'application/vnd.google-apps.folder'");
|
||||
const res = await googleApiRequest.call(this, 'GET', '/drive/v3/files', undefined, {
|
||||
q: query.join(' and '),
|
||||
pageToken: paginationToken,
|
||||
fields: 'nextPageToken,files(id,name,mimeType,webViewLink)',
|
||||
orderBy: 'name_natural',
|
||||
});
|
||||
return {
|
||||
results: res.files.map((i: GoogleDriveFilesItem) => ({
|
||||
name: i.name,
|
||||
value: i.id,
|
||||
url: i.webViewLink,
|
||||
})),
|
||||
paginationToken: res.nextPageToken,
|
||||
};
|
||||
},
|
||||
async driveSearch(
|
||||
this: ILoadOptionsFunctions,
|
||||
filter?: string,
|
||||
paginationToken?: string,
|
||||
): Promise<INodeListSearchResult> {
|
||||
const res = await googleApiRequest.call(this, 'GET', '/drive/v3/drives', undefined, {
|
||||
q: filter ? `name contains '${filter.replace("'", "\\'")}'` : undefined,
|
||||
pageToken: paginationToken,
|
||||
});
|
||||
return {
|
||||
results: res.drives.map((i: GoogleDriveDriveItem) => ({
|
||||
name: i.name,
|
||||
value: i.id,
|
||||
})),
|
||||
paginationToken: res.nextPageToken,
|
||||
};
|
||||
},
|
||||
fileSearch,
|
||||
folderSearch,
|
||||
driveSearch,
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user