From 0218c2ca4301c508b9efaebcc15762c89838ac0e Mon Sep 17 00:00:00 2001 From: Shiny Nematoda Date: Fri, 7 Apr 2023 16:24:11 +0000 Subject: [PATCH] Minor fixes - Avoid queue when fetching lyrics id - Better error handling for logout --- src/components/Lyrics.vue | 10 +++++----- src/components/Prefs.vue | 4 +++- src/scripts/fetch.js | 10 ++++++++-- src/scripts/xml.js | 2 +- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/components/Lyrics.vue b/src/components/Lyrics.vue index b7a9a61..271357c 100644 --- a/src/components/Lyrics.vue +++ b/src/components/Lyrics.vue @@ -27,11 +27,11 @@ function get() { if (data.state.lyrics && data.state.urls === data.state.url) { set(data.state.lyrics); } else if (data.state.url) { - getJsonHyp('/next/' + data.state.url.replace('/watch?v=', '')).then( - ({ lyricsId }) => { - if (lyricsId) set(lyricsId); - }, - ); + getJsonHyp( + '/next/' + data.state.url.replace('/watch?v=', '') + '?queue=avoid', + ).then(({ lyricsId }) => { + if (lyricsId) set(lyricsId); + }); } } diff --git a/src/components/Prefs.vue b/src/components/Prefs.vue index 082f8cc..45fa68c 100644 --- a/src/components/Prefs.vue +++ b/src/components/Prefs.vue @@ -80,7 +80,9 @@ async function setAuth(key) { const res = await useAuthLogout(); - if (res?.error) if (!confirm(`Got Error: ${res.error}. Continue?`)) return; + if (!res && res?.error) + if (!confirm(`Got Error ${res ? ': ' + res.error : ''}. Continue?`)) + return; } store.removeItem('auth'); diff --git a/src/scripts/fetch.js b/src/scripts/fetch.js index 2149b9c..901c834 100644 --- a/src/scripts/fetch.js +++ b/src/scripts/fetch.js @@ -108,13 +108,19 @@ export async function useAuthAddToPlaylist(id, path) { } export async function useAuthLogout() { - const auth = useAuthToken(); + const auth = useAuthToken(), + ctrl = new AbortController(), + id = setTimeout(() => ctrl.abort(), 1000); if (auth) return await getJsonAuth('/logout', { method: 'POST', + signal: ctrl.signal, headers: { - Authorization: store.auth, + Authorization: auth, }, + }).then(res => { + clearTimeout(id); + return res; }); } diff --git a/src/scripts/xml.js b/src/scripts/xml.js index 8c4eb84..5719bb0 100644 --- a/src/scripts/xml.js +++ b/src/scripts/xml.js @@ -53,7 +53,7 @@ export function useXML(json) { base += ''; - + base += useElems(json.elements); return base;