fix jellyfin playlists, add is public

This commit is contained in:
Kendall Garner 2024-09-01 09:37:37 -07:00
parent 528bef01f0
commit 93377dcc4f
No known key found for this signature in database
GPG key ID: 18D2767419676C87
11 changed files with 81 additions and 51 deletions

View file

@ -249,6 +249,8 @@
"title": "delete $t(entity.playlist_one)"
},
"editPlaylist": {
"publicJellyfinNote": "Jellyfin for some reason does not expose whether a playlist is public or not. If you wish for this to remain public, please have the following input selected",
"success": "$t(entity.playlist_one) updated successfully",
"title": "edit $t(entity.playlist_one)"
},
"lyricSearch": {

View file

@ -4,6 +4,7 @@ export enum ServerFeature {
LYRICS_MULTIPLE_STRUCTURED = 'lyricsMultipleStructured',
LYRICS_SINGLE_STRUCTURED = 'lyricsSingleStructured',
PLAYLISTS_SMART = 'playlistsSmart',
PUBLIC_PLAYLIST = 'publicPlaylist',
SHARING_ALBUM_SONG = 'sharingAlbumSong',
}

View file

@ -292,8 +292,8 @@ export const contract = c.router({
},
updatePlaylist: {
body: jfType._parameters.updatePlaylist,
method: 'PUT',
path: 'items/:id',
method: 'POST',
path: 'playlists/:id',
responses: {
200: jfType._response.updatePlaylist,
400: jfType._response.error,

View file

@ -607,9 +607,9 @@ const createPlaylist = async (args: CreatePlaylistArgs): Promise<CreatePlaylistR
const res = await jfApiClient(apiClientProps).createPlaylist({
body: {
IsPublic: body.public,
MediaType: 'Audio',
Name: body.name,
Overview: body.comment || '',
UserId: apiClientProps.server.userId,
},
});
@ -633,9 +633,9 @@ const updatePlaylist = async (args: UpdatePlaylistArgs): Promise<UpdatePlaylistR
const res = await jfApiClient(apiClientProps).updatePlaylist({
body: {
Genres: body.genres?.map((item) => ({ Id: item.id, Name: item.name })) || [],
IsPublic: body.public,
MediaType: 'Audio',
Name: body.name,
Overview: body.comment || '',
PremiereDate: null,
ProviderIds: {},
Tags: [],
@ -646,7 +646,7 @@ const updatePlaylist = async (args: UpdatePlaylistArgs): Promise<UpdatePlaylistR
},
});
if (res.status !== 200) {
if (res.status !== 204) {
throw new Error('Failed to update playlist');
}
@ -954,7 +954,12 @@ const getSongDetail = async (args: SongDetailArgs): Promise<SongDetailResponse>
return jfNormalize.song(res.body, apiClientProps.server, '');
};
const VERSION_INFO: VersionInfo = [['10.9.0', { [ServerFeature.LYRICS_SINGLE_STRUCTURED]: [1] }]];
const VERSION_INFO: VersionInfo = [
[
'10.9.0',
{ [ServerFeature.LYRICS_SINGLE_STRUCTURED]: [1], [ServerFeature.PUBLIC_PLAYLIST]: [1] },
],
];
const getServerInfo = async (args: ServerInfoArgs): Promise<ServerInfo> => {
const { apiClientProps } = args;

View file

@ -581,9 +581,9 @@ const playlistDetailParameters = baseParameters.extend({
});
const createPlaylistParameters = z.object({
IsPublic: z.boolean().optional(),
MediaType: z.literal('Audio'),
Name: z.string(),
Overview: z.string(),
UserId: z.string(),
});
@ -595,9 +595,9 @@ const updatePlaylist = z.null();
const updatePlaylistParameters = z.object({
Genres: z.array(genreItem),
IsPublic: z.boolean().optional(),
MediaType: z.literal('Audio'),
Name: z.string(),
Overview: z.string(),
PremiereDate: z.null(),
ProviderIds: z.object({}),
Tags: z.array(genericItem),

View file

@ -317,7 +317,7 @@ const createPlaylist = async (args: CreatePlaylistArgs): Promise<CreatePlaylistR
body: {
comment: body.comment,
name: body.name,
public: body._custom?.navidrome?.public,
public: body.public,
rules: body._custom?.navidrome?.rules,
sync: body._custom?.navidrome?.sync,
},
@ -339,7 +339,7 @@ const updatePlaylist = async (args: UpdatePlaylistArgs): Promise<UpdatePlaylistR
body: {
comment: body.comment || '',
name: body.name,
public: body._custom?.navidrome?.public || false,
public: body?.public || false,
rules: body._custom?.navidrome?.rules ? body._custom.navidrome.rules : undefined,
sync: body._custom?.navidrome?.sync || undefined,
},
@ -534,6 +534,7 @@ const getServerInfo = async (args: ServerInfoArgs): Promise<ServerInfo> => {
const features: ServerFeatures = {
lyricsMultipleStructured: !!navidromeFeatures[SubsonicExtensions.SONG_LYRICS],
playlistsSmart: !!navidromeFeatures[ServerFeature.PLAYLISTS_SMART],
publicPlaylist: true,
sharingAlbumSong: !!navidromeFeatures[ServerFeature.SHARING_ALBUM_SONG],
};

View file

@ -818,13 +818,13 @@ export type CreatePlaylistBody = {
navidrome?: {
owner?: string;
ownerId?: string;
public?: boolean;
rules?: Record<string, any>;
sync?: boolean;
};
};
comment?: string;
name: string;
public?: boolean;
};
export type CreatePlaylistArgs = { body: CreatePlaylistBody; serverId?: string } & BaseEndpointArgs;
@ -841,7 +841,6 @@ export type UpdatePlaylistBody = {
navidrome?: {
owner?: string;
ownerId?: string;
public?: boolean;
rules?: Record<string, any>;
sync?: boolean;
};
@ -849,6 +848,7 @@ export type UpdatePlaylistBody = {
comment?: string;
genres?: Genre[];
name: string;
public?: boolean;
};
export type UpdatePlaylistArgs = {

View file

@ -28,7 +28,6 @@ export const CreatePlaylistForm = ({ onCancel }: CreatePlaylistFormProps) => {
initialValues: {
_custom: {
navidrome: {
public: false,
rules: undefined,
},
},
@ -88,7 +87,7 @@ export const CreatePlaylistForm = ({ onCancel }: CreatePlaylistFormProps) => {
);
});
const isPublicDisplayed = server?.type === ServerType.NAVIDROME;
const isPublicDisplayed = hasFeature(server, ServerFeature.PUBLIC_PLAYLIST);
const isSubmitDisabled = !form.values.name || mutation.isLoading;
return (
@ -103,13 +102,15 @@ export const CreatePlaylistForm = ({ onCancel }: CreatePlaylistFormProps) => {
})}
{...form.getInputProps('name')}
/>
<TextInput
label={t('form.createPlaylist.input', {
context: 'description',
postProcess: 'titleCase',
})}
{...form.getInputProps('comment')}
/>
{server?.type === ServerType.NAVIDROME && (
<TextInput
label={t('form.createPlaylist.input', {
context: 'description',
postProcess: 'titleCase',
})}
{...form.getInputProps('comment')}
/>
)}
<Group>
{isPublicDisplayed && (
<Switch
@ -117,7 +118,7 @@ export const CreatePlaylistForm = ({ onCancel }: CreatePlaylistFormProps) => {
context: 'public',
postProcess: 'titleCase',
})}
{...form.getInputProps('_custom.navidrome.public', {
{...form.getInputProps('public', {
type: 'checkbox',
})}
/>

View file

@ -5,6 +5,8 @@ import { Button, Switch, TextInput, toast } from '/@/renderer/components';
import { useCreatePlaylist } from '/@/renderer/features/playlists/mutations/create-playlist-mutation';
import { useCurrentServer } from '/@/renderer/store';
import { useTranslation } from 'react-i18next';
import { ServerFeature } from '/@/renderer/api/features-types';
import { hasFeature } from '/@/renderer/api/utils';
interface SaveAsPlaylistFormProps {
body: Partial<CreatePlaylistBody>;
@ -27,13 +29,13 @@ export const SaveAsPlaylistForm = ({
initialValues: {
_custom: {
navidrome: {
public: false,
rules: undefined,
...body?._custom?.navidrome,
},
},
comment: body.comment || '',
name: body.name || '',
public: body.public,
},
});
@ -58,7 +60,7 @@ export const SaveAsPlaylistForm = ({
);
});
const isPublicDisplayed = server?.type === ServerType.NAVIDROME;
const isPublicDisplayed = hasFeature(server, ServerFeature.PUBLIC_PLAYLIST);
const isSubmitDisabled = !form.values.name || mutation.isLoading;
return (
@ -73,20 +75,22 @@ export const SaveAsPlaylistForm = ({
})}
{...form.getInputProps('name')}
/>
<TextInput
label={t('form.createPlaylist.input', {
context: 'description',
postProcess: 'titleCase',
})}
{...form.getInputProps('comment')}
/>
{server?.type === ServerType.NAVIDROME && (
<TextInput
label={t('form.createPlaylist.input', {
context: 'description',
postProcess: 'titleCase',
})}
{...form.getInputProps('comment')}
/>
)}
{isPublicDisplayed && (
<Switch
label={t('form.createPlaylist.input', {
context: 'public',
postProcess: 'titleCase',
})}
{...form.getInputProps('_custom.navidrome.public', { type: 'checkbox' })}
{...form.getInputProps('public', { type: 'checkbox' })}
/>
)}
<Group position="right">

View file

@ -20,6 +20,8 @@ import { queryClient } from '/@/renderer/lib/react-query';
import { useCurrentServer } from '/@/renderer/store';
import { useTranslation } from 'react-i18next';
import i18n from '/@/i18n/i18n';
import { hasFeature } from '/@/renderer/api/utils';
import { ServerFeature } from '/@/renderer/api/features-types';
interface UpdatePlaylistFormProps {
body: Partial<UpdatePlaylistBody>;
@ -44,13 +46,13 @@ export const UpdatePlaylistForm = ({ users, query, body, onCancel }: UpdatePlayl
navidrome: {
owner: body?._custom?.navidrome?.owner || '',
ownerId: body?._custom?.navidrome?.ownerId || '',
public: body?._custom?.navidrome?.public || false,
rules: undefined,
sync: body?._custom?.navidrome?.sync || false,
},
},
comment: body?.comment || '',
name: body?.name || '',
public: body.public,
},
});
@ -69,13 +71,16 @@ export const UpdatePlaylistForm = ({ users, query, body, onCancel }: UpdatePlayl
});
},
onSuccess: () => {
toast.success({
message: t('form.editPlaylist.success', { postProcess: 'sentenceCase' }),
});
onCancel();
},
},
);
});
const isPublicDisplayed = server?.type === ServerType.NAVIDROME;
const isPublicDisplayed = hasFeature(server, ServerFeature.PUBLIC_PLAYLIST);
const isOwnerDisplayed = server?.type === ServerType.NAVIDROME && userList;
const isSubmitDisabled = !form.values.name || mutation.isLoading;
@ -91,13 +96,15 @@ export const UpdatePlaylistForm = ({ users, query, body, onCancel }: UpdatePlayl
})}
{...form.getInputProps('name')}
/>
<TextInput
label={t('form.createPlaylist.input', {
context: 'description',
postProcess: 'titleCase',
})}
{...form.getInputProps('comment')}
/>
{server?.type === ServerType.NAVIDROME && (
<TextInput
label={t('form.createPlaylist.input', {
context: 'description',
postProcess: 'titleCase',
})}
{...form.getInputProps('comment')}
/>
)}
{isOwnerDisplayed && (
<Select
data={userList || []}
@ -109,13 +116,22 @@ export const UpdatePlaylistForm = ({ users, query, body, onCancel }: UpdatePlayl
/>
)}
{isPublicDisplayed && (
<Switch
label={t('form.createPlaylist.input', {
context: 'public',
postProcess: 'titleCase',
})}
{...form.getInputProps('_custom.navidrome.public', { type: 'checkbox' })}
/>
<>
{server?.type === ServerType.JELLYFIN && (
<div>
{t('form.editPlaylist.publicJellyfinNote', {
postProcess: 'sentenceCase',
})}
</div>
)}
<Switch
label={t('form.createPlaylist.input', {
context: 'public',
postProcess: 'titleCase',
})}
{...form.getInputProps('public', { type: 'checkbox' })}
/>
</>
)}
<Group position="right">
<Button
@ -175,7 +191,6 @@ export const openUpdatePlaylistModal = async (args: {
navidrome: {
owner: playlist?.owner || undefined,
ownerId: playlist?.ownerId || undefined,
public: playlist?.public || false,
rules: playlist?.rules || undefined,
sync: playlist?.sync || undefined,
},
@ -183,6 +198,7 @@ export const openUpdatePlaylistModal = async (args: {
comment: playlist?.description || undefined,
genres: playlist?.genres,
name: playlist?.name,
public: playlist?.public || false,
}}
query={{ id: playlist?.id }}
users={users?.items}

View file

@ -50,13 +50,13 @@ const PlaylistDetailSongListRoute = () => {
navidrome: {
owner: detailQuery?.data?.owner || '',
ownerId: detailQuery?.data?.ownerId || '',
public: detailQuery?.data?.public || false,
rules,
sync: detailQuery?.data?.sync || false,
},
},
comment: detailQuery?.data?.description || '',
name: detailQuery?.data?.name,
public: detailQuery?.data?.public || false,
},
serverId: detailQuery?.data?.serverId,
},
@ -92,7 +92,6 @@ const PlaylistDetailSongListRoute = () => {
navidrome: {
owner: detailQuery?.data?.owner || '',
ownerId: detailQuery?.data?.ownerId || '',
public: detailQuery?.data?.public || false,
rules: {
...filter,
limit: extraFilters.limit || undefined,
@ -104,6 +103,7 @@ const PlaylistDetailSongListRoute = () => {
},
comment: detailQuery?.data?.description || '',
name: detailQuery?.data?.name,
public: detailQuery?.data?.public || false,
}}
serverId={detailQuery?.data?.serverId}
onCancel={closeAllModals}