Small improvements

This commit is contained in:
ricardo 2020-04-21 23:13:30 -05:00
parent ed52b67329
commit bedc7f88e4
2 changed files with 16 additions and 29 deletions

View file

@ -337,12 +337,11 @@ export class AwsS3 implements INodeType {
if (resource === 'file') { if (resource === 'file') {
//https://docs.aws.amazon.com/AmazonS3/latest/API/API_CopyObject.html //https://docs.aws.amazon.com/AmazonS3/latest/API/API_CopyObject.html
if (operation === 'copy') { if (operation === 'copy') {
const source = this.getNodeParameter('source', i) as string; const sourcePath = this.getNodeParameter('sourcePath', i) as string;
const bucketName = this.getNodeParameter('bucketName', i) as string; const destinationPath = this.getNodeParameter('destinationPath', i) as string;
const destination = this.getNodeParameter('destination', i) as string;
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject; const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
headers['x-amz-copy-source'] = source; headers['x-amz-copy-source'] = sourcePath;
if (additionalFields.requesterPays) { if (additionalFields.requesterPays) {
headers['x-amz-request-payer'] = 'requester'; headers['x-amz-request-payer'] = 'requester';
@ -399,11 +398,17 @@ export class AwsS3 implements INodeType {
headers['x-amz-metadata-directive'] = (additionalFields.metadataDirective as string).toUpperCase(); headers['x-amz-metadata-directive'] = (additionalFields.metadataDirective as string).toUpperCase();
} }
const destinationParts = destinationPath.split('/');
const bucketName = destinationParts[1];
const destination = `/${destinationParts.slice(2, destinationParts.length).join('/')}`;
responseData = await awsApiRequestSOAP.call(this, `${bucketName}.s3`, 'GET', '', '', { location: '' }); responseData = await awsApiRequestSOAP.call(this, `${bucketName}.s3`, 'GET', '', '', { location: '' });
const region = responseData.LocationConstraint._; const region = responseData.LocationConstraint._;
responseData = await awsApiRequestSOAP.call(this, `${bucketName}.s3`, 'PUT', `${destination}`, '', qs, headers, {}, region); responseData = await awsApiRequestSOAP.call(this, `${bucketName}.s3`, 'PUT', destination, '', qs, headers, {}, region);
returnData.push(responseData.CopyObjectResult); returnData.push(responseData.CopyObjectResult);
} }

View file

@ -52,8 +52,8 @@ export const fileFields = [
/* file:copy */ /* file:copy */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
{ {
displayName: 'Source', displayName: 'Source Path',
name: 'source', name: 'sourcePath',
type: 'string', type: 'string',
required: true, required: true,
default: '', default: '',
@ -71,11 +71,12 @@ export const fileFields = [
description: 'The name of the source bucket and key name of the source object, separated by a slash (/)', description: 'The name of the source bucket and key name of the source object, separated by a slash (/)',
}, },
{ {
displayName: 'Bucket Name', displayName: 'Destination Path',
name: 'bucketName', name: 'destinationPath',
type: 'string', type: 'string',
required: true, required: true,
default: '', default: '',
placeholder: '/bucket/my-second-image.jpg',
displayOptions: { displayOptions: {
show: { show: {
resource: [ resource: [
@ -86,26 +87,7 @@ export const fileFields = [
], ],
}, },
}, },
description: 'The name of the destination bucket.', description: 'The name of the destination bucket and key name of the destination object, separated by a slash (/)',
},
{
displayName: 'Destination',
name: 'destination',
type: 'string',
required: true,
default: '',
placeholder: '/my-second-image.jpg',
displayOptions: {
show: {
resource: [
'file',
],
operation: [
'copy',
],
},
},
description: 'The key of the destination object.',
}, },
{ {
displayName: 'Additional Fields', displayName: 'Additional Fields',