auths
objectreturn
or this.key = 'value'
, pass input data to your code viaparams
, and maintain state across executions with$checkpoint.async
(event, steps, auths) => {
}
if(steps.trigger.event.url.indexOf('favicon.ico') > 0) $end("favicon");
auths
objectreturn
or this.key = 'value'
, pass input data to your code viaparams
, and maintain state across executions with$checkpoint.async
(event, steps, auths) => {
}
if($checkpoint && $checkpoint.favoriteAlbum) return $checkpoint.favoriteAlbum;
let result = await require("@pipedreamhq/platform").axios(this, {
url: 'https://photoslibrary.googleapis.com/v1/albums',
headers: {
Authorization: `Bearer ${auths.google_photos.oauth_access_token}`,
},
});
let favorite = result.albums.find(a => {
return a.title === 'Favorites';
});
if(!$checkpoint) $checkpoint = { };
$checkpoint.favoriteAlbum = favorite.id;
return favorite.id;
auths
objectreturn
or this.key = 'value'
, pass input data to your code viaparams
, and maintain state across executions with$checkpoint.async
(event, steps, auths) => {
}
/*
Fetch photos once every six hours
changed to 1 on 5/19/2022
*/
let cacheDuration = 1 * 60 * 60 * 1000;
let now = Date.now();
if($checkpoint && $checkpoint.photoCacheTime && (now - $checkpoint.photoCacheTime < cacheDuration) && $checkpoint.photoCache) return $checkpoint.photoCache;
console.log('not cached');
let result = await require("@pipedreamhq/platform").axios(this, {
url: 'https://photoslibrary.googleapis.com/v1/mediaItems:search',
headers: {
Authorization: `Bearer ${auths.google_photos.oauth_access_token}`,
},
method:'post',
data: {
albumId:steps.get_favorites_album.$return_value,
pageSize:100
}
});
// cache baseUrl
let photos = result.mediaItems.map(m => m.baseUrl);
$checkpoint.photoCacheTime = now;
$checkpoint.photoCache = photos;
console.log('stored cache time of ', $checkpoint.photoCacheTime);
return photos;
auths
objectreturn
or this.key = 'value'
, pass input data to your code viaparams
, and maintain state across executions with$checkpoint.async
(event, steps) => {
}
// goes from min to max-1
const getRandomInt = function(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min) + min); //The maximum is exclusive and the minimum is inclusive
}
return steps.get_photos.$return_value[getRandomInt(0, steps.get_photos.$return_value.length)];
auths
objectreturn
or this.key = 'value'
, pass input data to your code viaparams
, and maintain state across executions with$checkpoint.async
(event, steps, auths) => {
}
const result = await require("@pipedreamhq/platform").axios(this, {
url: steps.select_photo.$return_value,
headers: {
Authorization: `Bearer ${auths.google_photos.oauth_access_token}`,
},
responseType:'arraybuffer'
});
console.log('got here ok');
await $respond({
status:200,
headers: {
'Content-Type':'image/jpeg'
},
body:result
})