mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 01:56:46 +00:00
feat(Google Drive Node): Overhaul (#5941)
This commit is contained in:
55
packages/nodes-base/nodes/Google/Drive/v2/actions/router.ts
Normal file
55
packages/nodes-base/nodes/Google/Drive/v2/actions/router.ts
Normal file
@@ -0,0 +1,55 @@
|
||||
import type { IExecuteFunctions, INodeExecutionData } from 'n8n-workflow';
|
||||
import { NodeOperationError } from 'n8n-workflow';
|
||||
|
||||
import type { GoogleDriveType } from './node.type';
|
||||
|
||||
import * as drive from './drive/Drive.resource';
|
||||
import * as file from './file/File.resource';
|
||||
import * as fileFolder from './fileFolder/FileFolder.resource';
|
||||
import * as folder from './folder/Folder.resource';
|
||||
|
||||
export async function router(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
||||
const items = this.getInputData();
|
||||
const returnData: INodeExecutionData[] = [];
|
||||
|
||||
const resource = this.getNodeParameter<GoogleDriveType>('resource', 0);
|
||||
const operation = this.getNodeParameter('operation', 0);
|
||||
|
||||
const googleDrive = {
|
||||
resource,
|
||||
operation,
|
||||
} as GoogleDriveType;
|
||||
|
||||
for (let i = 0; i < items.length; i++) {
|
||||
try {
|
||||
switch (googleDrive.resource) {
|
||||
case 'drive':
|
||||
returnData.push(...(await drive[googleDrive.operation].execute.call(this, i)));
|
||||
break;
|
||||
case 'file':
|
||||
returnData.push(...(await file[googleDrive.operation].execute.call(this, i, items[i])));
|
||||
break;
|
||||
case 'fileFolder':
|
||||
returnData.push(...(await fileFolder[googleDrive.operation].execute.call(this, i)));
|
||||
break;
|
||||
case 'folder':
|
||||
returnData.push(...(await folder[googleDrive.operation].execute.call(this, i)));
|
||||
break;
|
||||
default:
|
||||
throw new NodeOperationError(this.getNode(), `The resource "${resource}" is not known`);
|
||||
}
|
||||
} catch (error) {
|
||||
if (this.continueOnFail()) {
|
||||
if (resource === 'file' && operation === 'download') {
|
||||
items[i].json = { error: error.message };
|
||||
} else {
|
||||
returnData.push({ json: { error: error.message } });
|
||||
}
|
||||
continue;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
return this.prepareOutputData(returnData);
|
||||
}
|
||||
Reference in New Issue
Block a user