Add unique session identifier to OpenSubsonic for improved behaviour with getNowPlaying

This commit is contained in:
Neshura 2024-04-30 02:25:15 +02:00
parent ff396e8ca2
commit 65f0e6776e
Signed by: Neshura
GPG key ID: B6983AAA6B9A7A6C

View file

@ -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<Parameter> = []) {
const apiPath = getApiUrl(path, parameters);