Skip to content

Commit

Permalink
2.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
eouia committed Mar 31, 2020
1 parent 9ad639a commit 77f6ee8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
19 changes: 17 additions & 2 deletions GPhotos.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ const {OAuth2Client} = require('google-auth-library')
const Axios = require('axios')
const moment = require('moment')

function sleep(ms=1000) {
return new Promise((resolve) => {
setTimeout(resolve, ms)
})
}
function Auth(config, debug=false) {
const log = (debug) ? (...args)=>{console.log("[GPHOTOS:AUTH]", ...args)} : ()=>{}
if (config === undefined) config = {}
Expand Down Expand Up @@ -202,6 +207,7 @@ class GPhotos {
var list = []
var found = 0
const getAlbum = async (pageSize=50, pageToken="") => {
this.log("Getting Album info chunks.")
var params = {
pageSize: pageSize,
pageToken: pageToken,
Expand All @@ -214,7 +220,11 @@ class GPhotos {
list = list.concat(body[type])
}
if (body.nextPageToken) {
getAlbum(pageSize, body.nextPageToken)
const generous = async () => {
await sleep(500)
getAlbum(pageSize, body.nextPageToken)
}
generous()
} else {
this.albums[type] = list
resolve(list)
Expand All @@ -235,6 +245,7 @@ class GPhotos {
var token = client.credentials.access_token
var list = []
const getImage = async (pageSize=50, pageToken="") => {
this.log("Indexing photos now.")
try {
var data = {
"albumId": albumId,
Expand All @@ -257,7 +268,11 @@ class GPhotos {
resolve(list) // full with maxNum
} else {
if (response.data.nextPageToken) {
getImage(50, response.data.nextPageToken)
const generous = async () => {
await sleep(500)
getImage(50, response.data.nextPageToken)
}
generous()
} else {
resolve(list) // all found but lesser than maxNum
}
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ Display your photos from album of Google Photos on MagicMirror
![](https://raw.githubusercontent.com/eouia/MMM-GooglePhotos/master/sc2.png)

## New Updates
**`[2.0.1] - 2020/03/31`**
- Fixed: 503 error from too often/many requests. (Thanks to @olafnorge)

**`[2.0.0] - 2020/03/23`**
- Notice: Whole new build from scratch. new installation and configuration is needed.
- Removed: deprecated dependency `request`. Instead, using `Axios` and `https`
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "MMM-GooglePhotos",
"version": "2.0.0",
"version": "2.0.1",
"description": "MagicMirror module for Google Photos",
"license": "MIT",
"author": "eouia0819@gmail.com",
Expand Down

0 comments on commit 77f6ee8

Please sign in to comment.