mirror of
https://github.com/wkulhanek/bonob.git
synced 2025-12-22 01:43:29 +01:00
Move subsonic t and s params into own function
This commit is contained in:
@@ -9,6 +9,14 @@ import randomString from "./random_string";
|
|||||||
export const t = (password: string, s: string) =>
|
export const t = (password: string, s: string) =>
|
||||||
Md5.hashStr(`${password}${s}`);
|
Md5.hashStr(`${password}${s}`);
|
||||||
|
|
||||||
|
export const t_and_s = (password: string) => {
|
||||||
|
const s = randomString();
|
||||||
|
return {
|
||||||
|
t: t(password, s),
|
||||||
|
s,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
export type SubconicEnvelope = {
|
export type SubconicEnvelope = {
|
||||||
"subsonic-response": SubsonicResponse;
|
"subsonic-response": SubsonicResponse;
|
||||||
};
|
};
|
||||||
@@ -43,39 +51,32 @@ export class Navidrome implements MusicService {
|
|||||||
{ username, password }: Credentials,
|
{ username, password }: Credentials,
|
||||||
path: string,
|
path: string,
|
||||||
q: {} = {}
|
q: {} = {}
|
||||||
): Promise<SubsonicResponse> => {
|
): Promise<SubsonicResponse> =>
|
||||||
const s = randomString();
|
axios
|
||||||
return axios
|
|
||||||
.get(`${this.url}${path}`, {
|
.get(`${this.url}${path}`, {
|
||||||
params: {
|
params: {
|
||||||
...q,
|
...q,
|
||||||
u: username,
|
u: username,
|
||||||
t: t(password, s),
|
...t_and_s(password),
|
||||||
s: s,
|
|
||||||
v: "1.16.1",
|
v: "1.16.1",
|
||||||
c: "bonob",
|
c: "bonob",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.then((response) => new X2JS().xml2js(response.data) as SubconicEnvelope)
|
.then((response) => new X2JS().xml2js(response.data) as SubconicEnvelope)
|
||||||
.then((json) => json["subsonic-response"]);
|
.then((json) => json["subsonic-response"])
|
||||||
};
|
|
||||||
|
|
||||||
generateToken = async (credentials: Credentials) => {
|
|
||||||
return this.get(credentials, "/rest/ping.view")
|
|
||||||
.then((json) => {
|
.then((json) => {
|
||||||
if (isError(json)) throw json.error._message;
|
if (isError(json)) throw json.error._message;
|
||||||
else return json;
|
else return json;
|
||||||
})
|
});
|
||||||
.then((_) => {
|
|
||||||
return {
|
generateToken = async (credentials: Credentials) =>
|
||||||
|
this.get(credentials, "/rest/ping.view").then((_) => ({
|
||||||
authToken: Buffer.from(
|
authToken: Buffer.from(
|
||||||
JSON.stringify(this.encryption.encrypt(JSON.stringify(credentials)))
|
JSON.stringify(this.encryption.encrypt(JSON.stringify(credentials)))
|
||||||
).toString("base64"),
|
).toString("base64"),
|
||||||
userId: credentials.username,
|
userId: credentials.username,
|
||||||
nickname: credentials.username,
|
nickname: credentials.username,
|
||||||
};
|
}));
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
parseToken = (token: string): Credentials =>
|
parseToken = (token: string): Credentials =>
|
||||||
JSON.parse(
|
JSON.parse(
|
||||||
|
|||||||
Reference in New Issue
Block a user