1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00
jellyfin-web/src/apps/dashboard/features/logs/api/useServerLog.ts
2025-02-24 19:33:01 +01:00

29 lines
916 B
TypeScript

import { Api } from '@jellyfin/sdk';
import { getSystemApi } from '@jellyfin/sdk/lib/utils/api/system-api';
import { useQuery } from '@tanstack/react-query';
import { useApi } from 'hooks/useApi';
import type { AxiosRequestConfig } from 'axios';
const fetchServerLog = async (
api: Api,
name: string,
options?: AxiosRequestConfig
) => {
if (!api) {
console.error('[useServerLog] No API instance available');
return;
}
const response = await getSystemApi(api).getLogFile({ name }, options);
// FIXME: TypeScript SDK thinks it is returning a File but in reality it is a string
return response.data as never as string;
};
export const useServerLog = (name: string) => {
const { api } = useApi();
return useQuery({
queryKey: ['ServerLog', name],
queryFn: ({ signal }) => fetchServerLog(api!, name, { signal }),
enabled: !!api
});
};