mirror of
https://github.com/wkulhanek/bonob.git
synced 2025-12-21 17:33:29 +01:00
basic navidrome implementation
This commit is contained in:
@@ -1,10 +1,3 @@
|
||||
import axios from "axios";
|
||||
import { Md5 } from "ts-md5/dist/md5";
|
||||
|
||||
const s = "foobar100";
|
||||
const navidrome = process.env["BONOB_NAVIDROME_URL"];
|
||||
const u = process.env["BONOB_USER"];
|
||||
const t = Md5.hashStr(`${process.env["BONOB_PASSWORD"]}${s}`);
|
||||
|
||||
export type Credentials = { username: string; password: string };
|
||||
|
||||
@@ -31,8 +24,8 @@ export type AuthFailure = {
|
||||
};
|
||||
|
||||
export interface MusicService {
|
||||
generateToken(credentials: Credentials): AuthSuccess | AuthFailure;
|
||||
login(authToken: string): MusicLibrary | AuthFailure;
|
||||
generateToken(credentials: Credentials): Promise<AuthSuccess | AuthFailure>;
|
||||
login(authToken: string): Promise<MusicLibrary>;
|
||||
}
|
||||
|
||||
export type Artist = {
|
||||
@@ -50,38 +43,3 @@ export interface MusicLibrary {
|
||||
artist(id: string): Artist;
|
||||
albums({ artistId, _index, _count }: { artistId?: string, _index?: number, _count?: number }): Album[];
|
||||
}
|
||||
|
||||
export class Navidrome implements MusicService {
|
||||
generateToken({ username }: Credentials) {
|
||||
return {
|
||||
authToken: `v1:${username}`,
|
||||
userId: username,
|
||||
nickname: username,
|
||||
};
|
||||
}
|
||||
|
||||
login(_: string) {
|
||||
return {
|
||||
artists: () => [],
|
||||
artist: (id: string) => ({
|
||||
id,
|
||||
name: id,
|
||||
}),
|
||||
albums: ({ artistId }: { artistId?: string }) => {
|
||||
console.log(artistId)
|
||||
return []
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
ping = (): Promise<boolean> =>
|
||||
axios
|
||||
.get(
|
||||
`${navidrome}/rest/ping.view?u=${u}&t=${t}&s=${s}&v=1.16.1.0&c=myapp`
|
||||
)
|
||||
.then((_) => true)
|
||||
.catch((e) => {
|
||||
console.log(e);
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user