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) {
|
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('')))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -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(
|
||||||
if (!seen.has(item.url)) {
|
(updatedItems, item) => {
|
||||||
updatedItems.push(item)
|
if (!seen.has(item.url)) {
|
||||||
seen.add(item.url)
|
updatedItems.push(item)
|
||||||
}
|
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
|
||||||
|
|
Loading…
Reference in a new issue