Skip to content

Commit

Permalink
Merge pull request #193 from hermanho/dev
Browse files Browse the repository at this point in the history
2.1.7
  • Loading branch information
hermanho authored Aug 15, 2024
2 parents 767d087 + 74b84f5 commit 843876a
Show file tree
Hide file tree
Showing 11 changed files with 594 additions and 999 deletions.
51 changes: 0 additions & 51 deletions .eslintrc.json

This file was deleted.

35 changes: 35 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Lint

on:
# Trigger the workflow on push or pull request,
# but only for the main branch
push:
branches:
- master
# Replace pull_request with pull_request_target if you
# plan to use this action with forks, see the Limitations section
pull_request:
branches:
- master

jobs:
run-linters:
name: Run linters
runs-on: ubuntu-latest

steps:
- name: Check out Git repository
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 20

# ESLint and Prettier must be in `package.json`
- name: Install Node.js dependencies
run: npm ci

- uses: sibiraj-s/action-eslint@v3
with:
annotations: true
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# MMM-GooglePhotos Change Log

**`[2.1.7] - 2024/03/16`**
- Fixed: update axios to 1.7.4 [CVE-2024-39338](https://security.snyk.io/vuln/SNYK-JS-AXIOS-7361793)
- Fixed: depedencies packages update
- Fixed: albumn info did not show when startup caching

**`[2.1.6] - 2024/03/16`**
- Fixed: [#187](https://github.com/hermanho/MMM-GooglePhotos/issues/187) fix pageSize parameter
- Fixed: update follow-redirects to 1.15.6 [CVE-2024-28849](https://github.com/advisories/GHSA-cxjh-pqwp-8mfp)
Expand Down
8 changes: 4 additions & 4 deletions GPhotos.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const { OAuth2Client } = require("google-auth-library");
*/
const Axios = require("axios");
const moment = require("moment");
const { isAxiosError } = require("axios");
const { error_to_string } = require("./error_to_string");
const { ConfigFileError, AuthError } = require("./Errors");

Expand Down Expand Up @@ -45,7 +44,7 @@ class Auth extends EventEmitter {
console.log("[GPHOTOS:AUTH]", ...args);
}
: () => { };
if (this.#config === undefined) config = {};
if (this.#config === undefined) this.#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 @@ -174,6 +173,9 @@ class GPhotos {
}
}

/**
* @returns {Promise<GooglePhotos.Album[]>}

Check warning on line 177 in GPhotos.js

View workflow job for this annotation

GitHub Actions / Run linters

Missing JSDoc @returns description
*/
async getAlbums() {
let albums = await this.getAlbumType("albums");
let shared = await this.getAlbumType("sharedAlbums");
Expand All @@ -196,7 +198,6 @@ class GPhotos {
const client = await this.onAuthReady();
let token = client.credentials.access_token;
let list = [];
let found = 0;
const getAlbum = async (pageSize = 50, pageToken = "") => {
this.log("Getting Album info chunks.");
let params = {
Expand All @@ -207,7 +208,6 @@ class GPhotos {
let response = await this.request(token, type, "get", params, null);
let body = response.data;
if (body[type] && Array.isArray(body[type])) {
found += body[type].length;
list = list.concat(body[type]);
}
if (body.nextPageToken) {
Expand Down
110 changes: 60 additions & 50 deletions MMM-GooglePhotos.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ Module.register("MMM-GooglePhotos", {
}, this.config.updateInterval);
}
}
if (noti === "UPDATE_ALBUMS") {
this.albums = payload;
}
if (noti === "MORE_PICS") {
if (payload && Array.isArray(payload) && payload.length > 0) this.needMorePicsFlag = false;
this.scanned = payload;
Expand Down Expand Up @@ -132,70 +135,77 @@ Module.register("MMM-GooglePhotos", {
this.needMorePicsFlag = true;
}
if (this.needMorePicsFlag) {
this.sendSocketNotification("NEED_MORE_PICS", []);
setTimeout(() => {
this.sendSocketNotification("NEED_MORE_PICS", []);
}, 2000);
}
},

ready: function (url, target) {
let hidden = document.createElement("img");
const _this = this;
hidden.onerror = (event, source, lineno, colno, error) => {
const errObj = { url, event, source, lineno, colno, error };
this.sendSocketNotification("IMAGE_LOAD_FAIL", errObj);
};
hidden.onload = () => {
let back = document.getElementById("GPHOTO_BACK");
let current = document.getElementById("GPHOTO_CURRENT");
current.textContent = "";
//current.classList.remove("animated")
// let dom = document.getElementById("GPHOTO");
back.style.backgroundImage = `url(${url})`;
current.style.backgroundImage = `url(${url})`;
current.classList.add("animated");
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();
let q = Math.floor(now.getMinutes() / 15);
let r = [
[0, "none", "none", 0],
["none", "none", 0, 0],
["none", 0, 0, "none"],
[0, 0, "none", "none"],
];
return r[q];
};
if (typeof this.config.autoInfoPosition === "function") {
op = this.config.autoInfoPosition;
}
const [top, left, bottom, right] = op(album, target);
info.style.setProperty("--top", top);
info.style.setProperty("--left", left);
info.style.setProperty("--bottom", bottom);
info.style.setProperty("--right", right);
}
info.innerHTML = "";
let albumCover = document.createElement("div");
albumCover.classList.add("albumCover");
albumCover.style.backgroundImage = `url(modules/MMM-GooglePhotos/cache/${album.id})`;
let albumTitle = document.createElement("div");
albumTitle.classList.add("albumTitle");
albumTitle.innerHTML = album.title;
let photoTime = document.createElement("div");
photoTime.classList.add("photoTime");
photoTime.innerHTML = this.config.timeFormat === "relative" ? moment(target.mediaMetadata.creationTime).fromNow() : moment(target.mediaMetadata.creationTime).format(this.config.timeFormat);
let infoText = document.createElement("div");
infoText.classList.add("infoText");

info.appendChild(albumCover);
infoText.appendChild(albumTitle);
infoText.appendChild(photoTime);
info.appendChild(infoText);
this.sendSocketNotification("IMAGE_LOADED", { id: target.id, index: this.index });
_this.render(url, target);
};
hidden.src = url;
},

render: function (url, target) {
let back = document.getElementById("GPHOTO_BACK");
let current = document.getElementById("GPHOTO_CURRENT");
current.textContent = "";
//current.classList.remove("animated")
// let dom = document.getElementById("GPHOTO");
back.style.backgroundImage = `url(${url})`;
current.style.backgroundImage = `url(${url})`;
current.classList.add("animated");
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) => {

Check warning on line 169 in MMM-GooglePhotos.js

View workflow job for this annotation

GitHub Actions / Run linters

'album' is defined but never used

Check warning on line 169 in MMM-GooglePhotos.js

View workflow job for this annotation

GitHub Actions / Run linters

'target' is defined but never used
let now = new Date();
let q = Math.floor(now.getMinutes() / 15);
let r = [
[0, "none", "none", 0],
["none", "none", 0, 0],
["none", 0, 0, "none"],
[0, 0, "none", "none"],
];
return r[q];
};
if (typeof this.config.autoInfoPosition === "function") {
op = this.config.autoInfoPosition;
}
const [top, left, bottom, right] = op(album, target);
info.style.setProperty("--top", top);
info.style.setProperty("--left", left);
info.style.setProperty("--bottom", bottom);
info.style.setProperty("--right", right);
}
info.innerHTML = "";
let albumCover = document.createElement("div");
albumCover.classList.add("albumCover");
albumCover.style.backgroundImage = `url(modules/MMM-GooglePhotos/cache/${album.id})`;
let albumTitle = document.createElement("div");
albumTitle.classList.add("albumTitle");
albumTitle.innerHTML = album.title;
let photoTime = document.createElement("div");
photoTime.classList.add("photoTime");
photoTime.innerHTML = this.config.timeFormat === "relative" ? moment(target.mediaMetadata.creationTime).fromNow() : moment(target.mediaMetadata.creationTime).format(this.config.timeFormat);
let infoText = document.createElement("div");
infoText.classList.add("infoText");

info.appendChild(albumCover);
infoText.appendChild(albumTitle);
infoText.appendChild(photoTime);
info.appendChild(infoText);
this.sendSocketNotification("IMAGE_LOADED", { id: target.id, index: this.index });
},

getDom: function () {
let wrapper = document.createElement("div");
wrapper.id = "GPHOTO";
Expand Down
2 changes: 0 additions & 2 deletions error_to_string.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const { isAxiosError } = require("axios");

const error_to_string = (error) => {
const logMessage = [];
if (error.response) {
Expand Down
53 changes: 53 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import globals from "globals";
import js from "@eslint/js";
import jsdoc from "eslint-plugin-jsdoc";

export default [
js.configs.recommended,
jsdoc.configs['flat/recommended'],
jsdoc.configs['flat/recommended-typescript-flavor'],
{
plugins: {
jsdoc,
},

languageOptions: {
globals: {
...globals.browser,
...globals.node,
Log: true,
MM: true,
Module: true,
moment: true,
},

ecmaVersion: 13,
sourceType: "module",

parserOptions: {
ecmaFeatures: {
globalReturn: true,
},
},
},

rules: {
"comma-dangle": ["error", {
arrays: "always-multiline",
objects: "always-multiline",
imports: "always-multiline",
exports: "always-multiline",
functions: "only-multiline",
}],

eqeqeq: "error",
"no-prototype-builtins": "off",
"no-unused-vars": "warn",
"no-useless-return": "error",
"no-var": "error",
"jsdoc/require-returns": "off",
"jsdoc/require-param-description": "off",
semi: "error",
},
},
];
2 changes: 1 addition & 1 deletion generate_token_v2.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function testKeyFile(keyFilePath) {
if (!keys) {
throw new Error();
}
} catch (err) {
} catch {
throw new Error(`keyfile ${keyFilePath} is not a valid GCP credential keyfile`);
}
}
Expand Down
Loading

0 comments on commit 843876a

Please sign in to comment.