Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix large file and png preview issues #4569

Merged
merged 3 commits into from
Nov 8, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion webui/src/lib/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -632,8 +632,11 @@ class Objects {
throw new Error(await extractError(response));
}

const responseBlob = await response.blob();
const responseText = await responseBlob.text();
return {
responseText: await response.text(),
responseText,
responseBlob,
headers: response.headers,
}
}
Expand Down
7 changes: 6 additions & 1 deletion webui/src/lib/components/repository/tree.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {Paginator} from "../pagination";
import {Link} from "../nav";
import {RefTypeBranch, RefTypeCommit} from "../../../constants";

const PREVIEW_SIZE_LIMIT = 4194304; // 4MB in bytes

export const humanSize = (bytes) => {
if (!bytes) return '0.0 B';
Expand Down Expand Up @@ -115,6 +116,10 @@ const EntryRow = ({repo, reference, path, entry, onDelete, showActions}) => {
ref: query.ref,
};

if (entry.size_bytes > PREVIEW_SIZE_LIMIT) {
filePathQuery["big"] = true;
}

button = (<Link href={{pathname: '/repositories/:repoId/objects/:objectName', query: filePathQuery, params: filePathParams}}>{buttonText}</Link>);
}

Expand Down Expand Up @@ -270,7 +275,7 @@ export const URINavigator = ({ repo, reference, path, relativeTo = "", pathURLBu
<Link href={pathURLBuilder(params, query)}>{part.name}</Link>
<strong>{'/'}</strong>
</>
)
);
return (
<span key={part.name}>
{edgeElement}
Expand Down
30 changes: 0 additions & 30 deletions webui/src/pages/repositories/repository/fileRenderers/index.jsx

This file was deleted.

65 changes: 65 additions & 0 deletions webui/src/pages/repositories/repository/fileRenderers/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import React, { FC } from "react";
import remarkGfm from 'remark-gfm'
import remarkHtml from 'remark-html'
import ReactMarkdown from 'react-markdown';
import { IpynbRenderer as NbRenderer } from "react-ipynb-renderer";

type RequireAtLeastOne<T, Keys extends keyof T = keyof T> = Pick<T, Exclude<keyof T, Keys>> & {
[K in Keys]-?: Required<Pick<T, K>> & Partial<Pick<T, Exclude<Keys, K>>>
}[Keys];

interface RendererComponentBase {
content: string;
contentBlob: Blob;
}

export type RendererComponent = RequireAtLeastOne<RendererComponentBase, 'content' | 'contentBlob'>;

export const MarkdownRenderer: FC<RendererComponent> = ({ content }) => {
if (content) {
return (
<ReactMarkdown remarkPlugins={[remarkGfm, remarkHtml]} linkTarget={"_blank"}>
{content}
</ReactMarkdown>
);
}
return null;
};

export const IpynbRenderer: FC<RendererComponent> = ({ content }) => {
if (content) {
return (
<NbRenderer
ipynb={JSON.parse(content)}
syntaxTheme="ghcolors"
language="python"
bgTransparent={true}
/>
);
}
return null;
};

export const ImageRenderer: FC<RendererComponent> = ({ contentBlob }) => {
if (contentBlob) {
return (
<img src={URL.createObjectURL(contentBlob)} />
);
}
return null;
}

export const supportedFileExtensionRenderers: Record<string, FC<RendererComponent>> = {
md: MarkdownRenderer,
ipynb: IpynbRenderer,
png: ImageRenderer,
jpg: ImageRenderer,
jpeg: ImageRenderer,
};

export const supportedContentTypeRenderers: Record<string, FC<RendererComponent>> = {
"application/x-ipynb+json": IpynbRenderer,
"text/markdown":MarkdownRenderer,
"image/png": ImageRenderer,
"image/jpeg": ImageRenderer,
};
152 changes: 0 additions & 152 deletions webui/src/pages/repositories/repository/objectViewer.jsx

This file was deleted.

Loading