mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-06-27 11:50:00 +00:00
## [2.27.0] - 2024-04-01 Thanks to: @bugsounet, @crazyscot, @illimarkangur, @jkriegshauser, @khassel, @KristjanESPERANTO, @Paranoid93, @rejas, @sdetweil and @vppencilsharpener. This release marks the first release without Michael Teeuw (@michmich). A very special thanks to him for creating MagicMirror and leading the project for so many years. For more info, please read the following post: [A New Chapter for MagicMirror: The Community Takes the Lead](https://forum.magicmirror.builders/topic/18329/a-new-chapter-for-magicmirror-the-community-takes-the-lead). ### Added - Output of system information to the console for troubleshooting (#3328 and #3337), ignore errors under aarch64 (#3349) - [chore] Add `eslint-plugin-package-json` to lint the `package.json` files (#3368) - [weather] `showHumidity` config is now a string describing where to show this element. Supported values: "wind", "temp", "feelslike", "below", "none". (#3330) - electron-rebuild test suite for electron and 3rd party modules compatibility (#3392) - Create MM² icon and attach it to electron process (#3407) ### Updated - Update updatenotification (update_helper.js): Recode with pm2 library (#3332) - Removing lodash dependency by replacing merge by spread operator (#3339) - Use node prefix for build-in modules (#3340) - Rework logging colors (#3350) - Update pm2 to v5.3.1 with no allow-ghsas (#3364) - [chore] Update husky and let lint-staged fix ESLint issues - [chore] Update dependencies including electron to v29 (#3357) and node-ical - Update translations for estonian (#3371) - Update electron to v29 and update other dependencies - [calendar] fullDay events over several days now show the left days from the first day on and 'today' on the last day - Update layout of current weather indoor values ### Fixed - Correct apibase of weathergov weatherprovider to match documentation (#2926) - Worked around several issues in the RRULE library that were causing deleted calender events to still show, some initial and recurring events to not show, and some event times to be off an hour. (#3291) - Skip changelog requirement when running tests for dependency updates (#3320) - Display precipitation probability when it is 0% instead of blank/empty (#3345) - [newsfeed] Suppress unsightly animation cases when there are 0 or 1 active news items (#3336) - [newsfeed] Always compute the feed item URL using the same helper function (#3336) - Ignore all custom css files (#3359) - [newsfeed] Fix newsfeed stall issue introduced by #3336 (#3361) - Changed `log.debug` to `log.log` in `app.js` where logLevel is not set because config is not loaded at this time (#3353) - [calendar] deny fetch interval < 60000 and set 60000 in this case (prevent fetch loop failed) (#3382) - added message in case where config.js is missing the module.export line PR #3383 - Fixed an issue where recurring events could extend past their recurrence end date (#3393) - Don't display any `npm WARN <....>` on install (#3399) - Fixed move suncalc dependency to production from dev, as it is used by clock module - [compliments] Fix mirror not responding anymore when no compliments are to be shown (#3385) ### Deleted - Unneeded file headers (#3358) --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Michael Teeuw <michael@xonaymedia.nl> Co-authored-by: Kristjan ESPERANTO <35647502+KristjanESPERANTO@users.noreply.github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Karsten Hassel <hassel@gmx.de> Co-authored-by: Ross Younger <crazyscot@gmail.com> Co-authored-by: Bugsounet - Cédric <github@bugsounet.fr> Co-authored-by: jkriegshauser <joshuakr@nvidia.com> Co-authored-by: illimarkangur <116028111+illimarkangur@users.noreply.github.com> Co-authored-by: sam detweiler <sdetweil@gmail.com> Co-authored-by: vppencilsharpener <tim.pray@gmail.com> Co-authored-by: Paranoid93 <6515818+Paranoid93@users.noreply.github.com>
186 lines
4.9 KiB
JavaScript
186 lines
4.9 KiB
JavaScript
const crypto = require("node:crypto");
|
|
const stream = require("node:stream");
|
|
const FeedMe = require("feedme");
|
|
const iconv = require("iconv-lite");
|
|
const { htmlToText } = require("html-to-text");
|
|
const Log = require("logger");
|
|
const NodeHelper = require("node_helper");
|
|
|
|
/**
|
|
* Responsible for requesting an update on the set interval and broadcasting the data.
|
|
* @param {string} url URL of the news feed.
|
|
* @param {number} reloadInterval Reload interval in milliseconds.
|
|
* @param {string} encoding Encoding of the feed.
|
|
* @param {boolean} logFeedWarnings If true log warnings when there is an error parsing a news article.
|
|
* @param {boolean} useCorsProxy If true cors proxy is used for article url's.
|
|
* @class
|
|
*/
|
|
const NewsfeedFetcher = function (url, reloadInterval, encoding, logFeedWarnings, useCorsProxy) {
|
|
let reloadTimer = null;
|
|
let items = [];
|
|
let reloadIntervalMS = reloadInterval;
|
|
|
|
let fetchFailedCallback = function () {};
|
|
let itemsReceivedCallback = function () {};
|
|
|
|
if (reloadIntervalMS < 1000) {
|
|
reloadIntervalMS = 1000;
|
|
}
|
|
|
|
/* private methods */
|
|
|
|
/**
|
|
* Request the new items.
|
|
*/
|
|
const fetchNews = () => {
|
|
clearTimeout(reloadTimer);
|
|
reloadTimer = null;
|
|
items = [];
|
|
|
|
const parser = new FeedMe();
|
|
|
|
parser.on("item", (item) => {
|
|
const title = item.title;
|
|
let description = item.description || item.summary || item.content || "";
|
|
const pubdate = item.pubdate || item.published || item.updated || item["dc:date"] || item["a10:updated"];
|
|
const url = item.url || item.link || "";
|
|
|
|
if (title && pubdate) {
|
|
// Convert HTML entities, codes and tag
|
|
description = htmlToText(description, {
|
|
wordwrap: false,
|
|
selectors: [
|
|
{ selector: "a", options: { ignoreHref: true, noAnchorUrl: true } },
|
|
{ selector: "br", format: "inlineSurround", options: { prefix: " " } },
|
|
{ selector: "img", format: "skip" }
|
|
]
|
|
});
|
|
|
|
items.push({
|
|
title: title,
|
|
description: description,
|
|
pubdate: pubdate,
|
|
url: url,
|
|
useCorsProxy: useCorsProxy,
|
|
hash: crypto.createHash("sha256").update(`${pubdate} :: ${title} :: ${url}`).digest("hex")
|
|
});
|
|
} else if (logFeedWarnings) {
|
|
Log.warn("Can't parse feed item:");
|
|
Log.warn(item);
|
|
Log.warn(`Title: ${title}`);
|
|
Log.warn(`Description: ${description}`);
|
|
Log.warn(`Pubdate: ${pubdate}`);
|
|
}
|
|
});
|
|
|
|
parser.on("end", () => {
|
|
this.broadcastItems();
|
|
});
|
|
|
|
parser.on("error", (error) => {
|
|
fetchFailedCallback(this, error);
|
|
scheduleTimer();
|
|
});
|
|
|
|
//"end" event is not broadcast if the feed is empty but "finish" is used for both
|
|
parser.on("finish", () => {
|
|
scheduleTimer();
|
|
});
|
|
|
|
parser.on("ttl", (minutes) => {
|
|
try {
|
|
// 86400000 = 24 hours is mentioned in the docs as maximum value:
|
|
const ttlms = Math.min(minutes * 60 * 1000, 86400000);
|
|
if (ttlms > reloadIntervalMS) {
|
|
reloadIntervalMS = ttlms;
|
|
Log.info(`Newsfeed-Fetcher: reloadInterval set to ttl=${reloadIntervalMS} for url ${url}`);
|
|
}
|
|
} catch (error) {
|
|
Log.warn(`Newsfeed-Fetcher: feed ttl is no valid integer=${minutes} for url ${url}`);
|
|
}
|
|
});
|
|
|
|
const nodeVersion = Number(process.version.match(/^v(\d+\.\d+)/)[1]);
|
|
const headers = {
|
|
"User-Agent": `Mozilla/5.0 (Node.js ${nodeVersion}) MagicMirror/${global.version}`,
|
|
"Cache-Control": "max-age=0, no-cache, no-store, must-revalidate",
|
|
Pragma: "no-cache"
|
|
};
|
|
|
|
fetch(url, { headers: headers })
|
|
.then(NodeHelper.checkFetchStatus)
|
|
.then((response) => {
|
|
let nodeStream;
|
|
if (response.body instanceof stream.Readable) {
|
|
nodeStream = response.body;
|
|
} else {
|
|
nodeStream = stream.Readable.fromWeb(response.body);
|
|
}
|
|
nodeStream.pipe(iconv.decodeStream(encoding)).pipe(parser);
|
|
})
|
|
.catch((error) => {
|
|
fetchFailedCallback(this, error);
|
|
scheduleTimer();
|
|
});
|
|
};
|
|
|
|
/**
|
|
* Schedule the timer for the next update.
|
|
*/
|
|
const scheduleTimer = function () {
|
|
clearTimeout(reloadTimer);
|
|
reloadTimer = setTimeout(function () {
|
|
fetchNews();
|
|
}, reloadIntervalMS);
|
|
};
|
|
|
|
/* public methods */
|
|
|
|
/**
|
|
* Update the reload interval, but only if we need to increase the speed.
|
|
* @param {number} interval Interval for the update in milliseconds.
|
|
*/
|
|
this.setReloadInterval = function (interval) {
|
|
if (interval > 1000 && interval < reloadIntervalMS) {
|
|
reloadIntervalMS = interval;
|
|
}
|
|
};
|
|
|
|
/**
|
|
* Initiate fetchNews();
|
|
*/
|
|
this.startFetch = function () {
|
|
fetchNews();
|
|
};
|
|
|
|
/**
|
|
* Broadcast the existing items.
|
|
*/
|
|
this.broadcastItems = function () {
|
|
if (items.length <= 0) {
|
|
Log.info("Newsfeed-Fetcher: No items to broadcast yet.");
|
|
return;
|
|
}
|
|
Log.info(`Newsfeed-Fetcher: Broadcasting ${items.length} items.`);
|
|
itemsReceivedCallback(this);
|
|
};
|
|
|
|
this.onReceive = function (callback) {
|
|
itemsReceivedCallback = callback;
|
|
};
|
|
|
|
this.onError = function (callback) {
|
|
fetchFailedCallback = callback;
|
|
};
|
|
|
|
this.url = function () {
|
|
return url;
|
|
};
|
|
|
|
this.items = function () {
|
|
return items;
|
|
};
|
|
};
|
|
|
|
module.exports = NewsfeedFetcher;
|