mirror of
https://github.com/wkulhanek/bonob.git
synced 2025-12-21 17:33:29 +01:00
Represent each subsonic api call as a method on Navidrome
This commit is contained in:
@@ -142,7 +142,17 @@ export class Navidrome implements MusicService {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
artistInfo = (credentials: Credentials, id: string): Promise<ArtistInfo> =>
|
getArtists = (credentials: Credentials): Promise<IdName[]> =>
|
||||||
|
this.get<GetArtistsResponse>(credentials, "/rest/getArtists")
|
||||||
|
.then((it) => it.artists.index.flatMap((it) => it.artist || []))
|
||||||
|
.then((artists) =>
|
||||||
|
artists.map((artist) => ({
|
||||||
|
id: artist._id,
|
||||||
|
name: artist._name,
|
||||||
|
}))
|
||||||
|
);
|
||||||
|
|
||||||
|
getArtistInfo = (credentials: Credentials, id: string): Promise<ArtistInfo> =>
|
||||||
this.get<GetArtistInfoResponse>(credentials, "/rest/getArtistInfo", {
|
this.get<GetArtistInfoResponse>(credentials, "/rest/getArtistInfo", {
|
||||||
id,
|
id,
|
||||||
}).then((it) => ({
|
}).then((it) => ({
|
||||||
@@ -153,6 +163,11 @@ export class Navidrome implements MusicService {
|
|||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
getArtist = (credentials: Credentials, id: string): Promise<IdName> =>
|
||||||
|
this.get<GetArtistResponse>(credentials, "/rest/getArtist", {
|
||||||
|
id,
|
||||||
|
}).then((it) => ({ id: it.artist._id, name: it.artist._name }));
|
||||||
|
|
||||||
async login(token: string) {
|
async login(token: string) {
|
||||||
const navidrome = this;
|
const navidrome = this;
|
||||||
const credentials: Credentials = this.parseToken(token);
|
const credentials: Credentials = this.parseToken(token);
|
||||||
@@ -160,27 +175,22 @@ export class Navidrome implements MusicService {
|
|||||||
const musicLibrary: MusicLibrary = {
|
const musicLibrary: MusicLibrary = {
|
||||||
artists: (q: ArtistQuery): Promise<Result<ArtistSummary>> =>
|
artists: (q: ArtistQuery): Promise<Result<ArtistSummary>> =>
|
||||||
navidrome
|
navidrome
|
||||||
.get<GetArtistsResponse>(credentials, "/rest/getArtists")
|
.getArtists(credentials)
|
||||||
.then((it) => it.artists.index.flatMap((it) => it.artist || []))
|
|
||||||
.then((artists) =>
|
|
||||||
artists.map((artist) => ({
|
|
||||||
id: artist._id,
|
|
||||||
name: artist._name,
|
|
||||||
}))
|
|
||||||
)
|
|
||||||
.then(slice2(q))
|
.then(slice2(q))
|
||||||
.then(asResult)
|
.then(asResult)
|
||||||
.then((result) =>
|
.then((result) =>
|
||||||
Promise.all(
|
Promise.all(
|
||||||
result.results.map((idName: IdName) =>
|
result.results.map((idName: IdName) =>
|
||||||
navidrome.artistInfo(credentials, idName.id).then((artist) => ({
|
navidrome
|
||||||
total: result.total,
|
.getArtistInfo(credentials, idName.id)
|
||||||
result: {
|
.then((artistInfo) => ({
|
||||||
id: idName.id,
|
total: result.total,
|
||||||
name: idName.name,
|
result: {
|
||||||
image: artist.image,
|
id: idName.id,
|
||||||
},
|
name: idName.name,
|
||||||
}))
|
image: artistInfo.image,
|
||||||
|
},
|
||||||
|
}))
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@@ -190,27 +200,15 @@ export class Navidrome implements MusicService {
|
|||||||
results: resultWithInfo.map((it) => it.result),
|
results: resultWithInfo.map((it) => it.result),
|
||||||
};
|
};
|
||||||
}),
|
}),
|
||||||
artist: async (id: string): Promise<Artist> => {
|
artist: async (id: string): Promise<Artist> =>
|
||||||
return navidrome
|
Promise.all([
|
||||||
.get<GetArtistResponse>(credentials, "/rest/getArtist", {
|
navidrome.getArtist(credentials, id),
|
||||||
id,
|
navidrome.getArtistInfo(credentials, id),
|
||||||
})
|
]).then(([artist, artistInfo]) => ({
|
||||||
.then(async (artist: GetArtistResponse) => {
|
id: artist.id,
|
||||||
return navidrome
|
name: artist.name,
|
||||||
.get<GetArtistInfoResponse>(credentials, "/rest/getArtistInfo", {
|
image: artistInfo.image,
|
||||||
id,
|
})),
|
||||||
})
|
|
||||||
.then((artistInfo: GetArtistInfoResponse) => ({
|
|
||||||
id: artist.artist._id,
|
|
||||||
name: artist.artist._name,
|
|
||||||
image: {
|
|
||||||
small: artistInfo.artistInfo.smallImageUrl,
|
|
||||||
medium: artistInfo.artistInfo.mediumImageUrl,
|
|
||||||
large: artistInfo.artistInfo.largeImageUrl,
|
|
||||||
},
|
|
||||||
}));
|
|
||||||
});
|
|
||||||
},
|
|
||||||
albums: (_: AlbumQuery): Promise<Result<Album>> => {
|
albums: (_: AlbumQuery): Promise<Result<Album>> => {
|
||||||
return Promise.resolve({ results: [], total: 0 });
|
return Promise.resolve({ results: [], total: 0 });
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user