Skip to content

Commit

Permalink
fix: update eslint to v9
Browse files Browse the repository at this point in the history
  • Loading branch information
hermanho committed Aug 15, 2024
1 parent 578c8f7 commit b01eb18
Show file tree
Hide file tree
Showing 9 changed files with 138 additions and 470 deletions.
51 changes: 0 additions & 51 deletions .eslintrc.json

This file was deleted.

3 changes: 0 additions & 3 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 @@ -196,7 +195,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 +205,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
107 changes: 57 additions & 50 deletions MMM-GooglePhotos.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,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) => {
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
10 changes: 4 additions & 6 deletions node_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const { RE2 } = require("re2-wasm");
const { Set } = require('immutable');
const NodeHelper = require("node_helper");
const Log = require("logger");
const { mkdirp } = require("mkdirp");
const GP = require("./GPhotos.js");
const authOption = require("./google_auth.json");
const { shuffle } = require("./shuffle.js");
Expand Down Expand Up @@ -90,7 +89,7 @@ module.exports = NodeHelper.create({
}
let uploadToken = await GPhotos.upload(path);
if (uploadToken) {
let result = await GPhotos.create(uploadToken, this.uploadAlbumId);
await GPhotos.create(uploadToken, this.uploadAlbumId);
Log.info("Upload completed.");
} else {
Log.error("Upload Fails.");
Expand All @@ -116,7 +115,6 @@ module.exports = NodeHelper.create({
}
delete this.config.albums;


this.tryToIntitialize();
},

Expand Down Expand Up @@ -192,8 +190,6 @@ module.exports = NodeHelper.create({
this.lastLocalPhotoPntr = this.localPhotoPntr;
this.localPhotoPntr = this.localPhotoPntr + list.length;
this.log_debug("refreshed: ", list.length, ", totalLength: ", this.localPhotoList.length, ", Pntr: ", this.localPhotoPntr);

this.log_debug("just sent ", list.length, " more pics");
} else {
Log.error("couldn't send ", list.length, " pics");
}
Expand Down Expand Up @@ -291,14 +287,16 @@ module.exports = NodeHelper.create({
Log.info("Finish Album scanning. Properly scanned :", selecetedAlbums.length);
Log.info("Albums:", selecetedAlbums.map((a) => a.title).join(", "));
this.writeFileSafe(this.CACHE_ALBUMNS_PATH, JSON.stringify(selecetedAlbums, null, 4), "Album list cache");

for (let a of selecetedAlbums) {
let url = a.coverPhotoBaseUrl + "=w160-h160-c";
let fpath = path.resolve(this.path, "cache", a.id);
let fpath = path.join(this.path, "cache", a.id);
let file = fs.createWriteStream(fpath);
const response = await fetch(url);
await finished(Readable.fromWeb(response.body).pipe(file));
}
this.selecetedAlbums = selecetedAlbums;
Log.info("getAlbumList done");
this.sendSocketNotification("INITIALIZED", selecetedAlbums);
},

Expand Down
Loading

0 comments on commit b01eb18

Please sign in to comment.