refactor: simplify KDrive integration by removing drive operations and using driveId from credentials
This commit is contained in:
+1
-1
@@ -25,7 +25,7 @@
|
|||||||
"KDrive"
|
"KDrive"
|
||||||
],
|
],
|
||||||
"credentials": [
|
"credentials": [
|
||||||
"KDriveCredentials"
|
"KDrive"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3,7 +3,7 @@ import {
|
|||||||
INodeProperties,
|
INodeProperties,
|
||||||
} from 'n8n-workflow';
|
} from 'n8n-workflow';
|
||||||
|
|
||||||
export class KDriveCredentials implements ICredentialType {
|
export class KDrive implements ICredentialType {
|
||||||
name = 'kDriveApi';
|
name = 'kDriveApi';
|
||||||
displayName = 'kDrive API';
|
displayName = 'kDrive API';
|
||||||
documentationUrl = 'https://developer.infomaniak.com';
|
documentationUrl = 'https://developer.infomaniak.com';
|
||||||
@@ -19,7 +19,13 @@ export class KDriveCredentials implements ICredentialType {
|
|||||||
required: true,
|
required: true,
|
||||||
description: 'Your kDrive API key',
|
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();
|
|
||||||
+3
-2
@@ -1,4 +1,5 @@
|
|||||||
import { KDrive } from './nodes/KDrive/KDrive.node';
|
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) {
|
if (error.response) {
|
||||||
// The request was made and the server responded with a status code
|
// The request was made and the server responded with a status code
|
||||||
// that falls out of the range of 2xx
|
// that falls out of the range of 2xx
|
||||||
if (error.response.body && error.response.body.message) {
|
if (error.response.body) {
|
||||||
|
if (error.response.body.message) {
|
||||||
errorMessage = error.response.body.message;
|
errorMessage = error.response.body.message;
|
||||||
} else if (error.response.body && typeof error.response.body === 'string') {
|
} else if (typeof error.response.body === 'string') {
|
||||||
errorMessage = error.response.body;
|
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 {
|
} else {
|
||||||
errorMessage = `API Error: ${error.response.statusCode} - ${error.response.statusMessage}`;
|
errorMessage = `API Error: ${error.response.statusCode} - ${error.response.statusMessage}`;
|
||||||
}
|
}
|
||||||
@@ -83,5 +89,14 @@ export function handleApiError(this: IExecuteFunctions, error: any): void {
|
|||||||
errorMessage = error.message;
|
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}`);
|
throw new Error(`kDrive API Error: ${errorMessage}`);
|
||||||
}
|
}
|
||||||
@@ -56,10 +56,6 @@ export class KDrive implements INodeType {
|
|||||||
type: 'options',
|
type: 'options',
|
||||||
noDataExpression: true,
|
noDataExpression: true,
|
||||||
options: [
|
options: [
|
||||||
{
|
|
||||||
name: 'Drive',
|
|
||||||
value: 'drive',
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
name: 'File',
|
name: 'File',
|
||||||
value: 'file',
|
value: 'file',
|
||||||
@@ -72,31 +68,7 @@ export class KDrive implements INodeType {
|
|||||||
default: 'file',
|
default: 'file',
|
||||||
description: 'Resource to operate on',
|
description: 'Resource to operate on',
|
||||||
},
|
},
|
||||||
// Drive operations
|
|
||||||
{
|
|
||||||
displayName: 'Operation',
|
|
||||||
name: 'operation',
|
|
||||||
type: 'options',
|
|
||||||
noDataExpression: true,
|
|
||||||
displayOptions: {
|
|
||||||
show: {
|
|
||||||
resource: ['drive'],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
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
|
// File operations
|
||||||
{
|
{
|
||||||
displayName: 'Operation',
|
displayName: 'Operation',
|
||||||
@@ -172,21 +144,7 @@ export class KDrive implements INodeType {
|
|||||||
],
|
],
|
||||||
default: 'createDirectory',
|
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
|
// File ID for file operations
|
||||||
{
|
{
|
||||||
displayName: 'File ID',
|
displayName: 'File ID',
|
||||||
@@ -360,17 +318,8 @@ export class KDrive implements INodeType {
|
|||||||
|
|
||||||
for (let i = 0; i < items.length; i++) {
|
for (let i = 0; i < items.length; i++) {
|
||||||
try {
|
try {
|
||||||
if (resource === 'drive') {
|
if (resource === 'file') {
|
||||||
if (operation === 'listDrives') {
|
const driveId = credentials.driveId as string;
|
||||||
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 (operation === 'listFiles') {
|
if (operation === 'listFiles') {
|
||||||
const parentDirectoryId = this.getNodeParameter('parentDirectoryId', i) as string;
|
const parentDirectoryId = this.getNodeParameter('parentDirectoryId', i) as string;
|
||||||
@@ -421,7 +370,7 @@ export class KDrive implements INodeType {
|
|||||||
returnData.push({ json: response });
|
returnData.push({ json: response });
|
||||||
}
|
}
|
||||||
} else if (resource === 'directory') {
|
} else if (resource === 'directory') {
|
||||||
const driveId = this.getNodeParameter('driveId', i) as string;
|
const driveId = credentials.driveId as string;
|
||||||
|
|
||||||
if (operation === 'createDirectory') {
|
if (operation === 'createDirectory') {
|
||||||
const parentDirectoryId = this.getNodeParameter('parentDirectoryId', i) as string;
|
const parentDirectoryId = this.getNodeParameter('parentDirectoryId', i) as string;
|
||||||
|
|||||||
Reference in New Issue
Block a user