fix: chunked responses (#19)
* fix: chunked response support in proxy * fix: feed merging
This commit is contained in:
parent
a849cdbc34
commit
13773e1d38
2 changed files with 15 additions and 10 deletions
|
@ -3,7 +3,9 @@ const https = require('https')
|
|||
async function httpGet(url) {
|
||||
return new Promise((resolve) => {
|
||||
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('')))
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
|
@ -28,15 +28,18 @@ function getRefetchThreshold() {
|
|||
|
||||
function mergeFeeds(first, second) {
|
||||
// Assuming `second` is newer.
|
||||
const seen = new Set(items.map((item) => item.url))
|
||||
const mergedItems = newFeedItems.reduce((updatedItems, item) => {
|
||||
if (!seen.has(item.url)) {
|
||||
updatedItems.push(item)
|
||||
seen.add(item.url)
|
||||
}
|
||||
const seen = new Set(first.items.map((item) => item.url))
|
||||
const mergedItems = second.items.reduce(
|
||||
(updatedItems, item) => {
|
||||
if (!seen.has(item.url)) {
|
||||
updatedItems.push(item)
|
||||
seen.add(item.url)
|
||||
}
|
||||
|
||||
return updatedItems
|
||||
}, [])
|
||||
return updatedItems
|
||||
},
|
||||
[...first.items],
|
||||
)
|
||||
return {
|
||||
...second,
|
||||
items: mergedItems,
|
||||
|
@ -83,7 +86,7 @@ export default async function fetchFeeds(
|
|||
return mergedFeeds
|
||||
} catch (e) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.error(e.response)
|
||||
console.error(e)
|
||||
}
|
||||
|
||||
return storedFeedData
|
||||
|
|
Loading…
Reference in a new issue