fix: audio label

This commit is contained in:
RockinChaos 2024-06-01 19:49:37 -07:00
parent ccb3225873
commit ceb2eb6a06
3 changed files with 11 additions and 17 deletions

View file

@ -6,6 +6,8 @@ import { alToken } from '@/modules/settings.js'
import { toast } from 'svelte-sonner'
import { sleep } from './util.js'
import { cacheDubs } from '@/modules/audiolabel.js'
export const codes = {
400: 'Bad Request',
401: 'Unauthorized',
@ -206,6 +208,8 @@ class AnilistClient {
return time
})
cacheDubs()
if (this.userID?.viewer?.data?.Viewer) {
this.userLists.value = this.getUserLists({ sort: 'UPDATED_TIME_DESC' })
// update userLists every 15 mins

View file

@ -4,18 +4,10 @@ import { codes } from '@/modules/anilist.js'
export const dubInfo = writable()
const initialized = writable(false)
export async function cacheDubs() {
await initialized.subscribe(async value => {
if (!value) {
dubInfo.value = await getDubInfo()
initialized.set(true)
// update dubInfo every hour
setInterval(async () => dubInfo.value = await getDubInfo(), 1000 * 60 * 60)
}
})
dubInfo.value = await getDubInfo()
// update dubInfo every hour
setInterval(async () => dubInfo.value = await getDubInfo(), 1000 * 60 * 60)
}
async function getDubInfo() {

View file

@ -1,7 +1,6 @@
<script>
import { onMount } from 'svelte'
import { settings } from '@/modules/settings.js'
import { cacheDubs } from '@/modules/audiolabel.js'
import { dubInfo } from '@/modules/audiolabel.js'
/** @type {import('@/modules/al.d.ts').Media} */
@ -17,18 +16,17 @@
/**
* @param {number} id
*/
async function setLabel(id) {
const info = await dubInfo
function setLabel(id) {
const info = dubInfo
if (info && info.value) {
isDubbed = info.value.dubbed.includes(id)
isPartial = info.value.incomplete.includes(id)
}
}
onMount(async () => {
await cacheDubs()
onMount(() => {
if (media != null) {
await setLabel(media.idMal)
setLabel(media.idMal)
}
})
</script>