mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-08-21 12:55:22 +00:00
Add fetcher_helper for calendar and newsfeed
This commit is contained in:
@@ -90,7 +90,7 @@ Module.register("newsfeed", {
|
||||
this.loaded = true;
|
||||
this.error = null;
|
||||
} else if (notification === "FETCH_ERROR") {
|
||||
this.error = `Could not fetch newsfeed ${payload.url}`;
|
||||
this.error = `${payload.error}`;
|
||||
this.scheduleUpdateInterval();
|
||||
} else if (notification === "INCORRECT_URL") {
|
||||
this.error = `Incorrect url: ${payload.url}`;
|
||||
|
@@ -5,6 +5,7 @@
|
||||
* MIT Licensed.
|
||||
*/
|
||||
const Log = require("logger");
|
||||
const FetcherHelper = require("fetcher_helper");
|
||||
const FeedMe = require("feedme");
|
||||
const fetch = require("node-fetch");
|
||||
const iconv = require("iconv-lite");
|
||||
@@ -84,12 +85,13 @@ const NewsfeedFetcher = function (url, reloadInterval, encoding, logFeedWarnings
|
||||
};
|
||||
|
||||
fetch(url, { headers: headers })
|
||||
.catch((error) => {
|
||||
fetchFailedCallback(this, error);
|
||||
scheduleTimer();
|
||||
.then(FetcherHelper.checkStatus)
|
||||
.then((response) => {
|
||||
response.body.pipe(iconv.decodeStream(encoding)).pipe(parser);
|
||||
})
|
||||
.then((res) => {
|
||||
res.body.pipe(iconv.decodeStream(encoding)).pipe(parser);
|
||||
.catch((error) => {
|
||||
fetchFailedCallback(this, error.message);
|
||||
scheduleTimer();
|
||||
});
|
||||
};
|
||||
|
||||
|
@@ -44,7 +44,7 @@ module.exports = NodeHelper.create({
|
||||
|
||||
let fetcher;
|
||||
if (typeof this.fetchers[url] === "undefined") {
|
||||
Log.log("Create new news fetcher for url: " + url + " - Interval: " + reloadInterval);
|
||||
Log.log("Create new newsfetcher for url: " + url + " - Interval: " + reloadInterval);
|
||||
fetcher = new NewsfeedFetcher(url, reloadInterval, encoding, config.logFeedWarnings);
|
||||
|
||||
fetcher.onReceive(() => {
|
||||
@@ -61,7 +61,7 @@ module.exports = NodeHelper.create({
|
||||
|
||||
this.fetchers[url] = fetcher;
|
||||
} else {
|
||||
Log.log("Use existing news fetcher for url: " + url);
|
||||
Log.log("Use existing newsfetcher for url: " + url);
|
||||
fetcher = this.fetchers[url];
|
||||
fetcher.setReloadInterval(reloadInterval);
|
||||
fetcher.broadcastItems();
|
||||
|
Reference in New Issue
Block a user