Skip to content

Commit

Permalink
Format
Browse files Browse the repository at this point in the history
  • Loading branch information
pregress committed Jan 7, 2023
1 parent 9c49120 commit c1a4f2a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 26 deletions.
12 changes: 5 additions & 7 deletions credentials/AzureStorageApi.credentials.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import {
ICredentialType,
INodeProperties,
} from 'n8n-workflow';
import { ICredentialType, INodeProperties } from 'n8n-workflow';

export class AzureStorageApi implements ICredentialType {
name = 'azureStorageApi';
displayName = 'Azure Blob Storage API';
documentationUrl = 'https://learn.microsoft.com/en-us/azure/storage/common/storage-account-keys-manage?toc=%2Fazure%2Fstorage%2Fblobs%2Ftoc.json&bc=%2Fazure%2Fstorage%2Fblobs%2Fbreadcrumb%2Ftoc.json&tabs=azure-portal#view-account-access-keys';
documentationUrl =
'https://learn.microsoft.com/en-us/azure/storage/common/storage-account-keys-manage?toc=%2Fazure%2Fstorage%2Fblobs%2Ftoc.json&bc=%2Fazure%2Fstorage%2Fblobs%2Fbreadcrumb%2Ftoc.json&tabs=azure-portal#view-account-access-keys';
properties: INodeProperties[] = [
{
displayName: 'Connection string',
name: 'connectionString',
type: 'string',
default: '',
}
];
},
];
}
17 changes: 9 additions & 8 deletions nodes/AzureBlobStorage/AzureBlobDescription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const containerOperations: INodeProperties[] = [
value: 'getMany',
description: 'List all the containers in a storage account',
action: 'Get many containers',
}
},
],

default: 'getMany',
Expand All @@ -40,10 +40,10 @@ export const containerOperations: INodeProperties[] = [
displayOptions: {
show: {
resource: ['container'],
operation: ['create']
operation: ['create'],
},
},
default: ""
default: '',
},
];

Expand Down Expand Up @@ -73,7 +73,7 @@ export const blobOperations: INodeProperties[] = [
value: 'getMany',
description: 'List blobs inside a container',
action: 'Get many blobs',
}
},
],

default: 'getMany',
Expand All @@ -89,8 +89,8 @@ export const blobOperations: INodeProperties[] = [
resource: ['blob'],
},
},
default: "",
description: "The name of the storage container"
default: '',
description: 'The name of the storage container',
},
{
displayName: 'Blob Name',
Expand All @@ -104,7 +104,8 @@ export const blobOperations: INodeProperties[] = [
operation: ['upload'],
},
},
description: 'Name of the blob that will be created. You can create folders like this: my-folder/my-file.txt.',
description:
'Name of the blob that will be created. You can create folders like this: my-folder/my-file.txt.',
},
{
displayName: 'Binary Property',
Expand All @@ -120,4 +121,4 @@ export const blobOperations: INodeProperties[] = [
},
description: 'Name of the binary property to which to write the data of the read file',
},
];
];
30 changes: 19 additions & 11 deletions nodes/AzureBlobStorage/AzureBlobStorage.node.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import { IBinaryKeyData, IDataObject, IExecuteFunctions, INodeExecutionData, INodeType, INodeTypeDescription, NodeOperationError } from 'n8n-workflow';
import {
IBinaryKeyData,
IDataObject,
IExecuteFunctions,
INodeExecutionData,
INodeType,
INodeTypeDescription,
NodeOperationError,
} from 'n8n-workflow';
import { containerOperations, blobOperations } from './AzureBlobDescription';

export class AzureBlobStorage implements INodeType {
Expand Down Expand Up @@ -41,16 +49,16 @@ export class AzureBlobStorage implements INodeType {
},

...containerOperations,
...blobOperations
...blobOperations,
],
};

async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
const resource = this.getNodeParameter('resource', 0) as string;
const operation = this.getNodeParameter('operation', 0) as string;
//Get credentials the user provided for this node
const credentials = await this.getCredentials('azureStorageApi') as IDataObject;
const { BlobServiceClient } = require("@azure/storage-blob");
const credentials = (await this.getCredentials('azureStorageApi')) as IDataObject;
const { BlobServiceClient } = require('@azure/storage-blob');
const blobServiceClient = BlobServiceClient.fromConnectionString(credentials.connectionString);

const items = this.getInputData();
Expand All @@ -66,8 +74,7 @@ export class AzureBlobStorage implements INodeType {

returnData.push(createContainerResponse as IDataObject);
}
}
else if (resource === 'blob') {
} else if (resource === 'blob') {
const containerName = this.getNodeParameter('container', i) as string;
const containerClient = blobServiceClient.getContainerClient(containerName);

Expand All @@ -78,8 +85,7 @@ export class AzureBlobStorage implements INodeType {
arr.push(blob);
}
returnData.push.apply(returnData, arr as IDataObject[]);
}
else if (operation === 'upload') {
} else if (operation === 'upload') {
const binaryPropertyName = this.getNodeParameter('binaryPropertyName', i) as string;

if (items[i].binary === undefined) {
Expand All @@ -101,12 +107,15 @@ export class AzureBlobStorage implements INodeType {
}
const blobName = this.getNodeParameter('blobName', i) as string;
const blockBlobClient = containerClient.getBlockBlobClient(blobName);
const uploadBlobResponse = await blockBlobClient.upload(binaryDataBuffer, binaryDataBuffer.length);
const uploadBlobResponse = await blockBlobClient.upload(
binaryDataBuffer,
binaryDataBuffer.length,
);
returnData.push(uploadBlobResponse as IDataObject);
}
}
}

// No node input
if (resource === 'container') {
if (operation === 'getMany') {
Expand All @@ -117,7 +126,6 @@ export class AzureBlobStorage implements INodeType {
}
returnData.push.apply(returnData, arr as IDataObject[]);
}

}

return [this.helpers.returnJsonArray(returnData)];
Expand Down

0 comments on commit c1a4f2a

Please sign in to comment.