Skip to content

Commit b01eb18

Browse files
committed
fix: update eslint to v9
1 parent 578c8f7 commit b01eb18

9 files changed

+138
-470
lines changed

.eslintrc.json

-51
This file was deleted.

GPhotos.js

-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ const { OAuth2Client } = require("google-auth-library");
1111
*/
1212
const Axios = require("axios");
1313
const moment = require("moment");
14-
const { isAxiosError } = require("axios");
1514
const { error_to_string } = require("./error_to_string");
1615
const { ConfigFileError, AuthError } = require("./Errors");
1716

@@ -196,7 +195,6 @@ class GPhotos {
196195
const client = await this.onAuthReady();
197196
let token = client.credentials.access_token;
198197
let list = [];
199-
let found = 0;
200198
const getAlbum = async (pageSize = 50, pageToken = "") => {
201199
this.log("Getting Album info chunks.");
202200
let params = {
@@ -207,7 +205,6 @@ class GPhotos {
207205
let response = await this.request(token, type, "get", params, null);
208206
let body = response.data;
209207
if (body[type] && Array.isArray(body[type])) {
210-
found += body[type].length;
211208
list = list.concat(body[type]);
212209
}
213210
if (body.nextPageToken) {

MMM-GooglePhotos.js

+57-50
Original file line numberDiff line numberDiff line change
@@ -135,70 +135,77 @@ Module.register("MMM-GooglePhotos", {
135135
this.needMorePicsFlag = true;
136136
}
137137
if (this.needMorePicsFlag) {
138-
this.sendSocketNotification("NEED_MORE_PICS", []);
138+
setTimeout(() => {
139+
this.sendSocketNotification("NEED_MORE_PICS", []);
140+
}, 2000);
139141
}
140142
},
141143

142144
ready: function (url, target) {
143145
let hidden = document.createElement("img");
146+
const _this = this;
144147
hidden.onerror = (event, source, lineno, colno, error) => {
145148
const errObj = { url, event, source, lineno, colno, error };
146149
this.sendSocketNotification("IMAGE_LOAD_FAIL", errObj);
147150
};
148151
hidden.onload = () => {
149-
let back = document.getElementById("GPHOTO_BACK");
150-
let current = document.getElementById("GPHOTO_CURRENT");
151-
current.textContent = "";
152-
//current.classList.remove("animated")
153-
// let dom = document.getElementById("GPHOTO");
154-
back.style.backgroundImage = `url(${url})`;
155-
current.style.backgroundImage = `url(${url})`;
156-
current.classList.add("animated");
157-
const info = document.getElementById("GPHOTO_INFO");
158-
const album = Array.isArray(this.albums) ? this.albums.find((a) => a.id === target._albumId) : { id: -1, title: '' };
159-
if (this.config.autoInfoPosition) {
160-
let op = (album, target) => {
161-
let now = new Date();
162-
let q = Math.floor(now.getMinutes() / 15);
163-
let r = [
164-
[0, "none", "none", 0],
165-
["none", "none", 0, 0],
166-
["none", 0, 0, "none"],
167-
[0, 0, "none", "none"],
168-
];
169-
return r[q];
170-
};
171-
if (typeof this.config.autoInfoPosition === "function") {
172-
op = this.config.autoInfoPosition;
173-
}
174-
const [top, left, bottom, right] = op(album, target);
175-
info.style.setProperty("--top", top);
176-
info.style.setProperty("--left", left);
177-
info.style.setProperty("--bottom", bottom);
178-
info.style.setProperty("--right", right);
179-
}
180-
info.innerHTML = "";
181-
let albumCover = document.createElement("div");
182-
albumCover.classList.add("albumCover");
183-
albumCover.style.backgroundImage = `url(modules/MMM-GooglePhotos/cache/${album.id})`;
184-
let albumTitle = document.createElement("div");
185-
albumTitle.classList.add("albumTitle");
186-
albumTitle.innerHTML = album.title;
187-
let photoTime = document.createElement("div");
188-
photoTime.classList.add("photoTime");
189-
photoTime.innerHTML = this.config.timeFormat === "relative" ? moment(target.mediaMetadata.creationTime).fromNow() : moment(target.mediaMetadata.creationTime).format(this.config.timeFormat);
190-
let infoText = document.createElement("div");
191-
infoText.classList.add("infoText");
192-
193-
info.appendChild(albumCover);
194-
infoText.appendChild(albumTitle);
195-
infoText.appendChild(photoTime);
196-
info.appendChild(infoText);
197-
this.sendSocketNotification("IMAGE_LOADED", { id: target.id, index: this.index });
152+
_this.render(url, target);
198153
};
199154
hidden.src = url;
200155
},
201156

157+
render: function (url, target) {
158+
let back = document.getElementById("GPHOTO_BACK");
159+
let current = document.getElementById("GPHOTO_CURRENT");
160+
current.textContent = "";
161+
//current.classList.remove("animated")
162+
// let dom = document.getElementById("GPHOTO");
163+
back.style.backgroundImage = `url(${url})`;
164+
current.style.backgroundImage = `url(${url})`;
165+
current.classList.add("animated");
166+
const info = document.getElementById("GPHOTO_INFO");
167+
const album = Array.isArray(this.albums) ? this.albums.find((a) => a.id === target._albumId) : { id: -1, title: '' };
168+
if (this.config.autoInfoPosition) {
169+
let op = (album, target) => {
170+
let now = new Date();
171+
let q = Math.floor(now.getMinutes() / 15);
172+
let r = [
173+
[0, "none", "none", 0],
174+
["none", "none", 0, 0],
175+
["none", 0, 0, "none"],
176+
[0, 0, "none", "none"],
177+
];
178+
return r[q];
179+
};
180+
if (typeof this.config.autoInfoPosition === "function") {
181+
op = this.config.autoInfoPosition;
182+
}
183+
const [top, left, bottom, right] = op(album, target);
184+
info.style.setProperty("--top", top);
185+
info.style.setProperty("--left", left);
186+
info.style.setProperty("--bottom", bottom);
187+
info.style.setProperty("--right", right);
188+
}
189+
info.innerHTML = "";
190+
let albumCover = document.createElement("div");
191+
albumCover.classList.add("albumCover");
192+
albumCover.style.backgroundImage = `url(modules/MMM-GooglePhotos/cache/${album.id})`;
193+
let albumTitle = document.createElement("div");
194+
albumTitle.classList.add("albumTitle");
195+
albumTitle.innerHTML = album.title;
196+
let photoTime = document.createElement("div");
197+
photoTime.classList.add("photoTime");
198+
photoTime.innerHTML = this.config.timeFormat === "relative" ? moment(target.mediaMetadata.creationTime).fromNow() : moment(target.mediaMetadata.creationTime).format(this.config.timeFormat);
199+
let infoText = document.createElement("div");
200+
infoText.classList.add("infoText");
201+
202+
info.appendChild(albumCover);
203+
infoText.appendChild(albumTitle);
204+
infoText.appendChild(photoTime);
205+
info.appendChild(infoText);
206+
this.sendSocketNotification("IMAGE_LOADED", { id: target.id, index: this.index });
207+
},
208+
202209
getDom: function () {
203210
let wrapper = document.createElement("div");
204211
wrapper.id = "GPHOTO";

error_to_string.js

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
const { isAxiosError } = require("axios");
2-
31
const error_to_string = (error) => {
42
const logMessage = [];
53
if (error.response) {

eslint.config.mjs

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import globals from "globals";
2+
import js from "@eslint/js";
3+
import jsdoc from "eslint-plugin-jsdoc";
4+
5+
export default [
6+
js.configs.recommended,
7+
jsdoc.configs['flat/recommended'],
8+
jsdoc.configs['flat/recommended-typescript-flavor'],
9+
{
10+
plugins: {
11+
jsdoc,
12+
},
13+
14+
languageOptions: {
15+
globals: {
16+
...globals.browser,
17+
...globals.node,
18+
Log: true,
19+
MM: true,
20+
Module: true,
21+
moment: true,
22+
},
23+
24+
ecmaVersion: 13,
25+
sourceType: "module",
26+
27+
parserOptions: {
28+
ecmaFeatures: {
29+
globalReturn: true,
30+
},
31+
},
32+
},
33+
34+
rules: {
35+
"comma-dangle": ["error", {
36+
arrays: "always-multiline",
37+
objects: "always-multiline",
38+
imports: "always-multiline",
39+
exports: "always-multiline",
40+
functions: "only-multiline",
41+
}],
42+
43+
eqeqeq: "error",
44+
"no-prototype-builtins": "off",
45+
"no-unused-vars": "warn",
46+
"no-useless-return": "error",
47+
"no-var": "error",
48+
"jsdoc/require-returns": "off",
49+
"jsdoc/require-param-description": "off",
50+
semi: "error",
51+
},
52+
},
53+
];

generate_token_v2.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ function testKeyFile(keyFilePath) {
1818
if (!keys) {
1919
throw new Error();
2020
}
21-
} catch (err) {
21+
} catch {
2222
throw new Error(`keyfile ${keyFilePath} is not a valid GCP credential keyfile`);
2323
}
2424
}

node_helper.js

+4-6
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ const { RE2 } = require("re2-wasm");
1010
const { Set } = require('immutable');
1111
const NodeHelper = require("node_helper");
1212
const Log = require("logger");
13-
const { mkdirp } = require("mkdirp");
1413
const GP = require("./GPhotos.js");
1514
const authOption = require("./google_auth.json");
1615
const { shuffle } = require("./shuffle.js");
@@ -90,7 +89,7 @@ module.exports = NodeHelper.create({
9089
}
9190
let uploadToken = await GPhotos.upload(path);
9291
if (uploadToken) {
93-
let result = await GPhotos.create(uploadToken, this.uploadAlbumId);
92+
await GPhotos.create(uploadToken, this.uploadAlbumId);
9493
Log.info("Upload completed.");
9594
} else {
9695
Log.error("Upload Fails.");
@@ -116,7 +115,6 @@ module.exports = NodeHelper.create({
116115
}
117116
delete this.config.albums;
118117

119-
120118
this.tryToIntitialize();
121119
},
122120

@@ -192,8 +190,6 @@ module.exports = NodeHelper.create({
192190
this.lastLocalPhotoPntr = this.localPhotoPntr;
193191
this.localPhotoPntr = this.localPhotoPntr + list.length;
194192
this.log_debug("refreshed: ", list.length, ", totalLength: ", this.localPhotoList.length, ", Pntr: ", this.localPhotoPntr);
195-
196-
this.log_debug("just sent ", list.length, " more pics");
197193
} else {
198194
Log.error("couldn't send ", list.length, " pics");
199195
}
@@ -291,14 +287,16 @@ module.exports = NodeHelper.create({
291287
Log.info("Finish Album scanning. Properly scanned :", selecetedAlbums.length);
292288
Log.info("Albums:", selecetedAlbums.map((a) => a.title).join(", "));
293289
this.writeFileSafe(this.CACHE_ALBUMNS_PATH, JSON.stringify(selecetedAlbums, null, 4), "Album list cache");
290+
294291
for (let a of selecetedAlbums) {
295292
let url = a.coverPhotoBaseUrl + "=w160-h160-c";
296-
let fpath = path.resolve(this.path, "cache", a.id);
293+
let fpath = path.join(this.path, "cache", a.id);
297294
let file = fs.createWriteStream(fpath);
298295
const response = await fetch(url);
299296
await finished(Readable.fromWeb(response.body).pipe(file));
300297
}
301298
this.selecetedAlbums = selecetedAlbums;
299+
Log.info("getAlbumList done");
302300
this.sendSocketNotification("INITIALIZED", selecetedAlbums);
303301
},
304302

0 commit comments

Comments
 (0)