basic navidrome implementation

This commit is contained in:
simojenki
2021-03-01 17:28:48 +11:00
parent 3b350c4402
commit 007db24713
17 changed files with 305 additions and 105 deletions

View File

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