From 65f0e6776e253c70019767979fb56a5e098d2419 Mon Sep 17 00:00:00 2001 From: Neshura Date: Tue, 30 Apr 2024 02:25:15 +0200 Subject: [PATCH] Add unique session identifier to OpenSubsonic for improved behaviour with getNowPlaying --- src/lib/opensubsonic.ts | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/lib/opensubsonic.ts b/src/lib/opensubsonic.ts index a8b2870..edadff8 100644 --- a/src/lib/opensubsonic.ts +++ b/src/lib/opensubsonic.ts @@ -1,14 +1,28 @@ import {Md5} from "ts-md5"; import Cookies from 'js-cookie'; +function getIdent(): string { + let cookie = Cookies.get("subsonicPlayerIdent"); + if (typeof cookie === "undefined") { + cookie = Math.random().toString(36).slice(2); + } + const options = { + expires: 7, + path: "/", + sameSite: "strict", + }; + Cookies.set("subsonicPlayerIdent", cookie, options); + return cookie; +} + export module OpenSubsonic { - export let username = ""; - export let password = ""; - let token = ""; - let salt = ""; + export let username: string = ""; + export let password: string = ""; + let token: string = ""; + let salt: string = ""; export let base = "https://music.neshweb.net"; const apiVer = "1.16.1"; // Version supported by Navidrome. Variable for easier updating - const clientName = "Lydstyrke"; + export const clientName = "Lydstyrke-" + getIdent(); export async function get(path: string, parameters: Array = []) { const apiPath = getApiUrl(path, parameters);