From 691682e09c07ec0483560b354283a0fe50db19cc Mon Sep 17 00:00:00 2001 From: Ali BARIN Date: Sun, 2 Apr 2023 15:54:08 +0000 Subject: [PATCH] feat(dropbox): add rename file action --- .../backend/src/apps/dropbox/actions/index.ts | 3 +- .../apps/dropbox/actions/rename-file/index.ts | 45 +++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 packages/backend/src/apps/dropbox/actions/rename-file/index.ts diff --git a/packages/backend/src/apps/dropbox/actions/index.ts b/packages/backend/src/apps/dropbox/actions/index.ts index e37381b9..14f401da 100644 --- a/packages/backend/src/apps/dropbox/actions/index.ts +++ b/packages/backend/src/apps/dropbox/actions/index.ts @@ -1,3 +1,4 @@ import createFolder from "./create-folder"; +import renameFile from "./rename-file"; -export default [createFolder]; +export default [createFolder, renameFile]; diff --git a/packages/backend/src/apps/dropbox/actions/rename-file/index.ts b/packages/backend/src/apps/dropbox/actions/rename-file/index.ts new file mode 100644 index 00000000..abf58c0f --- /dev/null +++ b/packages/backend/src/apps/dropbox/actions/rename-file/index.ts @@ -0,0 +1,45 @@ +import path from 'node:path'; +import defineAction from '../../../../helpers/define-action'; + +export default defineAction({ + name: 'Rename file', + key: 'renameFile', + description: 'Rename a file with the given file path and new name', + arguments: [ + { + label: 'File', + key: 'filePath', + type: 'string' as const, + required: true, + description: + 'Write the full path to the file such as /Folder1/File.pdf', + variables: true, + }, + { + label: 'New Name', + key: 'newName', + type: 'string' as const, + required: true, + description: "Enter the new name for the file (without the extension, e.g., '.pdf')", + variables: true, + }, + ], + + async run($) { + const filePath = $.step.parameters.filePath as string; + const newName = $.step.parameters.newName as string; + const fileObject = path.parse(filePath); + const newPath = path.format({ + dir: fileObject.dir, + ext: fileObject.ext, + name: newName, + }); + + const response = await $.http.post('/2/files/move_v2', { + from_path: filePath, + to_path: newPath, + }); + + $.setActionItem({ raw: response.data.metadata }); + }, +});