mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-06-27 19:53:36 +00:00
snapshot
This commit is contained in:
parent
ea6eebd809
commit
53e300bd31
@ -6,7 +6,8 @@
|
|||||||
*/
|
*/
|
||||||
const Log = require("logger");
|
const Log = require("logger");
|
||||||
const ical = require("node-ical");
|
const ical = require("node-ical");
|
||||||
const request = require("request");
|
const fetch = require("node-fetch");
|
||||||
|
const https = require('https');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Moment date
|
* Moment date
|
||||||
@ -43,22 +44,22 @@ const CalendarFetcher = function (url, reloadInterval, excludedEvents, maximumEn
|
|||||||
const fetchCalendar = function () {
|
const fetchCalendar = function () {
|
||||||
clearTimeout(reloadTimer);
|
clearTimeout(reloadTimer);
|
||||||
reloadTimer = null;
|
reloadTimer = null;
|
||||||
|
httpsAgent = null;
|
||||||
|
|
||||||
const nodeVersion = Number(process.version.match(/^v(\d+\.\d+)/)[1]);
|
const nodeVersion = Number(process.version.match(/^v(\d+\.\d+)/)[1]);
|
||||||
const opts = {
|
const headers = {
|
||||||
headers: {
|
"User-Agent": "Mozilla/5.0 (Node.js " + nodeVersion + ") MagicMirror/" + global.version + " (https://github.com/MichMich/MagicMirror/)"
|
||||||
"User-Agent": "Mozilla/5.0 (Node.js " + nodeVersion + ") MagicMirror/" + global.version + " (https://github.com/MichMich/MagicMirror/)"
|
|
||||||
},
|
|
||||||
gzip: true
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if (selfSignedCert) {
|
if (selfSignedCert) {
|
||||||
var agentOptions = {
|
httpsAgent = new https.Agent({
|
||||||
rejectUnauthorized: false
|
rejectUnauthorized: false,
|
||||||
};
|
});
|
||||||
opts.agentOptions = agentOptions;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// todo: auth,
|
||||||
|
// https://github.com/devfans/digest-fetch
|
||||||
|
// https://hackersandslackers.com/making-api-requests-with-nodejs/
|
||||||
if (auth) {
|
if (auth) {
|
||||||
if (auth.method === "bearer") {
|
if (auth.method === "bearer") {
|
||||||
opts.auth = {
|
opts.auth = {
|
||||||
@ -73,25 +74,27 @@ const CalendarFetcher = function (url, reloadInterval, excludedEvents, maximumEn
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
request(url, opts, function (err, r, requestData) {
|
fetch(url, { headers: headers, httpsAgent: httpsAgent })
|
||||||
if (err) {
|
.catch(error => {
|
||||||
fetchFailedCallback(self, err);
|
fetchFailedCallback(self, error);
|
||||||
scheduleTimer();
|
scheduleTimer();
|
||||||
return;
|
})
|
||||||
} else if (r.statusCode !== 200) {
|
.then(response => {
|
||||||
fetchFailedCallback(self, r.statusCode + ": " + r.statusMessage);
|
if (response.status !== 200) {
|
||||||
scheduleTimer();
|
throw new Error(response.status + ": " + response.statusText);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
return response;
|
||||||
|
})
|
||||||
|
.then(response => response.text())
|
||||||
|
.then(responseData => {
|
||||||
|
|
||||||
let data = [];
|
let data = [];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
data = ical.parseICS(requestData);
|
data = ical.parseICS(responseData);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
fetchFailedCallback(self, error.message);
|
fetchFailedCallback(self, error.message);
|
||||||
scheduleTimer();
|
scheduleTimer();
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.debug(" parsed data=" + JSON.stringify(data));
|
Log.debug(" parsed data=" + JSON.stringify(data));
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
*/
|
*/
|
||||||
const Log = require("logger");
|
const Log = require("logger");
|
||||||
const FeedMe = require("feedme");
|
const FeedMe = require("feedme");
|
||||||
const request = require("request");
|
const fetch = require("node-fetch");
|
||||||
const iconv = require("iconv-lite");
|
const iconv = require("iconv-lite");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -79,22 +79,21 @@ const NewsfeedFetcher = function (url, reloadInterval, encoding, logFeedWarnings
|
|||||||
});
|
});
|
||||||
|
|
||||||
const nodeVersion = Number(process.version.match(/^v(\d+\.\d+)/)[1]);
|
const nodeVersion = Number(process.version.match(/^v(\d+\.\d+)/)[1]);
|
||||||
const opts = {
|
const headers = {
|
||||||
headers: {
|
"User-Agent": "Mozilla/5.0 (Node.js " + nodeVersion + ") MagicMirror/" + global.version + " (https://github.com/MichMich/MagicMirror/)",
|
||||||
"User-Agent": "Mozilla/5.0 (Node.js " + nodeVersion + ") MagicMirror/" + global.version + " (https://github.com/MichMich/MagicMirror/)",
|
"Cache-Control": "max-age=0, no-cache, no-store, must-revalidate",
|
||||||
"Cache-Control": "max-age=0, no-cache, no-store, must-revalidate",
|
Pragma: "no-cache"
|
||||||
Pragma: "no-cache"
|
|
||||||
},
|
|
||||||
encoding: null
|
|
||||||
};
|
};
|
||||||
|
|
||||||
request(url, opts)
|
fetch(url, { headers: headers })
|
||||||
.on("error", function (error) {
|
.catch(error => {
|
||||||
fetchFailedCallback(self, error);
|
fetchFailedCallback(self, error);
|
||||||
scheduleTimer();
|
scheduleTimer();
|
||||||
})
|
})
|
||||||
.pipe(iconv.decodeStream(encoding))
|
.then(res => {
|
||||||
.pipe(parser);
|
res.body.pipe(iconv.decodeStream(encoding)).pipe(parser);
|
||||||
|
});
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -80,8 +80,8 @@
|
|||||||
"iconv-lite": "^0.6.2",
|
"iconv-lite": "^0.6.2",
|
||||||
"module-alias": "^2.2.2",
|
"module-alias": "^2.2.2",
|
||||||
"moment": "^2.29.1",
|
"moment": "^2.29.1",
|
||||||
|
"node-fetch": "^2.6.1",
|
||||||
"node-ical": "^0.12.7",
|
"node-ical": "^0.12.7",
|
||||||
"request": "^2.88.2",
|
|
||||||
"rrule": "^2.6.6",
|
"rrule": "^2.6.6",
|
||||||
"rrule-alt": "^2.2.8",
|
"rrule-alt": "^2.2.8",
|
||||||
"simple-git": "^2.31.0",
|
"simple-git": "^2.31.0",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user