feat(directory): proper cache handling

This commit is contained in:
Haoyu Xu
2023-02-28 17:34:37 -05:00
parent e4648945d1
commit 3cc0f48648
7 changed files with 95 additions and 34 deletions

View File

@@ -87,15 +87,15 @@ export default function Home() {
const loadVoice = (link) => {
if (!voiceOn) return
db.voice.get({ key: link }).then((v) => {
if (v === undefined) {
if (v) {
playVoice(v.blob)
} else {
fetch(`/${link}/assets/voice/${import.meta.env.VITE_APP_VOICE_URL}`)
.then(res => res.blob())
.then(blob => {
db.voice.put({ key: link, blob: blob })
playVoice(blob)
})
} else {
playVoice(v.blob)
}
})
}
@@ -162,15 +162,15 @@ function ImageElement({ item, language }) {
useEffect(() => {
db.image.get({ key: item.link }).then((v) => {
if (v === undefined) {
if (v) {
setBlobUrl(URL.createObjectURL(v.blob))
} else {
fetch(`/${item.link}/assets/${item.fallback_name.replace("#", "%23")}_portrait.png`)
.then(res => res.blob())
.then(blob => {
db.image.put({ key: item.link, blob: blob })
setBlobUrl(URL.createObjectURL(blob))
})
} else {
setBlobUrl(URL.createObjectURL(v.blob))
}
})
}, [item.link])