You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
63 lines
1.7 KiB
63 lines
1.7 KiB
import useSWR from 'swr';
|
|
import { MediaRequest } from '../../server/entity/MediaRequest';
|
|
import {
|
|
ServiceCommonServer,
|
|
ServiceCommonServerWithDetails,
|
|
} from '../../server/interfaces/api/serviceInterfaces';
|
|
|
|
interface OverrideStatus {
|
|
server?: string;
|
|
profile?: string;
|
|
rootFolder?: string;
|
|
languageProfile?: string;
|
|
}
|
|
|
|
const useRequestOverride = (request: MediaRequest): OverrideStatus => {
|
|
const { data: allServers } = useSWR<ServiceCommonServer[]>(
|
|
`/api/v1/service/${request.type === 'movie' ? 'radarr' : 'sonarr'}`
|
|
);
|
|
|
|
const { data } = useSWR<ServiceCommonServerWithDetails>(
|
|
`/api/v1/service/${request.type === 'movie' ? 'radarr' : 'sonarr'}/${
|
|
request.serverId
|
|
}`
|
|
);
|
|
|
|
if (!data || !allServers) {
|
|
return {};
|
|
}
|
|
|
|
const defaultServer = allServers.find(
|
|
(server) => server.is4k === request.is4k && server.isDefault
|
|
);
|
|
|
|
const activeServer = allServers.find(
|
|
(server) => server.id === request.serverId
|
|
);
|
|
|
|
return {
|
|
server:
|
|
activeServer && request.serverId !== defaultServer?.id
|
|
? activeServer.name
|
|
: undefined,
|
|
profile:
|
|
defaultServer?.activeProfileId !== request.profileId
|
|
? data.profiles.find((profile) => profile.id === request.profileId)
|
|
?.name
|
|
: undefined,
|
|
rootFolder:
|
|
defaultServer?.activeDirectory !== request.rootFolder
|
|
? request.rootFolder
|
|
: undefined,
|
|
languageProfile:
|
|
request.type === 'tv' &&
|
|
defaultServer?.activeLanguageProfileId !== request.languageProfileId
|
|
? data.languageProfiles?.find(
|
|
(profile) => profile.id === request.languageProfileId
|
|
)?.name
|
|
: undefined,
|
|
};
|
|
};
|
|
|
|
export default useRequestOverride;
|