Files
jellyfin-web/src/apps/dashboard/features/logs/api/useServerLog.ts

32 lines
949 B
TypeScript
Raw Normal View History

2025-02-20 22:19:36 +01:00
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 (
2025-02-24 19:33:01 +01:00
api: Api,
2025-02-23 21:57:41 +01:00
name: string,
2025-02-20 22:19:36 +01:00
options?: AxiosRequestConfig
) => {
const response = await getSystemApi(api).getLogFile({ name }, options);
// FIXME: TypeScript SDK thinks it is returning a File but in reality it is a string
2025-10-28 12:38:45 +03:00
const data = response.data as never as string | object;
if (typeof data === 'object') {
return JSON.stringify(data, null, 2);
} else {
return data;
}
2025-02-20 22:19:36 +01:00
};
export const useServerLog = (name: string) => {
const { api } = useApi();
return useQuery({
queryKey: ['ServerLog', name],
2025-02-24 19:33:01 +01:00
queryFn: ({ signal }) => fetchServerLog(api!, name, { signal }),
2025-02-20 22:19:36 +01:00
enabled: !!api
});
};