feat: add new photo in album flickr trigger

This commit is contained in:
Ali BARIN
2022-04-15 00:47:47 +02:00
committed by Ömer Faruk Aydın
parent 651cceec14
commit 1e00c7d14e
10 changed files with 204 additions and 5 deletions

View File

@@ -24,7 +24,7 @@ export default class FavoritePhoto {
}
async run(startTime: Date) {
const { photos } = (await this.client.favorites.getList({ per_page: 1, })).body;
const { photos } = (await this.client.favorites.getList()).body;
const favPhotos = [...photos.photo];
const newFavPhotos = [];
@@ -45,7 +45,7 @@ export default class FavoritePhoto {
if (isLastItem && page < photos.pages) {
page = page + 1;
const { photos } = (await this.client.favorites.getList({ page, per_page: 1, })).body;
const { photos } = (await this.client.favorites.getList({ page, })).body;
favPhotos.push(...photos.photo);
}
}

View File

@@ -0,0 +1,81 @@
import { DateTime } from 'luxon';
import FlickrApi from 'flickr-sdk';
import { IJSONObject } from '@automatisch/types';
export default class NewPhotoInAlbum {
client?: typeof FlickrApi;
connectionData?: IJSONObject;
albumId?: string;
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(',');
constructor(connectionData: IJSONObject, parameters: IJSONObject) {
if (
connectionData.consumerKey &&
connectionData.consumerSecret &&
connectionData.accessToken &&
connectionData.accessSecret
) {
this.client = new FlickrApi(
FlickrApi.OAuth.createPlugin(
connectionData.consumerKey,
connectionData.consumerSecret,
connectionData.accessToken,
connectionData.accessSecret
)
);
this.connectionData = connectionData;
}
if (parameters?.album) {
this.albumId = parameters.album as string;
}
}
async getAlbumPhotos(options: { perPage?: number, page?: number } = {}) {
const { perPage, page } = options;
const payload = {
page,
per_page: perPage,
photoset_id: this.albumId,
user_id: this.connectionData.userId,
extras: this.extraFields,
};
const { photoset } = (await this.client.photosets.getPhotos(payload)).body;
return photoset;
}
async run() {
// TODO: implement pagination on undated entries
const { photo } = await this.getAlbumPhotos({ page: 1 });
return photo;
}
async testRun() {
const { photo } = await this.getAlbumPhotos({ perPage: 1 });
return photo;
}
}