mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
Merge pull request #6561 from nielsvanvelzen/log-viewer
Add log viewer to dashboard
This commit is contained in:
commit
97b295dd0a
5 changed files with 142 additions and 18 deletions
25
src/apps/dashboard/features/logs/api/useServerLog.ts
Normal file
25
src/apps/dashboard/features/logs/api/useServerLog.ts
Normal file
|
@ -0,0 +1,25 @@
|
|||
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
|
||||
) => {
|
||||
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
|
||||
});
|
||||
};
|
|
@ -2,28 +2,15 @@ import React, { FunctionComponent } from 'react';
|
|||
import type { LogFile } from '@jellyfin/sdk/lib/generated-client/models/log-file';
|
||||
import List from '@mui/material/List';
|
||||
import ListItem from '@mui/material/ListItem';
|
||||
import ListItemButton from '@mui/material/ListItemButton';
|
||||
import ListItemText from '@mui/material/ListItemText';
|
||||
import OpenInNewIcon from '@mui/icons-material/OpenInNew';
|
||||
import { useApi } from 'hooks/useApi';
|
||||
import datetime from 'scripts/datetime';
|
||||
import ListItemLink from 'components/ListItemLink';
|
||||
|
||||
type LogItemProps = {
|
||||
logs: LogFile[];
|
||||
};
|
||||
|
||||
const LogItemList: FunctionComponent<LogItemProps> = ({ logs }: LogItemProps) => {
|
||||
const { api } = useApi();
|
||||
|
||||
const getLogFileUrl = (logFile: LogFile) => {
|
||||
if (!api) return '';
|
||||
|
||||
return api.getUri('/System/Logs/Log', {
|
||||
name: logFile.Name,
|
||||
api_key: api.accessToken
|
||||
});
|
||||
};
|
||||
|
||||
const getDate = (logFile: LogFile) => {
|
||||
const date = datetime.parseISO8601Date(logFile.DateModified, true);
|
||||
return datetime.toLocaleDateString(date) + ' ' + datetime.getDisplayTime(date);
|
||||
|
@ -34,15 +21,14 @@ const LogItemList: FunctionComponent<LogItemProps> = ({ logs }: LogItemProps) =>
|
|||
{logs.map(log => {
|
||||
return (
|
||||
<ListItem key={log.Name} disablePadding>
|
||||
<ListItemButton href={getLogFileUrl(log)} target='_blank'>
|
||||
<ListItemLink to={`/dashboard/logs/${log.Name}`}>
|
||||
<ListItemText
|
||||
primary={log.Name}
|
||||
primaryTypographyProps={{ variant: 'h3' }}
|
||||
secondary={getDate(log)}
|
||||
secondaryTypographyProps={{ variant: 'body1' }}
|
||||
/>
|
||||
<OpenInNewIcon />
|
||||
</ListItemButton>
|
||||
</ListItemLink>
|
||||
</ListItem>
|
||||
);
|
||||
})}
|
||||
|
|
|
@ -7,6 +7,7 @@ export const ASYNC_ADMIN_ROUTES: AsyncRoute[] = [
|
|||
{ path: 'devices', type: AppType.Dashboard },
|
||||
{ path: 'keys', type: AppType.Dashboard },
|
||||
{ path: 'logs', type: AppType.Dashboard },
|
||||
{ path: 'logs/:file', page: 'logs/file', type: AppType.Dashboard },
|
||||
{ path: 'playback/resume', type: AppType.Dashboard },
|
||||
{ path: 'playback/streaming', type: AppType.Dashboard },
|
||||
{ path: 'playback/trickplay', type: AppType.Dashboard },
|
||||
|
|
109
src/apps/dashboard/routes/logs/file.tsx
Normal file
109
src/apps/dashboard/routes/logs/file.tsx
Normal file
|
@ -0,0 +1,109 @@
|
|||
import Loading from 'components/loading/LoadingComponent';
|
||||
import Page from 'components/Page';
|
||||
import React, { useCallback } from 'react';
|
||||
import { useParams } from 'react-router-dom';
|
||||
import { useServerLog } from 'apps/dashboard/features/logs/api/useServerLog';
|
||||
import Alert from '@mui/material/Alert';
|
||||
import Box from '@mui/material/Box';
|
||||
import Button from '@mui/material/Button';
|
||||
import ButtonGroup from '@mui/material/ButtonGroup';
|
||||
import Container from '@mui/material/Container';
|
||||
import Paper from '@mui/material/Paper';
|
||||
import Typography from '@mui/material/Typography';
|
||||
import { ContentCopy, FileDownload } from '@mui/icons-material';
|
||||
import globalize from 'lib/globalize';
|
||||
import toast from 'components/toast/toast';
|
||||
import { copy } from 'scripts/clipboard';
|
||||
|
||||
export const Component = () => {
|
||||
const { file: fileName } = useParams();
|
||||
const {
|
||||
isError: error,
|
||||
isPending: loading,
|
||||
data: log,
|
||||
refetch
|
||||
} = useServerLog(fileName ?? '');
|
||||
|
||||
const retry = useCallback(() => refetch(), [refetch]);
|
||||
|
||||
const copyToClipboard = useCallback(async () => {
|
||||
if (log) {
|
||||
await copy(log);
|
||||
toast({ text: globalize.translate('CopyLogSuccess') });
|
||||
}
|
||||
}, [log]);
|
||||
|
||||
const downloadFile = useCallback(() => {
|
||||
if ('URL' in globalThis && log && fileName) {
|
||||
const blob = new Blob([log], { type: 'text/plain' });
|
||||
const url = URL.createObjectURL(blob);
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
a.download = fileName;
|
||||
a.click();
|
||||
URL.revokeObjectURL(url);
|
||||
}
|
||||
}, [log, fileName]);
|
||||
|
||||
return (
|
||||
<Page
|
||||
id='logPage'
|
||||
title={fileName}
|
||||
className='mainAnimatedPage type-interior'
|
||||
>
|
||||
<Container className='content-primary'>
|
||||
<Box>
|
||||
<Typography variant='h1'>{fileName}</Typography>
|
||||
|
||||
{error && (
|
||||
<Alert
|
||||
key='error'
|
||||
severity='error'
|
||||
sx={{ mt: 2 }}
|
||||
action={
|
||||
<Button
|
||||
color='inherit'
|
||||
size='small'
|
||||
onClick={retry}
|
||||
>
|
||||
{globalize.translate('Retry')}
|
||||
</Button>
|
||||
}
|
||||
>
|
||||
{globalize.translate('LogLoadFailure')}
|
||||
</Alert>
|
||||
)}
|
||||
|
||||
{loading && <Loading />}
|
||||
|
||||
{!error && !loading && (
|
||||
<>
|
||||
<ButtonGroup variant='contained' sx={{ mt: 2 }}>
|
||||
<Button
|
||||
startIcon={<ContentCopy />}
|
||||
onClick={copyToClipboard}
|
||||
>
|
||||
{globalize.translate('Copy')}
|
||||
</Button>
|
||||
<Button
|
||||
startIcon={<FileDownload />}
|
||||
onClick={downloadFile}
|
||||
>
|
||||
{globalize.translate('Download')}
|
||||
</Button>
|
||||
</ButtonGroup>
|
||||
|
||||
<Paper sx={{ mt: 2 }}>
|
||||
<code>
|
||||
<pre style={{ overflow:'auto', margin: 0, padding: '16px' }}>{log}</pre>
|
||||
</code>
|
||||
</Paper>
|
||||
</>
|
||||
)}
|
||||
</Box>
|
||||
</Container>
|
||||
</Page>
|
||||
);
|
||||
};
|
||||
|
||||
Component.displayName = 'LogPage';
|
|
@ -188,6 +188,7 @@
|
|||
"CopyFailed": "Could not copy",
|
||||
"CopyStreamURL": "Copy Stream URL",
|
||||
"CopyStreamURLSuccess": "URL copied successfully.",
|
||||
"CopyLogSuccess": "Log contents copied successfully.",
|
||||
"CoverArtist": "Cover artist",
|
||||
"Creator": "Creator",
|
||||
"CriticRating": "Critics rating",
|
||||
|
@ -1444,6 +1445,7 @@
|
|||
"ReplaceAllMetadata": "Replace all metadata",
|
||||
"ReplaceExistingImages": "Replace existing images",
|
||||
"ReplaceTrickplayImages": "Replace existing trickplay images",
|
||||
"Retry": "Retry",
|
||||
"Reset": "Reset",
|
||||
"ResetPassword": "Reset Password",
|
||||
"ResolutionMatchSource": "Match Source",
|
||||
|
@ -1808,5 +1810,6 @@
|
|||
"OptionExtractTrickplayImage": "Enable trickplay image extraction",
|
||||
"ExtractTrickplayImagesHelp": "Trickplay images are similar to chapter images, except they span the entire length of the content and are used to show a preview when scrubbing through videos.",
|
||||
"LabelExtractTrickplayDuringLibraryScan": "Extract trickplay images during the library scan",
|
||||
"LabelExtractTrickplayDuringLibraryScanHelp": "Generate trickplay images when videos are imported during the library scan. Otherwise, they will be extracted during the trickplay images scheduled task. If generation is set to non-blocking this will not affect the time a library scan takes to complete."
|
||||
"LabelExtractTrickplayDuringLibraryScanHelp": "Generate trickplay images when videos are imported during the library scan. Otherwise, they will be extracted during the trickplay images scheduled task. If generation is set to non-blocking this will not affect the time a library scan takes to complete.",
|
||||
"LogLoadFailure": "Failed to load the log file. It may still be actively written to."
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue