feat: add new photo in album flickr trigger
This commit is contained in:

committed by
Ömer Faruk Aydın

parent
651cceec14
commit
1e00c7d14e
10
packages/backend/src/apps/flickr/data.ts
Normal file
10
packages/backend/src/apps/flickr/data.ts
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
import { IJSONObject } from '@automatisch/types';
|
||||||
|
import ListAlbums from './data/list-albums';
|
||||||
|
|
||||||
|
export default class Data {
|
||||||
|
listAlbums: ListAlbums;
|
||||||
|
|
||||||
|
constructor(connectionData: IJSONObject) {
|
||||||
|
this.listAlbums = new ListAlbums(connectionData);
|
||||||
|
}
|
||||||
|
}
|
39
packages/backend/src/apps/flickr/data/list-albums.ts
Normal file
39
packages/backend/src/apps/flickr/data/list-albums.ts
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
import FlickrApi from 'flickr-sdk';
|
||||||
|
import type { IJSONObject } from '@automatisch/types';
|
||||||
|
|
||||||
|
export default class ListAlbums {
|
||||||
|
client?: typeof FlickrApi;
|
||||||
|
|
||||||
|
constructor(connectionData: 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
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async run() {
|
||||||
|
const { photosets } = (await this.client.photosets.getList()).body;
|
||||||
|
const allPhotosets = [...photosets.photoset];
|
||||||
|
|
||||||
|
for (let page = photosets.page + 1; page <= photosets.pages; page++) {
|
||||||
|
const { photosets } = (await this.client.photosets.getList({ page, })).body;
|
||||||
|
allPhotosets.push(...photosets.photoset);
|
||||||
|
}
|
||||||
|
|
||||||
|
return allPhotosets.map((photoset) => ({
|
||||||
|
value: photoset.id,
|
||||||
|
name: photoset.title._content,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}
|
@@ -6,10 +6,12 @@ import {
|
|||||||
} from '@automatisch/types';
|
} from '@automatisch/types';
|
||||||
import Authentication from './authentication';
|
import Authentication from './authentication';
|
||||||
import Triggers from './triggers';
|
import Triggers from './triggers';
|
||||||
|
import Data from './data';
|
||||||
|
|
||||||
export default class Flickr implements IService {
|
export default class Flickr implements IService {
|
||||||
authenticationClient: IAuthentication;
|
authenticationClient: IAuthentication;
|
||||||
triggers: Triggers;
|
triggers: Triggers;
|
||||||
|
data: Data;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
appData: IApp,
|
appData: IApp,
|
||||||
@@ -17,6 +19,7 @@ export default class Flickr implements IService {
|
|||||||
parameters: IJSONObject
|
parameters: IJSONObject
|
||||||
) {
|
) {
|
||||||
this.authenticationClient = new Authentication(appData, connectionData);
|
this.authenticationClient = new Authentication(appData, connectionData);
|
||||||
|
this.data = new Data(connectionData);
|
||||||
this.triggers = new Triggers(connectionData, parameters);
|
this.triggers = new Triggers(connectionData, parameters);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -218,9 +218,9 @@
|
|||||||
"triggers": [
|
"triggers": [
|
||||||
{
|
{
|
||||||
"name": "New favorite photo",
|
"name": "New favorite photo",
|
||||||
"key": "favoritePhoto",
|
"key": "newFavoritePhoto",
|
||||||
"interval": "15m",
|
"interval": "15m",
|
||||||
"description": "Will be triggered when you favorite a photo.",
|
"description": "Triggers when you favorite a photo.",
|
||||||
"substeps": [
|
"substeps": [
|
||||||
{
|
{
|
||||||
"key": "chooseAccount",
|
"key": "chooseAccount",
|
||||||
@@ -231,6 +231,45 @@
|
|||||||
"name": "Test trigger"
|
"name": "Test trigger"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "New photo in album",
|
||||||
|
"key": "newPhotoInAlbum",
|
||||||
|
"interval": "15m",
|
||||||
|
"description": "Triggers when you add a new photo in an album.",
|
||||||
|
"substeps": [
|
||||||
|
{
|
||||||
|
"key": "chooseAccount",
|
||||||
|
"name": "Choose account"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"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"
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@@ -1,10 +1,13 @@
|
|||||||
import { IJSONObject } from '@automatisch/types';
|
import { IJSONObject } from '@automatisch/types';
|
||||||
import FavoritePhoto from './triggers/favorite-photo';
|
import FavoritePhoto from './triggers/favorite-photo';
|
||||||
|
import NewPhotoInAlbum from './triggers/new-photo-in-album';
|
||||||
|
|
||||||
export default class Triggers {
|
export default class Triggers {
|
||||||
favoritePhoto: FavoritePhoto;
|
favoritePhoto: FavoritePhoto;
|
||||||
|
newPhotoInAlbum: NewPhotoInAlbum;
|
||||||
|
|
||||||
constructor(connectionData: IJSONObject, parameters: IJSONObject) {
|
constructor(connectionData: IJSONObject, parameters: IJSONObject) {
|
||||||
this.favoritePhoto = new FavoritePhoto(connectionData);
|
this.favoritePhoto = new FavoritePhoto(connectionData);
|
||||||
|
this.newPhotoInAlbum = new NewPhotoInAlbum(connectionData, parameters);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -24,7 +24,7 @@ export default class FavoritePhoto {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async run(startTime: Date) {
|
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 favPhotos = [...photos.photo];
|
||||||
const newFavPhotos = [];
|
const newFavPhotos = [];
|
||||||
|
|
||||||
@@ -45,7 +45,7 @@ export default class FavoritePhoto {
|
|||||||
|
|
||||||
if (isLastItem && page < photos.pages) {
|
if (isLastItem && page < photos.pages) {
|
||||||
page = page + 1;
|
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);
|
favPhotos.push(...photos.photo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
@@ -367,7 +367,21 @@ type TriggerSubstepArgument {
|
|||||||
label: String
|
label: String
|
||||||
key: String
|
key: String
|
||||||
type: String
|
type: String
|
||||||
|
description: String
|
||||||
required: Boolean
|
required: Boolean
|
||||||
|
variables: Boolean
|
||||||
|
source: TriggerSubstepArgumentSource
|
||||||
|
}
|
||||||
|
|
||||||
|
type TriggerSubstepArgumentSource {
|
||||||
|
type: String
|
||||||
|
name: String
|
||||||
|
arguments: [TriggerSubstepArgumentSourceArgument]
|
||||||
|
}
|
||||||
|
|
||||||
|
type TriggerSubstepArgumentSourceArgument {
|
||||||
|
name: String
|
||||||
|
value: String
|
||||||
}
|
}
|
||||||
|
|
||||||
type User {
|
type User {
|
||||||
|
@@ -13,7 +13,7 @@ class Step extends Base {
|
|||||||
connectionId?: string;
|
connectionId?: string;
|
||||||
status = 'incomplete';
|
status = 'incomplete';
|
||||||
position!: number;
|
position!: number;
|
||||||
parameters: Record<string, unknown> = {};
|
parameters: Record<string, unknown>;
|
||||||
connection?: Connection;
|
connection?: Connection;
|
||||||
flow: Flow;
|
flow: Flow;
|
||||||
executionSteps?: [ExecutionStep];
|
executionSteps?: [ExecutionStep];
|
||||||
|
@@ -61,6 +61,16 @@ export const GET_APPS = gql`
|
|||||||
key
|
key
|
||||||
type
|
type
|
||||||
required
|
required
|
||||||
|
description
|
||||||
|
variables
|
||||||
|
source {
|
||||||
|
type
|
||||||
|
name
|
||||||
|
arguments {
|
||||||
|
name
|
||||||
|
value
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user