feat(flickr): add new albums trigger

This commit is contained in:
Ali BARIN
2022-10-26 00:54:29 +02:00
parent fbc867b4fa
commit f8c7e601a5
2 changed files with 82 additions and 0 deletions

View File

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

View File

@@ -0,0 +1,58 @@
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 newAlbums = async ($: IGlobalVariable) => {
let page = 1;
let pages = 1;
do {
const params = {
page,
per_page: 500,
user_id: $.auth.data.userId,
extras: extraFields,
method: 'flickr.photosets.getList',
format: 'json',
nojsoncallback: 1,
};
const response = await $.http.get('/rest', { params });
const photosets = response.data.photosets;
page = photosets.page + 1;
pages = photosets.pages;
for (const photoset of photosets.photoset) {
if ($.flow.isAlreadyProcessed(photoset.id) && !$.execution.testRun)
return;
$.pushTriggerItem({
raw: photoset,
meta: {
internalId: photoset.id as string
}
})
}
} while (page <= pages && !$.execution.testRun);
};
export default newAlbums;