mirror of
https://github.com/cinnyapp/cinny.git
synced 2025-11-17 20:50:29 +03:00
Render file as readable with ext (#1446)
This commit is contained in:
parent
609b132106
commit
152576e85d
4 changed files with 58 additions and 11 deletions
|
|
@ -23,7 +23,12 @@ import { useMatrixClient } from '../../../hooks/useMatrixClient';
|
|||
import { getFileSrcUrl, getSrcFile } from './util';
|
||||
import { bytesToSize } from '../../../utils/common';
|
||||
import { TextViewer } from '../../../components/text-viewer';
|
||||
import { READABLE_TEXT_MIME_TYPES } from '../../../utils/mimeTypes';
|
||||
import {
|
||||
READABLE_EXT_TO_MIME_TYPE,
|
||||
READABLE_TEXT_MIME_TYPES,
|
||||
getFileNameExt,
|
||||
mimeTypeToExt,
|
||||
} from '../../../utils/mimeTypes';
|
||||
import { PdfViewer } from '../../../components/Pdf-viewer';
|
||||
import * as css from './styles.css';
|
||||
|
||||
|
|
@ -103,7 +108,11 @@ function ReadTextFile({ body, mimeType, url, encInfo }: Omit<FileContentProps, '
|
|||
<TextViewer
|
||||
name={body}
|
||||
text={textState.data}
|
||||
mimeType={mimeType}
|
||||
langName={
|
||||
READABLE_TEXT_MIME_TYPES.includes(mimeType)
|
||||
? mimeTypeToExt(mimeType)
|
||||
: mimeTypeToExt(READABLE_EXT_TO_MIME_TYPE[getFileNameExt(body)] ?? mimeType)
|
||||
}
|
||||
requestClose={() => setTextViewer(false)}
|
||||
/>
|
||||
</Modal>
|
||||
|
|
@ -247,7 +256,8 @@ function DownloadFile({ body, mimeType, url, info, encInfo }: FileContentProps)
|
|||
export const FileContent = as<'div', FileContentProps>(
|
||||
({ body, mimeType, url, info, encInfo, ...props }, ref) => (
|
||||
<Box direction="Column" gap="300" {...props} ref={ref}>
|
||||
{READABLE_TEXT_MIME_TYPES.includes(mimeType) && (
|
||||
{(READABLE_TEXT_MIME_TYPES.includes(mimeType) ||
|
||||
READABLE_EXT_TO_MIME_TYPE[getFileNameExt(body)]) && (
|
||||
<ReadTextFile body={body} mimeType={mimeType} url={url} encInfo={encInfo} />
|
||||
)}
|
||||
{mimeType === 'application/pdf' && (
|
||||
|
|
|
|||
|
|
@ -246,7 +246,7 @@ export const MessageSourceCodeItem = as<
|
|||
<Modal variant="Surface" size="500">
|
||||
<TextViewer
|
||||
name="Source Code"
|
||||
mimeType="application/json"
|
||||
langName="json"
|
||||
text={text}
|
||||
requestClose={handleClose}
|
||||
/>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue