Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/pieces/community/google-drive/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@activepieces/piece-google-drive",
"version": "0.7.9",
"version": "0.7.10",
"main": "./dist/src/index.js",
"types": "./dist/src/index.d.ts",
"dependencies": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import { createAction, Property } from '@activepieces/pieces-framework';
import {
httpClient,
HttpMethod,
AuthenticationType,
} from '@activepieces/pieces-common';
import FormData from 'form-data';
import { googleDriveAuth, getAccessToken } from '../auth';
import { drive as googleDrive } from '@googleapis/drive';
import { googleDriveAuth, createGoogleClient } from '../auth';
import { common } from '../common';
import { createNewGdriveFileActionOutputSchema } from '../output-schemas';

Expand All @@ -31,12 +26,12 @@ export const googleDriveCreateNewTextFile = createAction({
displayName: 'Content type',
description: 'Select file type',
required: true,
defaultValue: 'plain/text',
defaultValue: 'text/plain',
options: {
options: [
{
label: 'Text',
value: 'plain/text',
value: 'text/plain',
},
{
label: 'CSV',
Expand All @@ -54,40 +49,32 @@ export const googleDriveCreateNewTextFile = createAction({
},
outputSchema: createNewGdriveFileActionOutputSchema,
async run(context) {
const meta = {
mimeType: context.propsValue.fileType,
name: context.propsValue.fileName,
...(context.propsValue.parentFolder
? { parents: [context.propsValue.parentFolder] }
: {}),
};
const authClient = await createGoogleClient(context.auth);
const drive = googleDrive({ version: 'v3', auth: authClient });

const metaBuffer = Buffer.from(JSON.stringify(meta), 'utf-8');
const textBuffer = Buffer.from(context.propsValue.text!, 'utf-8');
// Normalize the legacy 'plain/text' value saved by existing flows to the
// valid 'text/plain' MIME type Google Drive expects.
const mimeType =
context.propsValue.fileType === 'plain/text'
? 'text/plain'
: context.propsValue.fileType;

const form = new FormData();
form.append('Metadata', metaBuffer, { contentType: 'application/json' });
form.append('Media', textBuffer, {
contentType: context.propsValue.fileType,
});

const result = await httpClient.sendRequest({
method: HttpMethod.POST,
url: `https://www.googleapis.com/upload/drive/v3/files?uploadType=multipart`,
body: form,
headers: {
...form.getHeaders(),
},
queryParams: {
supportsAllDrives: String(context.propsValue.include_team_drives || false),
const response = await drive.files.create({
requestBody: {
name: context.propsValue.fileName,
mimeType,
...(context.propsValue.parentFolder
? { parents: [context.propsValue.parentFolder] }
: {}),
},
authentication: {
type: AuthenticationType.BEARER_TOKEN,
token: await getAccessToken(context.auth),
media: {
mimeType,
body: context.propsValue.text,
},
supportsAllDrives: context.propsValue.include_team_drives ?? false,
fields: 'id, name, mimeType, kind',
});

console.debug('File creation response', result);
return result.body;
return response.data;
},
});
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import { createAction, Property } from '@activepieces/pieces-framework';
import {
httpClient,
HttpMethod,
AuthenticationType,
} from '@activepieces/pieces-common';
import FormData from 'form-data';
import { googleDriveAuth, getAccessToken } from '../auth';
import { Readable } from 'stream';
import mime from 'mime-types';
import { drive as googleDrive } from '@googleapis/drive';
import { googleDriveAuth, createGoogleClient } from '../auth';
import { common } from '../common';
import { uploadGdriveFileActionOutputSchema } from '../output-schemas';

Expand Down Expand Up @@ -34,43 +30,26 @@ export const googleDriveUploadFile = createAction({
outputSchema: uploadGdriveFileActionOutputSchema,
async run(context) {
const fileData = context.propsValue.file;
const mimeType = mime.lookup(fileData.extension ? fileData.extension : '');
const mimeType = mime.lookup(fileData.extension ?? '') || 'application/octet-stream';

const meta = {
mimeType: mimeType,
name: context.propsValue.fileName,
...(context.propsValue.parentFolder
? { parents: [context.propsValue.parentFolder] }
: {}),
};
const authClient = await createGoogleClient(context.auth);
const drive = googleDrive({ version: 'v3', auth: authClient });

const metaBuffer = Buffer.from(JSON.stringify(meta), 'utf-8');
const fileBuffer = Buffer.from(fileData.base64, 'base64');

const form = new FormData();
form.append('Metadata', metaBuffer, { contentType: 'application/json' });
form.append('Media', fileBuffer);

const result = await httpClient.sendRequest({
method: HttpMethod.POST,
url: `https://www.googleapis.com/upload/drive/v3/files`,
queryParams: {
uploadType: 'multipart',
supportsAllDrives: String(
context.propsValue.include_team_drives || false
),
},
body: form,
headers: {
...form.getHeaders(),
const response = await drive.files.create({
requestBody: {
name: context.propsValue.fileName,
...(context.propsValue.parentFolder
? { parents: [context.propsValue.parentFolder] }
: {}),
},
authentication: {
type: AuthenticationType.BEARER_TOKEN,
token: await getAccessToken(context.auth),
media: {
mimeType,
body: Readable.from(Buffer.from(fileData.base64, 'base64')),
},
supportsAllDrives: context.propsValue.include_team_drives ?? false,
fields: 'id, name, mimeType, kind',
});

console.debug('File upload response', result);
return result.body;
return response.data;
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,7 @@ const TestWebhookFunctionalityForm = (
<FormItem>
<DictionaryInput
values={field.value}
onChange={(record) =>
field.onChange({ target: { value: record } })
}
onChange={field.onChange}
disabled={false}
/>
</FormItem>
Expand All @@ -252,9 +250,7 @@ const TestWebhookFunctionalityForm = (
<FormItem>
<DictionaryInput
values={field.value}
onChange={(record) =>
field.onChange({ target: { value: record } })
}
onChange={field.onChange}
disabled={false}
/>
</FormItem>
Expand Down
Loading