1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00
jellyfin-web/src/hooks/useSystemInfo.ts
Doxterpepper 614c9e4481 Backport pull request #5730 from jellyfin-web/release-10.9.z
Add no-cache attribute for fetch requests to /system/info/public to prevent stale server info

Original-merge: a0e6da790c

Merged-by: thornbill <thornbill@users.noreply.github.com>

Backported-by: thornbill <thornbill@users.noreply.github.com>
2024-08-13 11:53:19 -04:00

35 lines
997 B
TypeScript

import { queryOptions, 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';
import { useApi } from './useApi';
const fetchSystemInfo = async (
api?: Api,
options?: AxiosRequestConfig
) => {
if (!api) {
console.warn('[fetchSystemInfo] No API instance available');
return;
}
const response = await getSystemApi(api)
.getSystemInfo(options);
return response.data;
};
export const getSystemInfoQuery = (
api?: Api
) => queryOptions({
queryKey: [ 'SystemInfo' ],
queryFn: ({ signal }) => fetchSystemInfo(api, { signal, headers: { 'Cache-Control': 'no-cache' } }),
// Allow for query reuse in legacy javascript.
staleTime: 1000, // 1 second
enabled: !!api
});
export const useSystemInfo = () => {
const { api } = useApi();
return useQuery(getSystemInfoQuery(api));
};