feat(google-drive): add new files trigger

This commit is contained in:
Rıdvan Akca
2023-03-22 22:16:44 +03:00
parent 8e1087b818
commit d16d709b72
14 changed files with 263 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
import newFiles from './new-files';
export default [newFiles];

View File

@@ -0,0 +1,13 @@
import defineTrigger from '../../../../helpers/define-trigger';
import newFiles from './new-files';
export default defineTrigger({
name: 'New Files',
key: 'newFiles',
pollInterval: 15,
description: 'Triggers when any new file is added (inside of any folder).',
async run($) {
await newFiles($);
},
});

View File

@@ -0,0 +1,29 @@
import { IGlobalVariable } from '@automatisch/types';
const newFiles = async ($: IGlobalVariable) => {
const params = {
pageToken: undefined as unknown as string,
orderBy: 'createdTime desc',
q: `mimeType!='application/vnd.google-apps.folder'`,
fields: '*',
pageSize: 1000,
};
do {
const { data } = await $.http.get('/v3/files', { params });
params.pageToken = data.nextPageToken;
if (data.files?.length) {
for (const file of data.files) {
$.pushTriggerItem({
raw: file,
meta: {
internalId: file.id,
},
});
}
}
} while (params.pageToken);
};
export default newFiles;