mirror of
https://github.com/diced/zipline.git
synced 2025-12-12 15:50:11 -08:00
feat: pdf rendering in dashboard
uses builtin browser renderer, basically every modern browser will work
This commit is contained in:
@@ -11,11 +11,12 @@ import {
|
|||||||
Text,
|
Text,
|
||||||
} from '@mantine/core';
|
} from '@mantine/core';
|
||||||
import { Icon, IconFileUnknown, IconPlayerPlay, IconShieldLockFilled } from '@tabler/icons-react';
|
import { Icon, IconFileUnknown, IconPlayerPlay, IconShieldLockFilled } from '@tabler/icons-react';
|
||||||
import { useEffect, useState, useCallback, useMemo } from 'react';
|
import { useCallback, useEffect, useMemo, useState } from 'react';
|
||||||
import { renderMode } from '../pages/upload/renderMode';
|
import { renderMode } from '../pages/upload/renderMode';
|
||||||
|
import Asciinema from '../render/Asciinema';
|
||||||
|
import Pdf from '../render/Pdf';
|
||||||
import Render from '../render/Render';
|
import Render from '../render/Render';
|
||||||
import fileIcon from './fileIcon';
|
import fileIcon from './fileIcon';
|
||||||
import Asciinema from '../render/Asciinema';
|
|
||||||
|
|
||||||
function PlaceholderContent({ text, Icon }: { text: string; Icon: Icon }) {
|
function PlaceholderContent({ text, Icon }: { text: string; Icon: Icon }) {
|
||||||
return (
|
return (
|
||||||
@@ -204,6 +205,7 @@ export default function DashboardFileType({
|
|||||||
) : (
|
) : (
|
||||||
<Placeholder text={`Click to play video ${file.name}`} Icon={fileIcon(file.type)} />
|
<Placeholder text={`Click to play video ${file.name}`} Icon={fileIcon(file.type)} />
|
||||||
);
|
);
|
||||||
|
|
||||||
case type === 'image':
|
case type === 'image':
|
||||||
return show ? (
|
return show ? (
|
||||||
<Center>
|
<Center>
|
||||||
@@ -243,6 +245,7 @@ export default function DashboardFileType({
|
|||||||
alt={file.name || 'Image'}
|
alt={file.name || 'Image'}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|
||||||
case type === 'audio':
|
case type === 'audio':
|
||||||
return show ? (
|
return show ? (
|
||||||
<audio
|
<audio
|
||||||
@@ -255,6 +258,7 @@ export default function DashboardFileType({
|
|||||||
) : (
|
) : (
|
||||||
<Placeholder text={`Click to play audio ${file.name}`} Icon={fileIcon(file.type)} />
|
<Placeholder text={`Click to play audio ${file.name}`} Icon={fileIcon(file.type)} />
|
||||||
);
|
);
|
||||||
|
|
||||||
case type === 'text':
|
case type === 'text':
|
||||||
return show ? (
|
return show ? (
|
||||||
fileContent.trim() === '' ? (
|
fileContent.trim() === '' ? (
|
||||||
@@ -279,15 +283,24 @@ export default function DashboardFileType({
|
|||||||
) : (
|
) : (
|
||||||
<Placeholder text={`Click to view text ${file.name}`} Icon={fileIcon(file.type)} />
|
<Placeholder text={`Click to view text ${file.name}`} Icon={fileIcon(file.type)} />
|
||||||
);
|
);
|
||||||
|
|
||||||
case isAsciicast === true:
|
case isAsciicast === true:
|
||||||
return show && dbFile ? (
|
return show && dbFile ? (
|
||||||
<Asciinema src={`/raw/${file.name}`} />
|
<Asciinema src={`/raw/${file.name}${password ? `?pw=${password}` : ''}`} />
|
||||||
) : (
|
) : (
|
||||||
<Placeholder
|
<Placeholder
|
||||||
text={`Click to download asciinema cast ${file.name}`}
|
text={`Click to download asciinema cast ${file.name}`}
|
||||||
Icon={fileIcon('application/x-asciicast')}
|
Icon={fileIcon('application/x-asciicast')}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
case file.type === 'application/pdf':
|
||||||
|
return show && dbFile ? (
|
||||||
|
<Pdf src={`/raw/${file.name}${password ? `?pw=${password}` : ''}`} />
|
||||||
|
) : (
|
||||||
|
<Placeholder text={`Click to view PDF ${file.name}`} Icon={fileIcon(file.type)} />
|
||||||
|
);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if (dbFile && !show)
|
if (dbFile && !show)
|
||||||
return <Placeholder text={`Click to view file ${file.name}`} Icon={fileIcon(file.type)} />;
|
return <Placeholder text={`Click to view file ${file.name}`} Icon={fileIcon(file.type)} />;
|
||||||
|
|||||||
17
src/components/render/Pdf.tsx
Normal file
17
src/components/render/Pdf.tsx
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
import { useLocation } from 'react-router-dom';
|
||||||
|
|
||||||
|
export default function Pdf({ src }: { src: string }) {
|
||||||
|
const location = useLocation();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<iframe
|
||||||
|
src={src + '#view=FitH'}
|
||||||
|
style={{
|
||||||
|
width: location.pathname.startsWith('/view') ? '70vw' : '100%',
|
||||||
|
height: location.pathname.startsWith('/view') ? '80vh' : '100vh',
|
||||||
|
border: 'none',
|
||||||
|
}}
|
||||||
|
title={src}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user