Merge pull request #637 from automatisch/flickr/new-photos
feat(flickr): add new photos trigger
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
import defineTrigger from '../../../../helpers/define-trigger';
|
||||
import newPhotos from './new-photos';
|
||||
|
||||
export default defineTrigger({
|
||||
name: 'New photo',
|
||||
pollInterval: 15,
|
||||
key: 'newPhoto',
|
||||
description: 'Triggers when you add a new photo.',
|
||||
dedupeStrategy: 'unique',
|
||||
substeps: [
|
||||
{
|
||||
key: 'chooseConnection',
|
||||
name: 'Choose connection'
|
||||
},
|
||||
{
|
||||
key: 'testStep',
|
||||
name: 'Test trigger'
|
||||
}
|
||||
],
|
||||
|
||||
async run($) {
|
||||
await newPhotos($);
|
||||
},
|
||||
});
|
@@ -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.photos.search',
|
||||
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.id) && !$.execution.testRun)
|
||||
return;
|
||||
|
||||
$.pushTriggerItem({
|
||||
raw: photo,
|
||||
meta: {
|
||||
internalId: photo.id as string
|
||||
}
|
||||
})
|
||||
}
|
||||
} while (page <= pages && !$.execution.testRun);
|
||||
};
|
||||
|
||||
export default newPhotos;
|
@@ -47,7 +47,7 @@ const newWatchers = async ($: IGlobalVariable) => {
|
||||
$.pushTriggerItem(dataItem);
|
||||
}
|
||||
}
|
||||
} while (pathname && !$.execution.testRun === false);
|
||||
} while (pathname && !$.execution.testRun);
|
||||
};
|
||||
|
||||
export default newWatchers;
|
||||
|
Reference in New Issue
Block a user