refactor: simplify KDrive integration by removing drive operations and using driveId from credentials
This commit is contained in:
@@ -25,7 +25,7 @@
|
||||
"KDrive"
|
||||
],
|
||||
"credentials": [
|
||||
"KDriveCredentials"
|
||||
"KDrive"
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@ import {
|
||||
INodeProperties,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
export class KDriveCredentials implements ICredentialType {
|
||||
export class KDrive implements ICredentialType {
|
||||
name = 'kDriveApi';
|
||||
displayName = 'kDrive API';
|
||||
documentationUrl = 'https://developer.infomaniak.com';
|
||||
@@ -19,7 +19,13 @@ export class KDriveCredentials implements ICredentialType {
|
||||
required: true,
|
||||
description: 'Your kDrive API key',
|
||||
},
|
||||
{
|
||||
displayName: 'Drive ID',
|
||||
name: 'driveId',
|
||||
type: 'string',
|
||||
default: '',
|
||||
required: true,
|
||||
description: 'Your kDrive Drive ID',
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
export const kdriveCredentials = new KDriveCredentials();
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import { KDrive } from './nodes/KDrive/KDrive.node';
|
||||
import { KDriveCredentials, kdriveCredentials } from './nodes/KDrive/KDriveCredentials.api';
|
||||
import { KDrive as KDriveCredentials } from './credentials/KDrive.credentials';
|
||||
|
||||
export { KDrive, KDriveCredentials, kdriveCredentials };
|
||||
export { KDrive, KDriveCredentials };
|
||||
export const kDriveCredentials = new KDriveCredentials();
|
||||
@@ -71,10 +71,16 @@ export function handleApiError(this: IExecuteFunctions, error: any): void {
|
||||
if (error.response) {
|
||||
// The request was made and the server responded with a status code
|
||||
// that falls out of the range of 2xx
|
||||
if (error.response.body && error.response.body.message) {
|
||||
errorMessage = error.response.body.message;
|
||||
} else if (error.response.body && typeof error.response.body === 'string') {
|
||||
errorMessage = error.response.body;
|
||||
if (error.response.body) {
|
||||
if (error.response.body.message) {
|
||||
errorMessage = error.response.body.message;
|
||||
} else if (typeof error.response.body === 'string') {
|
||||
errorMessage = error.response.body;
|
||||
} else if (error.response.body.error && error.response.body.error.description) {
|
||||
errorMessage = error.response.body.error.description;
|
||||
} else {
|
||||
errorMessage = `API Error: ${error.response.statusCode} - ${error.response.statusMessage}`;
|
||||
}
|
||||
} else {
|
||||
errorMessage = `API Error: ${error.response.statusCode} - ${error.response.statusMessage}`;
|
||||
}
|
||||
@@ -83,5 +89,14 @@ export function handleApiError(this: IExecuteFunctions, error: any): void {
|
||||
errorMessage = error.message;
|
||||
}
|
||||
|
||||
// Log the full error for debugging
|
||||
console.error('kDrive API Error:', {
|
||||
errorMessage,
|
||||
statusCode: error.response?.statusCode,
|
||||
statusMessage: error.response?.statusMessage,
|
||||
responseBody: error.response?.body,
|
||||
originalError: error.message
|
||||
});
|
||||
|
||||
throw new Error(`kDrive API Error: ${errorMessage}`);
|
||||
}
|
||||
@@ -50,53 +50,25 @@ export class KDrive implements INodeType {
|
||||
default: 'apiKey',
|
||||
description: 'Authentication method',
|
||||
},
|
||||
{
|
||||
displayName: 'Resource',
|
||||
name: 'resource',
|
||||
type: 'options',
|
||||
noDataExpression: true,
|
||||
options: [
|
||||
{
|
||||
name: 'Drive',
|
||||
value: 'drive',
|
||||
},
|
||||
{
|
||||
name: 'File',
|
||||
value: 'file',
|
||||
},
|
||||
{
|
||||
name: 'Directory',
|
||||
value: 'directory',
|
||||
},
|
||||
],
|
||||
default: 'file',
|
||||
description: 'Resource to operate on',
|
||||
},
|
||||
// Drive operations
|
||||
{
|
||||
displayName: 'Operation',
|
||||
name: 'operation',
|
||||
type: 'options',
|
||||
noDataExpression: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['drive'],
|
||||
},
|
||||
{
|
||||
displayName: 'Resource',
|
||||
name: 'resource',
|
||||
type: 'options',
|
||||
noDataExpression: true,
|
||||
options: [
|
||||
{
|
||||
name: 'File',
|
||||
value: 'file',
|
||||
},
|
||||
{
|
||||
name: 'Directory',
|
||||
value: 'directory',
|
||||
},
|
||||
],
|
||||
default: 'file',
|
||||
description: 'Resource to operate on',
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: 'List Drives',
|
||||
value: 'listDrives',
|
||||
description: 'List all accessible drives',
|
||||
},
|
||||
{
|
||||
name: 'Get Drive Info',
|
||||
value: 'getDriveInfo',
|
||||
description: 'Get information about a specific drive',
|
||||
},
|
||||
],
|
||||
default: 'listDrives',
|
||||
},
|
||||
|
||||
// File operations
|
||||
{
|
||||
displayName: 'Operation',
|
||||
@@ -172,21 +144,7 @@ export class KDrive implements INodeType {
|
||||
],
|
||||
default: 'createDirectory',
|
||||
},
|
||||
// Drive ID
|
||||
{
|
||||
displayName: 'Drive ID',
|
||||
name: 'driveId',
|
||||
type: 'string',
|
||||
required: true,
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['file', 'directory'],
|
||||
operation: ['listFiles', 'getFileInfo', 'uploadFile', 'downloadFile', 'deleteFile', 'searchFiles', 'getFileVersions', 'createDirectory', 'createFile'],
|
||||
},
|
||||
},
|
||||
description: 'The ID of the drive',
|
||||
},
|
||||
|
||||
// File ID for file operations
|
||||
{
|
||||
displayName: 'File ID',
|
||||
@@ -360,17 +318,8 @@ export class KDrive implements INodeType {
|
||||
|
||||
for (let i = 0; i < items.length; i++) {
|
||||
try {
|
||||
if (resource === 'drive') {
|
||||
if (operation === 'listDrives') {
|
||||
const response = await kdriveApiRequest.call(this, 'GET', '/2/drive', {}, credentials);
|
||||
returnData.push({ json: response });
|
||||
} else if (operation === 'getDriveInfo') {
|
||||
const driveId = this.getNodeParameter('driveId', i) as string;
|
||||
const response = await kdriveApiRequest.call(this, 'GET', `/2/drive/${driveId}/settings`, {}, credentials);
|
||||
returnData.push({ json: response });
|
||||
}
|
||||
} else if (resource === 'file') {
|
||||
const driveId = this.getNodeParameter('driveId', i) as string;
|
||||
if (resource === 'file') {
|
||||
const driveId = credentials.driveId as string;
|
||||
|
||||
if (operation === 'listFiles') {
|
||||
const parentDirectoryId = this.getNodeParameter('parentDirectoryId', i) as string;
|
||||
@@ -421,7 +370,7 @@ export class KDrive implements INodeType {
|
||||
returnData.push({ json: response });
|
||||
}
|
||||
} else if (resource === 'directory') {
|
||||
const driveId = this.getNodeParameter('driveId', i) as string;
|
||||
const driveId = credentials.driveId as string;
|
||||
|
||||
if (operation === 'createDirectory') {
|
||||
const parentDirectoryId = this.getNodeParameter('parentDirectoryId', i) as string;
|
||||
|
||||
Reference in New Issue
Block a user