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

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

export const googleDriveTrashFile = createAction({
  auth: googleDriveAuth,
  name: 'trash_gdrive_file',
  classification: 'DESTRUCTIVE',
  description: 'Move a file to the bin, where it can be restored.',
  audience: 'human',
  aiMetadata: { description: 'Moves a Drive file to the trash by its ID, a reversible deletion that can be restored from Drive. Use for safe removal instead of permanent deletion. Requires the file ID. Idempotent: re-trashing an already-trashed file leaves it in the same state.', idempotent: true },
  displayName: 'Move File to Trash',
  props: {
    fileId: Property.ShortText({
      displayName: 'File ID',
      description: 'The ID of the file to trash.',
      required: true,
      placeholder: '1dpv4-sKJfKRwI9qx1vWqQhEGEn3EpbI5',
    }),
    include_team_drives: common.properties.include_team_drives,
  },
  outputSchema: trashGdriveFileActionOutputSchema,
  async run(context) {
    const authClient = await createGoogleClient(context.auth);

    const drive = googleDrive({ version: 'v3', auth: authClient });
    const body_value = {
      trashed: true,
    };
    const response = await drive.files.update({
      fileId: context.propsValue.fileId,
      supportsAllDrives: context.propsValue.include_team_drives,
      requestBody: body_value,
    });

    return response.data;
  },
});