Merge pull request #1039 from automatisch/list-shared-drives-for-new-files

feat(google-drive): list shared drives for new files trigger
This commit is contained in:
Ali BARIN
2023-04-06 16:35:59 +02:00
committed by GitHub
4 changed files with 59 additions and 1 deletions

View File

@@ -1,3 +1,4 @@
import listFolders from './list-folders';
import listDrives from './list-drives';
export default [listFolders];
export default [listFolders, listDrives];

View File

@@ -0,0 +1,35 @@
import { IGlobalVariable, IJSONObject } from '@automatisch/types';
export default {
name: 'List drives',
key: 'listDrives',
async run($: IGlobalVariable) {
const drives: {
data: IJSONObject[];
} = {
data: [{ value: null, name: 'My Google Drive' }],
};
const params = {
pageSize: 100,
pageToken: undefined as unknown as string,
};
do {
const { data } = await $.http.get(`/v3/drives`, { params });
params.pageToken = data.nextPageToken;
if (data.drives) {
for (const drive of data.drives) {
drives.data.push({
value: drive.id,
name: drive.name,
});
}
}
} while (params.pageToken);
return drives;
},
};

View File

@@ -6,6 +6,27 @@ export default defineTrigger({
key: 'newFiles',
pollInterval: 15,
description: 'Triggers when any new file is added (inside of any folder).',
arguments: [
{
label: 'Drive',
key: 'driveId',
type: 'dropdown' as const,
required: false,
description:
'The drive to use. If nothing is selected, then your personal Google Drive will be used.',
variables: false,
source: {
type: 'query',
name: 'getDynamicData',
arguments: [
{
name: 'key',
value: 'listDrives',
},
],
},
},
],
async run($) {
await newFiles($);

View File

@@ -7,6 +7,7 @@ const newFiles = async ($: IGlobalVariable) => {
q: `mimeType!='application/vnd.google-apps.folder'`,
fields: '*',
pageSize: 1000,
driveId: $.step.parameters.driveId,
};
do {