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);