From 28c9f7686a181f525f4866b5bc428649e3683dfc Mon Sep 17 00:00:00 2001 From: Shiny Nematoda Date: Mon, 25 Nov 2024 14:19:49 +0000 Subject: [PATCH] feat: support custom endpoint for stream extraction --- src/App.vue | 8 +------- src/assets/version.json | 2 +- src/components/Prefs.vue | 17 ++++++++++++++++- src/scripts/fetch.js | 4 ++-- src/stores/player.js | 2 +- 5 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/App.vue b/src/App.vue index 43d94dd..72f1e26 100644 --- a/src/App.vue +++ b/src/App.vue @@ -82,16 +82,10 @@ function parseUrl() { if (loc[2].startsWith('MPRE')) results.getAlbum('?list=' + loc[2]); break; case 'charts': - nav.state.page = 'charts'; - break; case 'library': - nav.state.page = 'library'; - break; case 'prefs': - nav.state.page = 'prefs'; - break; case 'restore': - nav.state.page = 'restore'; + nav.state.page = base; break; default: console.log(loc); diff --git a/src/assets/version.json b/src/assets/version.json index a6e24cf..e17c0b0 100644 --- a/src/assets/version.json +++ b/src/assets/version.json @@ -1,3 +1,3 @@ { - "date": "2024-07-22" + "date": "2024-11-25" } diff --git a/src/components/Prefs.vue b/src/components/Prefs.vue index 2bde47c..a078af5 100644 --- a/src/components/Prefs.vue +++ b/src/components/Prefs.vue @@ -118,6 +118,11 @@ async function setAuth(e) { setCustom('authapi', e); } +function setStreamApi(e) { + if (e.target.value) store.setItem('streamapi', e.target.value) + else store.removeItem('streamapi'); +} + const verifyApi = computed(() => hypInstances.value .map(i => i.api_url.replace('https://', '').replace('http://', '')) @@ -407,6 +412,15 @@ onMounted(() => { +

{{ t('instances.streamapi') }}

+ +
@@ -470,7 +484,8 @@ h2, h3, label, footer, -.restore { +.restore, +.input { text-align: center; word-break: break-word; } diff --git a/src/scripts/fetch.js b/src/scripts/fetch.js index 5d7b22e..f4b1377 100644 --- a/src/scripts/fetch.js +++ b/src/scripts/fetch.js @@ -38,8 +38,8 @@ export async function getJson(url, opts) { return res; } -export async function getJsonPiped(path, opts) { - const root = +export async function getJsonPiped(path, opts, root) { + root ??= new URLSearchParams(location.search).get('pipedapi') || useStore().getItem('pipedapi') || PIPED_INSTANCE; diff --git a/src/stores/player.js b/src/stores/player.js index a616ec1..93b1dcc 100644 --- a/src/stores/player.js +++ b/src/stores/player.js @@ -22,7 +22,7 @@ export const useData = defineStore('data', () => { async function getSong(e) { const hash = new URLSearchParams(e.substring(e.indexOf('?'))).get('v'), - json = await getJsonPiped('/streams/' + hash), + json = await getJsonPiped('/streams/' + hash, {}, store.getItem('streamapi')), unamp = txt => txt?.replace(AMP, '&'); state.art = unamp(json.thumbnailUrl);