feat(flickr): add new fav photos trigger

This commit is contained in:
Ali BARIN
2022-10-24 23:48:05 +02:00
parent 524c3c22dc
commit 6b40d206f8
2 changed files with 88 additions and 0 deletions

View File

@@ -0,0 +1,24 @@
import defineTrigger from '../../../../helpers/define-trigger';
import newFavoritePhotos from './new-favorite-photos';
export default defineTrigger({
name: 'New favorite photos',
pollInterval: 15,
key: 'newFavoritePhotos',
description: 'Triggers when you favorite a photo.',
dedupeStrategy: 'unique',
substeps: [
{
key: 'chooseConnection',
name: 'Choose connection'
},
{
key: 'testStep',
name: 'Test trigger'
}
],
async run($) {
await newFavoritePhotos($);
},
});

View File

@@ -0,0 +1,64 @@
import { IGlobalVariable } from '@automatisch/types';
const extraFields = [
'description',
'license',
'date_upload',
'date_taken',
'owner_name',
'icon_server',
'original_format',
'last_update',
'geo',
'tags',
'machine_tags',
'o_dims',
'views',
'media',
'path_alias',
'url_sq',
'url_t',
'url_s',
'url_q',
'url_m',
'url_n',
'url_z',
'url_c',
'url_l',
'url_o',
].join(',');
const newPhotos = async ($: IGlobalVariable) => {
let page = 1;
let pages = 1;
do {
const params = {
page,
per_page: 500,
user_id: $.auth.data.userId,
extras: extraFields,
method: 'flickr.favorites.getList',
format: 'json',
nojsoncallback: 1,
};
const response = await $.http.get('/rest', { params });
const photos = response.data.photos;
page = photos.page + 1;
pages = photos.pages;
for (const photo of photos.photo) {
if ($.flow.isAlreadyProcessed(photo.date_faved) && !$.execution.testRun)
return;
$.pushTriggerItem({
raw: photo,
meta: {
internalId: photo.date_faved as string
}
})
}
} while (page <= pages && !$.execution.testRun);
};
export default newPhotos;