Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2.1.5 #186

Merged
merged 10 commits into from
Mar 8, 2024
Merged

2.1.5 #186

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"node": true
},
"globals": {
"config": true,
"Log": true,
"MM": true,
"Module": true,
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ node_modules/
cache/*
!cache/keep.txt
.idea
.DS_Store
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"files.exclude": {
"**/node_modules": true
}
}
23 changes: 18 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
# MMM-GooglePhotos Change Log

**`[2.1.5] - 2024/03/08`**
- Added: Allow regular expression ([RE2 engine](https://github.com/google/re2)) in album names ([#179](https://github.com/hermanho/MMM-GooglePhotos/issues/179))

**`[2.1.4] - 2024/01/28`**
- Changed: Update README.md and INSTALL.md
- Changed: Enrich error message display

**`[2.1.2] - 2023/07/17`**

- Changed: Update dependency packages to fix vulnerability [SNYK-JS-AXIOS-6032459](https://snyk.io/vuln/SNYK-JS-AXIOS-6032459)
- Changed: Move installation guideline to [INSTALL.md](INSTALL.md)
- Changed: Use shuffle algorithm to do random sorting.
Expand All @@ -10,25 +18,31 @@
- Fixed: #170 fix photo showing when GPHOTO_PREVIOUS is triggered

**`[2.1.1] - 2023/07/17`**

- Changed: Update dependency packages to fix vulnerability.

**`[2.1.0] - 2023/01/19`**

- Changed: Update dependency packages to fix vulnerability.
- Fixed: Change mkdirp to promise syntax (#156)
- Fixed: Change mkdirp to promise syntax ([#156](https://github.com/hermanho/MMM-GooglePhotos/issues/156))

**`[2.0.3] - 2022/10/18`**

- Changed: Update dependency packages to fix vulnerability.

**`[2.0.2] - 2020/04/01`**

- Added: `autoInfoPosition` - For preventing LCD burning, Photo info can be relocated by condition.
- `true` : automatically change position to each corner per 15 minutes.
- `false` : not using.
- callbackfunction (album, photo) : User can make his own position.
- `true` : automatically change position to each corner per 15 minutes.
- `false` : not using.
- callbackfunction (album, photo) : User can make his own position.

**`[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`
- Changed: More stable displaying photos
Expand All @@ -38,4 +52,3 @@
- Added: `GPHOTO_NEXT`, `GPHOTO_PREVIOUS` notifications are supported.
- Added: `GPHOTO_UPLOAD` notification is supported. Now `MMM-Selfieshot` and `MMM-TelegramBot` can upload pictures with this module.
- Removed: `mode`, `scanInterval`, `opacity` is removed because no more necessary.

16 changes: 10 additions & 6 deletions GPhotos.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,17 @@ class Auth extends EventEmitter {
this.#config = config;
this.#debug = debug;
this.init().then(
() => {},
() => { },
(err) => this.emit("error", err),
);
}

async init() {
const log = this.#debug
? (...args) => {
console.log("[GPHOTOS:AUTH]", ...args);
}
: () => {};
console.log("[GPHOTOS:AUTH]", ...args);
}
: () => { };
if (this.#config === undefined) config = {};
if (this.#config.keyFilePath === undefined) {
throw new ConfigFileError('Missing "keyFilePath" from config (This should be where your Credential file is)');
Expand Down Expand Up @@ -187,6 +187,10 @@ class GPhotos {
return albums;
}

/**
* @param {string} type "albums" or "sharedAlbums"
* @returns {Promise<GooglePhotos.Album[]>}
*/
async getAlbumType(type = "albums") {
if (type !== "albums" && type !== "sharedAlbums") throw new Error("Invalid parameter for .getAlbumType()", type);
const client = await this.onAuthReady();
Expand Down Expand Up @@ -234,8 +238,8 @@ class GPhotos {
* @param {string} pageToken
* @returns {Promise<MediaItem[]>} MediaItem
*/
const getImage = async (pageSize = 50, pageToken = "") => {
this.log("Indexing photos now. total: ", list.length);
const getImage = async (pageSize = 100, pageToken = "") => {
// this.log("Indexing photos now. total: ", list.length);
try {
let data = {
albumId: albumId,
Expand Down
37 changes: 25 additions & 12 deletions MMM-GooglePhotos.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,19 @@ Module.register("MMM-GooglePhotos", {
this.firstScan = true;
if (this.config.updateInterval < 1000 * 10) this.config.updateInterval = 1000 * 10;
this.config.condition = Object.assign({}, this.defaults.condition, this.config.condition);
this.sendSocketNotification("INIT", this.config);

const config = { ...this.config };
for (let i = 0; i < config.albums.length; i++) {
const album = config.albums[i];
if (album instanceof RegExp) {
config.albums[i] = {
source: album.source,
flags: album.flags,
};
}
}

this.sendSocketNotification("INIT", config);
this.dynamicPosition = 0;
},

Expand All @@ -53,9 +65,12 @@ Module.register("MMM-GooglePhotos", {
if (noti === "INITIALIZED") {
this.albums = payload;
//set up timer once initialized, more robust against faults
this.updateTimer = setInterval(() => {
this.updatePhotos();
}, this.config.updateInterval);
if (!this.updateTimer || this.updateTimer === null) {
Log.info("Start timer for updating photos.");
this.updateTimer = setInterval(() => {
this.updatePhotos();
}, this.config.updateInterval);
}
}
if (noti === "MORE_PICS") {
if (payload && Array.isArray(payload) && payload.length > 0) this.needMorePicsFlag = false;
Expand Down Expand Up @@ -90,6 +105,7 @@ Module.register("MMM-GooglePhotos", {
},

updatePhotos: function (dir = 0) {
Log.debug("Updating photos..");
this.firstScan = false;

if (this.scanned.length === 0) {
Expand Down Expand Up @@ -131,15 +147,12 @@ Module.register("MMM-GooglePhotos", {
let current = document.getElementById("GPHOTO_CURRENT");
current.textContent = "";
//current.classList.remove("animated")
let dom = document.getElementById("GPHOTO");
// let dom = document.getElementById("GPHOTO");
back.style.backgroundImage = `url(${url})`;
current.style.backgroundImage = `url(${url})`;
current.classList.add("animated");
let info = document.getElementById("GPHOTO_INFO");
let album = this.albums.find((a) => {
if (a.id === target._albumId) return true;
return false;
});
const info = document.getElementById("GPHOTO_INFO");
const album = Array.isArray(this.albums) ? this.albums.find((a) => a.id === target._albumId) : { id: -1, title: '' };
if (this.config.autoInfoPosition) {
let op = (album, target) => {
let now = new Date();
Expand All @@ -155,7 +168,7 @@ Module.register("MMM-GooglePhotos", {
if (typeof this.config.autoInfoPosition === "function") {
op = this.config.autoInfoPosition;
}
let [top, left, bottom, right] = op(album, target);
const [top, left, bottom, right] = op(album, target);
info.style.setProperty("--top", top);
info.style.setProperty("--left", left);
info.style.setProperty("--bottom", bottom);
Expand Down Expand Up @@ -203,7 +216,7 @@ Module.register("MMM-GooglePhotos", {
wrapper.appendChild(back);
wrapper.appendChild(current);
wrapper.appendChild(info);
console.log("updated!");
Log.info("updated!");
return wrapper;
},

Expand Down
Loading
Loading