feat(flickr): add new photos in an album trigger
This commit is contained in:
@@ -0,0 +1,47 @@
|
|||||||
|
import defineTrigger from '../../../../helpers/define-trigger';
|
||||||
|
import newPhotosInAlbum from './new-photos-in-album';
|
||||||
|
|
||||||
|
export default defineTrigger({
|
||||||
|
name: 'New photos in album',
|
||||||
|
pollInterval: 15,
|
||||||
|
key: 'newPhotosInAlbum',
|
||||||
|
description: 'Triggers when you add a new photo in an album.',
|
||||||
|
dedupeStrategy: 'greatest',
|
||||||
|
substeps: [
|
||||||
|
{
|
||||||
|
key: 'chooseConnection',
|
||||||
|
name: 'Choose connection'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'chooseTrigger',
|
||||||
|
name: 'Set up a trigger',
|
||||||
|
arguments: [
|
||||||
|
{
|
||||||
|
label: 'Album',
|
||||||
|
key: 'album',
|
||||||
|
type: 'dropdown',
|
||||||
|
required: true,
|
||||||
|
variables: false,
|
||||||
|
source: {
|
||||||
|
type: 'query',
|
||||||
|
name: 'getData',
|
||||||
|
arguments: [
|
||||||
|
{
|
||||||
|
name: 'key',
|
||||||
|
value: 'listAlbums'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'testStep',
|
||||||
|
name: 'Test trigger'
|
||||||
|
}
|
||||||
|
],
|
||||||
|
|
||||||
|
async run($) {
|
||||||
|
await newPhotosInAlbum($);
|
||||||
|
},
|
||||||
|
});
|
@@ -0,0 +1,59 @@
|
|||||||
|
import { IGlobalVariable } from '@automatisch/types';
|
||||||
|
|
||||||
|
const extraFields = [
|
||||||
|
'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_m',
|
||||||
|
'url_o',
|
||||||
|
].join(',');
|
||||||
|
|
||||||
|
const newPhotosInAlbum = async ($: IGlobalVariable) => {
|
||||||
|
let page = 1;
|
||||||
|
let pages = 1;
|
||||||
|
|
||||||
|
do {
|
||||||
|
const params = {
|
||||||
|
page,
|
||||||
|
per_page: 11,
|
||||||
|
user_id: $.auth.data.userId,
|
||||||
|
extras: extraFields,
|
||||||
|
photoset_id: $.step.parameters.album as string,
|
||||||
|
method: 'flickr.photosets.getPhotos',
|
||||||
|
format: 'json',
|
||||||
|
nojsoncallback: 1,
|
||||||
|
};
|
||||||
|
const response = await $.http.get('/rest', { params });
|
||||||
|
const photoset = response.data.photoset;
|
||||||
|
page = photoset.page + 1;
|
||||||
|
pages = photoset.pages;
|
||||||
|
|
||||||
|
for (const photo of photoset.photo) {
|
||||||
|
if ($.flow.isAlreadyProcessed(photo.id) && !$.execution.testRun)
|
||||||
|
return;
|
||||||
|
|
||||||
|
$.pushTriggerItem({
|
||||||
|
raw: photo,
|
||||||
|
meta: {
|
||||||
|
internalId: photo.id as string
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
} while (page <= pages && !$.execution.testRun);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default newPhotosInAlbum;
|
Reference in New Issue
Block a user