fix newsfeedfetcher using correct stream version (changed with node-18-fetch)

This commit is contained in:
Karsten Hassel 2022-05-28 22:28:37 +02:00
parent 4f1db749c0
commit 591f907134
2 changed files with 9 additions and 2 deletions

View File

@ -19,7 +19,7 @@ _This release is scheduled to be released on 2022-07-01._
- Use latest node 18 when running tests on github actions
- Update `electron` to v19 and other dependencies.
- Use internal fetch function of node instead external `node-fetch` library if node version >= `v18`.
- Use internal fetch function of node instead external `node-fetch` library if used node version >= `v18`.
### Fixed

View File

@ -9,6 +9,7 @@ const FeedMe = require("feedme");
const NodeHelper = require("node_helper");
const fetch = require("fetch");
const iconv = require("iconv-lite");
const stream = require("stream");
/**
* Responsible for requesting an update on the set interval and broadcasting the data.
@ -87,7 +88,13 @@ const NewsfeedFetcher = function (url, reloadInterval, encoding, logFeedWarnings
fetch(url, { headers: headers })
.then(NodeHelper.checkFetchStatus)
.then((response) => {
response.body.pipe(iconv.decodeStream(encoding)).pipe(parser);
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);