From 7488b7cfeb3bfb604ce3c3bc8c5f2fb455be7cfa Mon Sep 17 00:00:00 2001 From: Neshura Date: Mon, 29 Apr 2024 07:12:43 +0200 Subject: [PATCH] Use opensubsonic types in module and code --- src/lib/opensubsonic.ts | 21 ++++++++++--- src/routes/+page.svelte | 68 +++++++++++++++++++++++------------------ 2 files changed, 54 insertions(+), 35 deletions(-) diff --git a/src/lib/opensubsonic.ts b/src/lib/opensubsonic.ts index d68cca5..a8b2870 100644 --- a/src/lib/opensubsonic.ts +++ b/src/lib/opensubsonic.ts @@ -10,17 +10,28 @@ export module OpenSubsonic { const apiVer = "1.16.1"; // Version supported by Navidrome. Variable for easier updating const clientName = "Lydstyrke"; - export async function get(path: string, parameters: {parameter: string, value: string}[] = []) { + export async function get(path: string, parameters: Array = []) { const apiPath = getApiUrl(path, parameters); const res = (await fetch(apiPath)); if (res.ok) { - switch (res.headers.get("content-type")) { + const contentType =res.headers.get("content-type"); + switch (contentType) { case("application/json"): { return (await res.json())["subsonic-response"]; } case("audio/mp4"): { return res; } + case("image/jpeg"): { + return res; + } + case("image/png"): { + return res; + } + default: { + + console.warn(`Content Type: '${contentType}' is not supported`) + } } } else { @@ -28,10 +39,10 @@ export module OpenSubsonic { } } - export function getApiUrl(path: string, parameters: {parameter: string, value: string}[] = []) { + export function getApiUrl(path: string, parameters: Array = []) { let apiPath = generateBasePath(path); - parameters.forEach(({parameter, value}) => { - apiPath = apiPath + `&${parameter}=${value}`; + parameters.forEach((parameter) => { + apiPath = apiPath + `&${parameter.key}=${parameter.value}`; }) return apiPath; diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index c3f6680..a29be4e 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -1,7 +1,10 @@