feat(Microsoft OneDrive Node): Add rename option for files and folders (#3224)

This commit is contained in:
Jonathan Bennetts 2022-05-15 18:55:09 +01:00 committed by GitHub
parent d8870ecbff
commit 50246d174a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 93 additions and 0 deletions

View file

@ -35,6 +35,11 @@ export const fileOperations: INodeProperties[] = [
value: 'get', value: 'get',
description: 'Get a file', description: 'Get a file',
}, },
{
name: 'Rename',
value: 'rename',
description: 'Rename a file',
},
{ {
name: 'Search', name: 'Search',
value: 'search', value: 'search',
@ -257,6 +262,43 @@ export const fileFields: INodeProperties[] = [
description: 'Field ID', description: 'Field ID',
}, },
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* file:rename */
/* -------------------------------------------------------------------------- */
{
displayName: 'Item ID',
name: 'itemId',
type: 'string',
displayOptions: {
show: {
operation: [
'rename',
],
resource: [
'file',
],
},
},
default: '',
description: 'ID of the file',
},
{
displayName: 'New Name',
name: 'newName',
type: 'string',
displayOptions: {
show: {
operation: [
'rename',
],
resource: [
'file',
],
},
},
default: '',
description: 'New name for file',
},
/* -------------------------------------------------------------------------- */
/* file:search */ /* file:search */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
{ {

View file

@ -30,6 +30,11 @@ export const folderOperations: INodeProperties[] = [
value: 'getChildren', value: 'getChildren',
description: 'Get items inside a folder', description: 'Get items inside a folder',
}, },
{
name: 'Rename',
value: 'rename',
description: 'Rename a folder',
},
{ {
name: 'Search', name: 'Search',
value: 'search', value: 'search',
@ -117,6 +122,43 @@ export const folderFields: INodeProperties[] = [
default: '', default: '',
}, },
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* folder:rename */
/* -------------------------------------------------------------------------- */
{
displayName: 'Item ID',
name: 'itemId',
type: 'string',
displayOptions: {
show: {
operation: [
'rename',
],
resource: [
'folder',
],
},
},
default: '',
description: 'ID of the folder',
},
{
displayName: 'New Name',
name: 'newName',
type: 'string',
displayOptions: {
show: {
operation: [
'rename',
],
resource: [
'folder',
],
},
},
default: '',
description: 'New name for folder',
},
/* -------------------------------------------------------------------------- */
/* folder:search */ /* folder:search */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
{ {

View file

@ -271,6 +271,15 @@ export class MicrosoftOneDrive implements INodeType {
returnData.push(responseData); returnData.push(responseData);
} }
} }
if (resource === 'file' || resource === 'folder') {
if (operation === 'rename') {
const itemId = this.getNodeParameter('itemId', i) as string;
const newName = this.getNodeParameter('newName', i) as string;
const body = {name: newName};
responseData = await microsoftApiRequest.call(this, 'PATCH', `/drive/items/${itemId}`, body);
returnData.push(responseData as IDataObject);
}
}
} catch (error) { } catch (error) {
if (this.continueOnFail()) { if (this.continueOnFail()) {
if (resource === 'file' && operation === 'download') { if (resource === 'file' && operation === 'download') {