Skip to content

Commit

Permalink
fix the issue about photos shared from others
Browse files Browse the repository at this point in the history
  • Loading branch information
eouia committed Jul 27, 2018
1 parent 543c3a1 commit 4ae8c7f
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
6 changes: 3 additions & 3 deletions auth_and_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ auth.on('ready', (client) => {
console.log("auth_and_test started.")
var token = client.credentials.access_token
function getAlbum(client, pageSize=50, pageToken="") {
var url = 'https://photoslibrary.googleapis.com/v1/albums'
var url = 'https://photoslibrary.googleapis.com/v1/sharedAlbums'
url = url + "?pageSize=" + pageSize + "&pageToken=" + pageToken
request.get(
url,
Expand All @@ -34,8 +34,8 @@ auth.on('ready', (client) => {
process.exit(1);
}
var found = 0
for (var i in body.albums) {
var album = body.albums[i]
for (var i in body.sharedAlbums) {
var album = body.sharedAlbums[i]
console.log (album.title, " : ", album.id)
found++;
}
Expand Down
34 changes: 34 additions & 0 deletions node_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ module.exports = NodeHelper.create({
},

initializeAfterLoading: function (config) {
if (config.scanInterval > 1000 * 60 * 60) {
config.scanInterval = 1000 * 60 * 55 // By using baseUrl from :search directly, there needs to maintain scanInterval under 1hour because risk of expiration of baseUrl.
}
this.config = config
console.log(this.name + " initialized after loading.")
this.authConfig = {
Expand Down Expand Up @@ -85,10 +88,12 @@ module.exports = NodeHelper.create({
found = mediaItems.length
}
for (var i in mediaItems) {
//console.log("scanned:", mediaItems[i])
if ("photo" in mediaItems[i].mediaMetadata) {
var item = {
"id": mediaItems[i].id,
"creationTime": Date.parse(mediaItems[i].mediaMetadata.creationTime),
"baseUrl": mediaItems[i].baseUrl
}
self.tempItems.push(item)
}
Expand Down Expand Up @@ -136,6 +141,9 @@ module.exports = NodeHelper.create({
}
},

/* Changed for shared Image.
* Very weird API. I don't know why "mediaItems:search" can access shared photos but "mediaItems/[photoID]" cannot.
* anyway, here will be trick.
getPhoto: function() {
var photoId = this.items[this.index].id
const options = {
Expand All @@ -155,6 +163,7 @@ module.exports = NodeHelper.create({
if (this.index >= this.items.length) {
this.index = 0
}
console.log("body", body)
var payload = {
"id":body.id,
"url":body.baseUrl + "=w" + this.config.originalHeightPx + "-h" + this.config.originalHeightPx,
Expand All @@ -164,6 +173,31 @@ module.exports = NodeHelper.create({
this.sendSocketNotification("NEW_IMAGE", payload)
})
},
*/
getPhoto: function() {
if (this.items.length <= 0) {
console.log("There is no scanned photo currently.")
return
}
var photo = null
if (typeof this.items[this.index] !== "undefined") {
photo = this.items[this.index]
} else {
photo = this.items[0]
this.index = 0
}
//console.log("photo", this.index, this.items.id)
this.index++

var payload = {
"id":photo.id,
"url":photo.baseUrl + "=w" + this.config.originalHeightPx + "-h" + this.config.originalHeightPx,
"time": Date.parse(photo.creationTime),
}
this.sendSocketNotification("NEW_IMAGE", payload)
},



broadcast: function() {
var auth = new Auth(this.authConfig)
Expand Down

0 comments on commit 4ae8c7f

Please sign in to comment.