2023-11-28 10:26:14 -05:00
|
|
|
import { useQuery } from '@tanstack/react-query';
|
|
|
|
import type { Api } from '@jellyfin/sdk';
|
|
|
|
import { getSystemApi } from '@jellyfin/sdk/lib/utils/api/system-api';
|
|
|
|
import type { AxiosRequestConfig } from 'axios';
|
|
|
|
|
2024-02-21 00:47:03 -05:00
|
|
|
import { useApi } from './useApi';
|
|
|
|
import { queryOptions } from 'utils/query/queryOptions';
|
|
|
|
|
2023-11-28 10:26:14 -05:00
|
|
|
const fetchSystemInfo = async (
|
2024-02-21 00:47:03 -05:00
|
|
|
api?: Api,
|
|
|
|
options?: AxiosRequestConfig
|
2023-11-28 10:26:14 -05:00
|
|
|
) => {
|
2024-02-21 00:47:03 -05:00
|
|
|
if (!api) {
|
|
|
|
console.warn('[fetchSystemInfo] No API instance available');
|
|
|
|
return;
|
|
|
|
}
|
2023-11-28 10:26:14 -05:00
|
|
|
|
|
|
|
const response = await getSystemApi(api)
|
|
|
|
.getSystemInfo(options);
|
|
|
|
return response.data;
|
|
|
|
};
|
|
|
|
|
2024-02-21 00:47:03 -05:00
|
|
|
export const getSystemInfoQuery = (
|
|
|
|
api?: Api
|
|
|
|
) => queryOptions({
|
|
|
|
queryKey: [ 'SystemInfo' ],
|
|
|
|
queryFn: ({ signal }) => fetchSystemInfo(api, { signal }),
|
|
|
|
// Allow for query reuse in legacy javascript.
|
|
|
|
staleTime: 1000, // 1 second
|
|
|
|
enabled: !!api
|
|
|
|
});
|
|
|
|
|
|
|
|
export const useSystemInfo = () => {
|
|
|
|
const { api } = useApi();
|
|
|
|
return useQuery(getSystemInfoQuery(api));
|
2023-11-28 10:26:14 -05:00
|
|
|
};
|