Replace dependencies where possible (#14)
* refactor: remove axios, use fetch * refactor: remove md5 * fix: handle failed fetches
This commit is contained in:
parent
185f405fe2
commit
5c3da0a2f4
4 changed files with 17 additions and 50 deletions
|
@ -40,9 +40,7 @@
|
|||
"dependencies": {
|
||||
"@material-ui/core": "^4.12.1",
|
||||
"@material-ui/icons": "^4.11.2",
|
||||
"axios": "^0.21.1",
|
||||
"htmlparser2": "^6.1.0",
|
||||
"md5": "^2.3.0",
|
||||
"react": "^17.0.2",
|
||||
"react-dom": "^17.0.2"
|
||||
}
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
import axios from 'axios'
|
||||
import { parseFeed } from 'htmlparser2'
|
||||
|
||||
import type { Feed } from '../types'
|
||||
|
@ -65,12 +64,16 @@ export default async function fetchFeeds(
|
|||
if (!forceRefetch && lastPull > getRefetchThreshold())
|
||||
return storedFeedData
|
||||
|
||||
const response = await axios.get('/.netlify/functions/rss-proxy', {
|
||||
params: { url },
|
||||
})
|
||||
const response = await fetch(
|
||||
`/.netlify/functions/rss-proxy?url=${url}`,
|
||||
)
|
||||
|
||||
if (!response.ok) return storedFeedData
|
||||
|
||||
const responseData = await response.text()
|
||||
|
||||
try {
|
||||
const newFeedData = parseFeed(response.data)
|
||||
const newFeedData = parseFeed(responseData)
|
||||
const newFeed = processFeedXML(newFeedData)
|
||||
const mergedFeeds = storedFeedData
|
||||
? mergeFeeds(storedFeedData, newFeed)
|
||||
|
@ -87,5 +90,5 @@ export default async function fetchFeeds(
|
|||
}),
|
||||
)
|
||||
|
||||
return feeds
|
||||
return feeds.filter((feed) => feed)
|
||||
}
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
import md5 from 'md5'
|
||||
|
||||
import type { RSSData, Settings } from '../types'
|
||||
|
||||
const SETTINGS_KEY = 'settings'
|
||||
const RSS_DATA_KEY_PREFIX = 'savedItems_'
|
||||
|
||||
function cacheKeyFromURL(url: string): string {
|
||||
return url.replace(/^https?:\/\//, '').replace(/\/$/, '')
|
||||
}
|
||||
|
||||
function storeToLocal(key: string, data): void {
|
||||
window.localStorage.setItem(key, JSON.stringify(data))
|
||||
}
|
||||
|
@ -26,11 +28,11 @@ export function restoreSettings(): Settings {
|
|||
}
|
||||
|
||||
export function storeRssData(url: string, items: Item[]): void {
|
||||
const key = RSS_DATA_KEY_PREFIX + md5(url)
|
||||
const key = RSS_DATA_KEY_PREFIX + cacheKeyFromURL(url)
|
||||
storeToLocal(key, items)
|
||||
}
|
||||
|
||||
export function restoreRssData(url: string): RSSData {
|
||||
const key = RSS_DATA_KEY_PREFIX + md5(url)
|
||||
const key = RSS_DATA_KEY_PREFIX + cacheKeyFromURL(url)
|
||||
return restoreFromLocal(key)
|
||||
}
|
||||
|
|
40
yarn.lock
40
yarn.lock
|
@ -4793,15 +4793,6 @@ __metadata:
|
|||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"axios@npm:^0.21.1":
|
||||
version: 0.21.1
|
||||
resolution: "axios@npm:0.21.1"
|
||||
dependencies:
|
||||
follow-redirects: ^1.10.0
|
||||
checksum: c87915fa0b18c15c63350112b6b3563a3e2ae524d7707de0a73d2e065e0d30c5d3da8563037bc29d4cc1b7424b5a350cb7274fa52525c6c04a615fe561c6ab11
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"axobject-query@npm:^2.2.0":
|
||||
version: 2.2.0
|
||||
resolution: "axobject-query@npm:2.2.0"
|
||||
|
@ -5626,13 +5617,6 @@ __metadata:
|
|||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"charenc@npm:0.0.2":
|
||||
version: 0.0.2
|
||||
resolution: "charenc@npm:0.0.2"
|
||||
checksum: 81dcadbe57e861d527faf6dd3855dc857395a1c4d6781f4847288ab23cffb7b3ee80d57c15bba7252ffe3e5e8019db767757ee7975663ad2ca0939bb8fcaf2e5
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"chokidar@npm:^3.0.2":
|
||||
version: 3.5.2
|
||||
resolution: "chokidar@npm:3.5.2"
|
||||
|
@ -6429,13 +6413,6 @@ __metadata:
|
|||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"crypt@npm:0.0.2":
|
||||
version: 0.0.2
|
||||
resolution: "crypt@npm:0.0.2"
|
||||
checksum: baf4c7bbe05df656ec230018af8cf7dbe8c14b36b98726939cef008d473f6fe7a4fad906cfea4062c93af516f1550a3f43ceb4d6615329612c6511378ed9fe34
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"crypto-browserify@npm:^3.12.0":
|
||||
version: 3.12.0
|
||||
resolution: "crypto-browserify@npm:3.12.0"
|
||||
|
@ -8668,7 +8645,7 @@ __metadata:
|
|||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"follow-redirects@npm:^1.0.0, follow-redirects@npm:^1.10.0":
|
||||
"follow-redirects@npm:^1.0.0":
|
||||
version: 1.14.1
|
||||
resolution: "follow-redirects@npm:1.14.1"
|
||||
peerDependenciesMeta:
|
||||
|
@ -10067,7 +10044,7 @@ __metadata:
|
|||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"is-buffer@npm:^1.1.5, is-buffer@npm:~1.1.6":
|
||||
"is-buffer@npm:^1.1.5":
|
||||
version: 1.1.6
|
||||
resolution: "is-buffer@npm:1.1.6"
|
||||
checksum: 4a186d995d8bbf9153b4bd9ff9fd04ae75068fe695d29025d25e592d9488911eeece84eefbd8fa41b8ddcc0711058a71d4c466dcf6f1f6e1d83830052d8ca707
|
||||
|
@ -12317,17 +12294,6 @@ __metadata:
|
|||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"md5@npm:^2.3.0":
|
||||
version: 2.3.0
|
||||
resolution: "md5@npm:2.3.0"
|
||||
dependencies:
|
||||
charenc: 0.0.2
|
||||
crypt: 0.0.2
|
||||
is-buffer: ~1.1.6
|
||||
checksum: a63cacf4018dc9dee08c36e6f924a64ced735b37826116c905717c41cebeb41a522f7a526ba6ad578f9c80f02cb365033ccd67fe186ffbcc1a1faeb75daa9b6e
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"mdn-data@npm:2.0.14":
|
||||
version: 2.0.14
|
||||
resolution: "mdn-data@npm:2.0.14"
|
||||
|
@ -15776,7 +15742,6 @@ __metadata:
|
|||
"@tophat/eslint-import-resolver-require": ^0.1.3
|
||||
"@typescript-eslint/eslint-plugin": ^4.28.3
|
||||
"@typescript-eslint/parser": ^4.28.3
|
||||
axios: ^0.21.1
|
||||
eslint: ^7.30.0
|
||||
eslint-config-prettier: ^8.3.0
|
||||
eslint-import-resolver-node: ^0.3.4
|
||||
|
@ -15789,7 +15754,6 @@ __metadata:
|
|||
eslint-plugin-react-hooks: ^4.2.0
|
||||
htmlparser2: ^6.1.0
|
||||
jest: ^27.0.6
|
||||
md5: ^2.3.0
|
||||
netlify-cli: ^5.2.3
|
||||
parcel: ^2.0.0-beta.2
|
||||
prettier: ^2.3.2
|
||||
|
|
Loading…
Reference in a new issue