mirror of
https://github.com/MrRobotjs/MUM.git
synced 2025-12-20 08:19:33 -06:00
Refactor plugin metadata handling in streaming cards
Moves plugin metadata fetching from StreamingSessionCard to ActiveStreamsCard and passes the data as a prop. Defines PluginMetaResponse type in types/streaming.ts for better type safety and reusability.
This commit is contained in:
@@ -1,7 +1,8 @@
|
|||||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
||||||
import { Badge } from '@/components/ui/badge';
|
import { Badge } from '@/components/ui/badge';
|
||||||
import { StreamingSessionCard } from './StreamingSessionCard';
|
import { StreamingSessionCard } from './StreamingSessionCard';
|
||||||
import type { ActiveSession, ActiveSessionsResponse, ViewMode } from '@/types/streaming';
|
import { useAdminApi } from '@/hooks/useAdminApi';
|
||||||
|
import type { ActiveSession, ActiveSessionsResponse, PluginMetaResponse, ViewMode } from '@/types/streaming';
|
||||||
|
|
||||||
interface ActiveStreamsCardProps {
|
interface ActiveStreamsCardProps {
|
||||||
sessionsData: ActiveSessionsResponse | null;
|
sessionsData: ActiveSessionsResponse | null;
|
||||||
@@ -24,11 +25,15 @@ export const ActiveStreamsCard = ({
|
|||||||
lastUpdateAt,
|
lastUpdateAt,
|
||||||
onTerminateSession
|
onTerminateSession
|
||||||
}: ActiveStreamsCardProps) => {
|
}: ActiveStreamsCardProps) => {
|
||||||
|
const { data: pluginMetaData } = useAdminApi<PluginMetaResponse>('/plugins/metadata', true);
|
||||||
|
const pluginFeaturesByService = pluginMetaData?.data ?? null;
|
||||||
|
|
||||||
const renderSessionCard = (session: ActiveSession) => (
|
const renderSessionCard = (session: ActiveSession) => (
|
||||||
<StreamingSessionCard
|
<StreamingSessionCard
|
||||||
key={session.session_key}
|
key={session.session_key}
|
||||||
session={session}
|
session={session}
|
||||||
onTerminate={onTerminateSession}
|
onTerminate={onTerminateSession}
|
||||||
|
pluginFeaturesByService={pluginFeaturesByService}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -14,11 +14,10 @@ import { Textarea } from '@/components/ui/textarea';
|
|||||||
import { requestJson } from '@/util/apiClient';
|
import { requestJson } from '@/util/apiClient';
|
||||||
import { useAlerts } from '@/contexts/AlertContext';
|
import { useAlerts } from '@/contexts/AlertContext';
|
||||||
import { getServiceIconClass, getServiceMeta } from '@/config/pluginMetadata';
|
import { getServiceIconClass, getServiceMeta } from '@/config/pluginMetadata';
|
||||||
import { useAdminApi } from '@/hooks/useAdminApi';
|
|
||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import { useNavigate } from '@tanstack/react-router';
|
import { useNavigate } from '@tanstack/react-router';
|
||||||
import { buildUserProfilePath } from '@/util/routes';
|
import { buildUserProfilePath } from '@/util/routes';
|
||||||
import type { ActiveSession } from '@/types/streaming';
|
import type { ActiveSession, PluginMetaResponse } from '@/types/streaming';
|
||||||
|
|
||||||
const StreamInfoDialog = ({ open, onOpenChange }: { open: boolean; onOpenChange: (open: boolean) => void }) => {
|
const StreamInfoDialog = ({ open, onOpenChange }: { open: boolean; onOpenChange: (open: boolean) => void }) => {
|
||||||
return (
|
return (
|
||||||
@@ -80,6 +79,7 @@ const StreamInfoDialog = ({ open, onOpenChange }: { open: boolean; onOpenChange:
|
|||||||
interface StreamingSessionCardProps {
|
interface StreamingSessionCardProps {
|
||||||
session: ActiveSession;
|
session: ActiveSession;
|
||||||
onTerminate: (session: ActiveSession) => void;
|
onTerminate: (session: ActiveSession) => void;
|
||||||
|
pluginFeaturesByService?: PluginMetaResponse['data'] | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const getStateColor = (state?: string) => {
|
const getStateColor = (state?: string) => {
|
||||||
@@ -90,15 +90,6 @@ const getStateColor = (state?: string) => {
|
|||||||
return 'text-gray-500 bg-gray-500';
|
return 'text-gray-500 bg-gray-500';
|
||||||
};
|
};
|
||||||
|
|
||||||
type PluginMetaResponse = {
|
|
||||||
data: Record<
|
|
||||||
string,
|
|
||||||
{
|
|
||||||
features?: string[];
|
|
||||||
}
|
|
||||||
>;
|
|
||||||
};
|
|
||||||
|
|
||||||
type JellyfinRawSession = {
|
type JellyfinRawSession = {
|
||||||
UserId?: string;
|
UserId?: string;
|
||||||
PlayState?: { AudioStreamIndex?: number };
|
PlayState?: { AudioStreamIndex?: number };
|
||||||
@@ -183,14 +174,13 @@ const tryExtractJellyfinUserId = (rawDataJson?: string) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const StreamingSessionCard = ({ session, onTerminate }: StreamingSessionCardProps) => {
|
export const StreamingSessionCard = ({ session, onTerminate, pluginFeaturesByService }: StreamingSessionCardProps) => {
|
||||||
const [showStreamInfo, setShowStreamInfo] = useState(false);
|
const [showStreamInfo, setShowStreamInfo] = useState(false);
|
||||||
const [showSendMessage, setShowSendMessage] = useState(false);
|
const [showSendMessage, setShowSendMessage] = useState(false);
|
||||||
const [sendMessageText, setSendMessageText] = useState('');
|
const [sendMessageText, setSendMessageText] = useState('');
|
||||||
const [sendMessageHeader, setSendMessageHeader] = useState('MUM');
|
const [sendMessageHeader, setSendMessageHeader] = useState('MUM');
|
||||||
const [sendMessageTimeoutSeconds, setSendMessageTimeoutSeconds] = useState<string>('');
|
const [sendMessageTimeoutSeconds, setSendMessageTimeoutSeconds] = useState<string>('');
|
||||||
const [sendingMessage, setSendingMessage] = useState(false);
|
const [sendingMessage, setSendingMessage] = useState(false);
|
||||||
const { data: pluginMetaData } = useAdminApi<PluginMetaResponse>('/plugins/metadata', true);
|
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const normalizedState = session.state?.toLowerCase();
|
const normalizedState = session.state?.toLowerCase();
|
||||||
const stateColor = getStateColor(session.state);
|
const stateColor = getStateColor(session.state);
|
||||||
@@ -205,7 +195,7 @@ export const StreamingSessionCard = ({ session, onTerminate }: StreamingSessionC
|
|||||||
const serviceMeta = getServiceMeta(session.service_type);
|
const serviceMeta = getServiceMeta(session.service_type);
|
||||||
const supportsSessionMessage = Boolean(
|
const supportsSessionMessage = Boolean(
|
||||||
normalizedServiceType &&
|
normalizedServiceType &&
|
||||||
pluginMetaData?.data?.[normalizedServiceType]?.features?.includes('session_message')
|
pluginFeaturesByService?.[normalizedServiceType]?.features?.includes('session_message')
|
||||||
);
|
);
|
||||||
|
|
||||||
const jellyfinAudioTranscodeLabel =
|
const jellyfinAudioTranscodeLabel =
|
||||||
|
|||||||
@@ -71,3 +71,11 @@ export type ActiveSessionsResponse = {
|
|||||||
|
|
||||||
export type ViewMode = 'merged' | 'categorized' | 'service';
|
export type ViewMode = 'merged' | 'categorized' | 'service';
|
||||||
|
|
||||||
|
export type PluginMetaResponse = {
|
||||||
|
data: Record<
|
||||||
|
string,
|
||||||
|
{
|
||||||
|
features?: string[];
|
||||||
|
}
|
||||||
|
>;
|
||||||
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user