Skip to content

AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents

2.0 KB
Raw Blame
import { googleDriveAuth, createGoogleClient } from '../auth';
import { createAction, Property } from '@activepieces/pieces-framework';
import { common } from '../common';
import { drive as googleDrive } from '@googleapis/drive';
import { googleDriveMoveFileActionOutputSchema } from '../output-schemas';

export const moveFileAction = createAction({
  auth: googleDriveAuth,
  name: 'google-drive-move-file',
  classification: 'WRITE',
  displayName: 'Move File',
  description: 'Move a file into another folder.',
  audience: 'human',
  aiMetadata: { description: 'Relocates a Drive file to a target folder, detaching it from its current parents and attaching it to the new one. Use to reorganize a file once you know its ID and the destination folder ID. Idempotent: repeating with the same destination leaves the file in the same folder.', idempotent: true },
  props: {
    fileId: Property.ShortText({
      displayName: 'File ID',
      description: 'Use the ID from a trigger or the Find File or Folder action.',
      required: true,
      placeholder: '1dpv4-sKJfKRwI9qx1vWqQhEGEn3EpbI5',
    }),
    folderId: common.parentFolderDropdown({
      displayName: 'Destination Folder',
      description: 'The folder to move the file into. Type to search by folder name.',
    }),
    include_team_drives: common.properties.include_team_drives,
  },
  outputSchema: googleDriveMoveFileActionOutputSchema,
  async run(context) {
    const fileId = context.propsValue.fileId;
    const folderId = context.propsValue.folderId;

    const authClient = await createGoogleClient(context.auth);

    const drive = googleDrive({ version: 'v3', auth: authClient });

    const file = await drive.files.get({
      fileId,
      supportsAllDrives: context.propsValue.include_team_drives,
      fields: 'id,parents',
    });

    const response = await drive.files.update({
      fileId: fileId,
      fields: '*',
      removeParents: file.data.parents?.join(','),
      addParents: folderId,
      supportsAllDrives: context.propsValue.include_team_drives,
    });

    return response.data;
  },
});