Merge pull request #2857 from khassel/fetch

This commit is contained in:
Michael Teeuw 2022-06-04 14:14:52 +02:00 committed by GitHub
commit c0743ce9de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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);