Adjust server feature naming convention
This commit is contained in:
parent
a9315be259
commit
a7a5b92011
6 changed files with 14 additions and 12 deletions
|
@ -1,7 +1,9 @@
|
||||||
|
// Should follow a strict naming convention: "<FEATURE GROUP>_<FEATURE NAME>"
|
||||||
|
// For example: <FEATURE GROUP>: "Playlists", <FEATURE NAME>: "Smart" = "PLAYLISTS_SMART"
|
||||||
export enum ServerFeature {
|
export enum ServerFeature {
|
||||||
MULTIPLE_STRUCTURED_LYRICS = 'multipleStructuredLyrics',
|
LYRICS_MULTIPLE_STRUCTURED = 'lyricsMultipleStructured',
|
||||||
SINGLE_STRUCTURED_LYRIC = 'singleStructuredLyric',
|
LYRICS_SINGLE_STRUCTURED = 'lyricsSingleStructured',
|
||||||
SMART_PLAYLISTS = 'smartPlaylists',
|
PLAYLISTS_SMART = 'playlistsSmart',
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ServerFeatures = Partial<Record<ServerFeature, boolean>>;
|
export type ServerFeatures = Partial<Record<ServerFeature, boolean>>;
|
||||||
|
|
|
@ -961,7 +961,7 @@ const getServerInfo = async (args: ServerInfoArgs): Promise<ServerInfo> => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const features: ServerFeatures = {
|
const features: ServerFeatures = {
|
||||||
singleStructuredLyric: true,
|
lyricsSingleStructured: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -368,7 +368,7 @@ const getPlaylistList = async (args: PlaylistListArgs): Promise<PlaylistListResp
|
||||||
if (
|
if (
|
||||||
customQuery &&
|
customQuery &&
|
||||||
customQuery.smart !== undefined &&
|
customQuery.smart !== undefined &&
|
||||||
!hasFeature(apiClientProps.server, ServerFeature.SMART_PLAYLISTS)
|
!hasFeature(apiClientProps.server, ServerFeature.PLAYLISTS_SMART)
|
||||||
) {
|
) {
|
||||||
customQuery.smart = undefined;
|
customQuery.smart = undefined;
|
||||||
}
|
}
|
||||||
|
@ -483,7 +483,7 @@ const removeFromPlaylist = async (
|
||||||
};
|
};
|
||||||
|
|
||||||
const VERSION_INFO: Array<[string, Record<string, number[]>]> = [
|
const VERSION_INFO: Array<[string, Record<string, number[]>]> = [
|
||||||
['0.48.0', { [ServerFeature.SMART_PLAYLISTS]: [1] }],
|
['0.48.0', { [ServerFeature.PLAYLISTS_SMART]: [1] }],
|
||||||
];
|
];
|
||||||
|
|
||||||
const getFeatures = (version: string): Record<string, number[]> => {
|
const getFeatures = (version: string): Record<string, number[]> => {
|
||||||
|
@ -540,8 +540,8 @@ const getServerInfo = async (args: ServerInfoArgs): Promise<ServerInfo> => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const features: ServerFeatures = {
|
const features: ServerFeatures = {
|
||||||
multipleStructuredLyrics: !!navidromeFeatures[SubsonicExtensions.SONG_LYRICS],
|
lyricsMultipleStructured: !!navidromeFeatures[SubsonicExtensions.SONG_LYRICS],
|
||||||
smartPlaylists: !!navidromeFeatures[NavidromeExtensions.SMART_PLAYLISTS],
|
playlistsSmart: !!navidromeFeatures[NavidromeExtensions.SMART_PLAYLISTS],
|
||||||
};
|
};
|
||||||
|
|
||||||
return { features, id: apiClientProps.server?.id, version: ping.body.serverVersion! };
|
return { features, id: apiClientProps.server?.id, version: ping.body.serverVersion! };
|
||||||
|
|
|
@ -404,7 +404,7 @@ const getServerInfo = async (args: ServerInfoArgs): Promise<ServerInfo> => {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (subsonicFeatures[SubsonicExtensions.SONG_LYRICS]) {
|
if (subsonicFeatures[SubsonicExtensions.SONG_LYRICS]) {
|
||||||
features.multipleStructuredLyrics = true;
|
features.lyricsMultipleStructured = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return { features, id: apiClientProps.server?.id, version: ping.body.serverVersion };
|
return { features, id: apiClientProps.server?.id, version: ping.body.serverVersion };
|
||||||
|
|
|
@ -96,7 +96,7 @@ export const useSongLyricsBySong = (
|
||||||
if (!server) throw new Error('Server not found');
|
if (!server) throw new Error('Server not found');
|
||||||
if (!song) return null;
|
if (!song) return null;
|
||||||
|
|
||||||
if (hasFeature(server, ServerFeature.MULTIPLE_STRUCTURED_LYRICS)) {
|
if (hasFeature(server, ServerFeature.LYRICS_MULTIPLE_STRUCTURED)) {
|
||||||
const subsonicLyrics = await api.controller
|
const subsonicLyrics = await api.controller
|
||||||
.getStructuredLyrics({
|
.getStructuredLyrics({
|
||||||
apiClientProps: { server, signal },
|
apiClientProps: { server, signal },
|
||||||
|
@ -107,7 +107,7 @@ export const useSongLyricsBySong = (
|
||||||
if (subsonicLyrics) {
|
if (subsonicLyrics) {
|
||||||
return subsonicLyrics;
|
return subsonicLyrics;
|
||||||
}
|
}
|
||||||
} else if (hasFeature(server, ServerFeature.SINGLE_STRUCTURED_LYRIC)) {
|
} else if (hasFeature(server, ServerFeature.LYRICS_SINGLE_STRUCTURED)) {
|
||||||
const jfLyrics = await api.controller
|
const jfLyrics = await api.controller
|
||||||
.getLyrics({
|
.getLyrics({
|
||||||
apiClientProps: { server, signal },
|
apiClientProps: { server, signal },
|
||||||
|
|
|
@ -123,7 +123,7 @@ export const CreatePlaylistForm = ({ onCancel }: CreatePlaylistFormProps) => {
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{server?.type === ServerType.NAVIDROME &&
|
{server?.type === ServerType.NAVIDROME &&
|
||||||
hasFeature(server, ServerFeature.SMART_PLAYLISTS) && (
|
hasFeature(server, ServerFeature.PLAYLISTS_SMART) && (
|
||||||
<Switch
|
<Switch
|
||||||
label="Is smart playlist?"
|
label="Is smart playlist?"
|
||||||
onChange={(e) => setIsSmartPlaylist(e.currentTarget.checked)}
|
onChange={(e) => setIsSmartPlaylist(e.currentTarget.checked)}
|
||||||
|
|
Reference in a new issue