fix: chunked responses (#19)

* fix: chunked response support in proxy

* fix: feed merging
This commit is contained in:
Marc Cataford 2021-08-02 11:42:45 -04:00 committed by GitHub
parent a849cdbc34
commit 13773e1d38
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 10 deletions

View file

@ -3,7 +3,9 @@ const https = require('https')
async function httpGet(url) { async function httpGet(url) {
return new Promise((resolve) => { return new Promise((resolve) => {
https.get(url, (response) => { https.get(url, (response) => {
response.on('data', (d) => resolve(d)) const chunks = []
response.on('data', (d) => chunks.push(d))
response.on('end', () => resolve(chunks.join('')))
}) })
}) })
} }

View file

@ -28,15 +28,18 @@ function getRefetchThreshold() {
function mergeFeeds(first, second) { function mergeFeeds(first, second) {
// Assuming `second` is newer. // Assuming `second` is newer.
const seen = new Set(items.map((item) => item.url)) const seen = new Set(first.items.map((item) => item.url))
const mergedItems = newFeedItems.reduce((updatedItems, item) => { const mergedItems = second.items.reduce(
(updatedItems, item) => {
if (!seen.has(item.url)) { if (!seen.has(item.url)) {
updatedItems.push(item) updatedItems.push(item)
seen.add(item.url) seen.add(item.url)
} }
return updatedItems return updatedItems
}, []) },
[...first.items],
)
return { return {
...second, ...second,
items: mergedItems, items: mergedItems,
@ -83,7 +86,7 @@ export default async function fetchFeeds(
return mergedFeeds return mergedFeeds
} catch (e) { } catch (e) {
// eslint-disable-next-line no-console // eslint-disable-next-line no-console
console.error(e.response) console.error(e)
} }
return storedFeedData return storedFeedData