2024-12-17 20:31:03 +03:00
|
|
|
import React, { ChangeEvent, useCallback, useEffect, useState } from 'react';
|
2024-12-17 15:55:15 +03:00
|
|
|
import { getConfigurationApi } from '@jellyfin/sdk/lib/utils/api/configuration-api';
|
|
|
|
import Loading from 'components/loading/LoadingComponent';
|
|
|
|
import Page from 'components/Page';
|
|
|
|
import globalize from 'lib/globalize';
|
2024-12-17 17:00:24 +03:00
|
|
|
import { Alert, Box, Button, FormControlLabel, Stack, Switch, TextField, Typography } from '@mui/material';
|
2024-12-17 21:35:45 +03:00
|
|
|
import { type ActionFunctionArgs, Form, useActionData } from 'react-router-dom';
|
2024-12-17 20:31:03 +03:00
|
|
|
import ServerConnections from 'components/ServerConnections';
|
2025-01-14 01:07:56 +03:00
|
|
|
import { useServerLogs } from 'apps/dashboard/features/logs/api/useServerLogs';
|
2025-01-14 01:10:06 +03:00
|
|
|
import { useConfiguration } from 'hooks/useConfiguration';
|
2024-12-17 21:35:45 +03:00
|
|
|
import type { ServerConfiguration } from '@jellyfin/sdk/lib/generated-client/models/server-configuration';
|
2024-12-17 23:38:03 +03:00
|
|
|
import { ActionData } from 'types/actionData';
|
2025-01-14 23:42:26 +03:00
|
|
|
import LogItemList from 'apps/dashboard/features/logs/components/LogItemList';
|
2024-12-17 20:31:03 +03:00
|
|
|
|
|
|
|
export const action = async ({ request }: ActionFunctionArgs) => {
|
|
|
|
const api = ServerConnections.getCurrentApi();
|
|
|
|
if (!api) throw new Error('No Api instance available');
|
|
|
|
|
|
|
|
const formData = await request.formData();
|
|
|
|
const { data: config } = await getConfigurationApi(api).getConfiguration();
|
|
|
|
|
2024-12-18 00:03:09 +03:00
|
|
|
const enableWarningMessage = formData.get('EnableWarningMessage');
|
2025-01-14 01:17:56 +03:00
|
|
|
config.EnableSlowResponseWarning = enableWarningMessage === 'on';
|
2024-12-17 20:31:03 +03:00
|
|
|
|
|
|
|
const responseTime = formData.get('SlowResponseTime');
|
|
|
|
if (responseTime) {
|
|
|
|
config.SlowResponseThresholdMs = parseInt(responseTime.toString(), 10);
|
|
|
|
}
|
|
|
|
|
|
|
|
await getConfigurationApi(api)
|
|
|
|
.updateConfiguration({ serverConfiguration: config });
|
|
|
|
|
|
|
|
return {
|
|
|
|
isSaved: true
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-12-17 21:35:45 +03:00
|
|
|
const Logs = () => {
|
2024-12-17 20:31:03 +03:00
|
|
|
const actionData = useActionData() as ActionData | undefined;
|
|
|
|
const [ isSubmitting, setIsSubmitting ] = useState(false);
|
2024-12-17 17:00:24 +03:00
|
|
|
|
2025-01-14 01:07:56 +03:00
|
|
|
const { isPending: isLogEntriesPending, data: logs } = useServerLogs();
|
2025-01-14 01:10:06 +03:00
|
|
|
const { isPending: isConfigurationPending, data: defaultConfiguration } = useConfiguration();
|
2024-12-17 21:35:45 +03:00
|
|
|
const [ loading, setLoading ] = useState(true);
|
2025-01-14 01:17:56 +03:00
|
|
|
const [ configuration, setConfiguration ] = useState<ServerConfiguration>( {} );
|
2024-12-17 17:00:24 +03:00
|
|
|
|
2024-12-17 21:35:45 +03:00
|
|
|
useEffect(() => {
|
2025-01-14 01:10:06 +03:00
|
|
|
if (!isConfigurationPending && defaultConfiguration) {
|
2025-01-14 01:17:56 +03:00
|
|
|
setConfiguration(defaultConfiguration);
|
2024-12-17 21:35:45 +03:00
|
|
|
setLoading(false);
|
|
|
|
}
|
2025-01-14 01:10:06 +03:00
|
|
|
}, [isConfigurationPending, defaultConfiguration]);
|
2024-12-17 15:55:15 +03:00
|
|
|
|
2024-12-17 21:35:45 +03:00
|
|
|
const setLogWarningMessage = useCallback((_: ChangeEvent<HTMLInputElement>, checked: boolean) => {
|
2025-01-14 01:17:56 +03:00
|
|
|
setConfiguration({
|
|
|
|
...configuration,
|
2024-12-17 21:35:45 +03:00
|
|
|
EnableSlowResponseWarning: checked
|
|
|
|
});
|
2025-01-14 01:17:56 +03:00
|
|
|
}, [configuration]);
|
2024-12-17 15:55:15 +03:00
|
|
|
|
2024-12-17 21:35:45 +03:00
|
|
|
const onResponseTimeChange = useCallback((event: ChangeEvent<HTMLTextAreaElement>) => {
|
2025-01-14 01:17:56 +03:00
|
|
|
setConfiguration({
|
|
|
|
...configuration,
|
2024-12-17 21:35:45 +03:00
|
|
|
SlowResponseThresholdMs: parseInt(event.target.value, 10)
|
|
|
|
});
|
2025-01-14 01:17:56 +03:00
|
|
|
}, [configuration]);
|
2024-12-17 15:55:15 +03:00
|
|
|
|
2024-12-17 20:31:03 +03:00
|
|
|
const onSubmit = useCallback(() => {
|
|
|
|
setIsSubmitting(true);
|
|
|
|
}, []);
|
2024-12-17 15:55:15 +03:00
|
|
|
|
2025-01-14 23:42:26 +03:00
|
|
|
if (isLogEntriesPending || isConfigurationPending || loading || !logs) {
|
2024-12-17 15:55:15 +03:00
|
|
|
return <Loading />;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Page
|
|
|
|
id='logPage'
|
|
|
|
title={globalize.translate('TabLogs')}
|
|
|
|
className='mainAnimatedPage type-interior'
|
|
|
|
>
|
2024-12-17 17:00:24 +03:00
|
|
|
<Box className='content-primary'>
|
2024-12-17 20:31:03 +03:00
|
|
|
<Form method='POST' onSubmit={onSubmit}>
|
2024-12-17 17:00:24 +03:00
|
|
|
<Stack spacing={3}>
|
|
|
|
<Typography variant='h1'>
|
|
|
|
{globalize.translate('TabLogs')}
|
|
|
|
</Typography>
|
|
|
|
|
2024-12-17 20:31:03 +03:00
|
|
|
{isSubmitting && actionData?.isSaved && (
|
2024-12-17 17:00:24 +03:00
|
|
|
<Alert severity='success'>
|
|
|
|
{globalize.translate('SettingsSaved')}
|
|
|
|
</Alert>
|
|
|
|
)}
|
|
|
|
|
|
|
|
<FormControlLabel
|
|
|
|
control={
|
|
|
|
<Switch
|
2025-01-14 01:17:56 +03:00
|
|
|
checked={configuration?.EnableSlowResponseWarning}
|
2024-12-17 17:00:24 +03:00
|
|
|
onChange={setLogWarningMessage}
|
2024-12-17 20:31:03 +03:00
|
|
|
name={'EnableWarningMessage'}
|
2024-12-17 17:00:24 +03:00
|
|
|
/>
|
|
|
|
}
|
|
|
|
label={globalize.translate('LabelSlowResponseEnabled')}
|
2024-12-17 15:55:15 +03:00
|
|
|
/>
|
|
|
|
|
2024-12-17 17:00:24 +03:00
|
|
|
<TextField
|
|
|
|
fullWidth
|
|
|
|
type='number'
|
2024-12-17 20:31:03 +03:00
|
|
|
name={'SlowResponseTime'}
|
2024-12-17 17:00:24 +03:00
|
|
|
label={globalize.translate('LabelSlowResponseTime')}
|
2025-01-14 01:17:56 +03:00
|
|
|
value={configuration?.SlowResponseThresholdMs}
|
|
|
|
disabled={!configuration?.EnableSlowResponseWarning}
|
2024-12-17 17:00:24 +03:00
|
|
|
onChange={onResponseTimeChange}
|
|
|
|
/>
|
|
|
|
|
|
|
|
<Button
|
|
|
|
type='submit'
|
|
|
|
size='large'
|
|
|
|
>
|
|
|
|
{globalize.translate('Save')}
|
|
|
|
</Button>
|
|
|
|
</Stack>
|
|
|
|
</Form>
|
2025-01-14 01:57:43 +03:00
|
|
|
<Stack className='serverLogs readOnlyContent' spacing={1} sx={{ mt: 1 }}>
|
2025-01-14 23:42:26 +03:00
|
|
|
<LogItemList logs={logs} />
|
2025-01-14 01:57:43 +03:00
|
|
|
</Stack>
|
2024-12-17 17:00:24 +03:00
|
|
|
</Box>
|
2024-12-17 15:55:15 +03:00
|
|
|
</Page>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Logs;
|