Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -12,52 +12,6 @@ import { JsonVisualizerRemote, JsonVisualizerValue } from "./JsonVisualizer";
import ParquetVisualizer from "./ParquetVisualizer";
import { TextVisualizerRemote, TextVisualizerValue } from "./TextVisualizer";

const VISUALIZABLE_TYPES = [
"text",
"image",
"jsonobject",
"jsonarray",
"csv",
"tsv",
"apacheparquet",
] as const;

type VisualizableType = (typeof VISUALIZABLE_TYPES)[number];

const TYPE_ALIASES: Record<string, VisualizableType> = {
txt: "text",
log: "text",
yaml: "text",
yml: "text",
xml: "text",
png: "image",
jpg: "image",
jpeg: "image",
gif: "image",
bmp: "image",
svg: "image",
json: "jsonobject",
parquet: "apacheparquet",
table: "apacheparquet",
};

export const normalizeRawType = (type?: string | null): string =>
(type ?? "text").toLowerCase().replace(/\s/g, "");

export const resolveArtifactType = (raw: string): string =>
TYPE_ALIASES[raw] ?? raw;

export const isVisualizableType = (type: string): type is VisualizableType =>
(VISUALIZABLE_TYPES as readonly string[]).includes(type);

export const inferTypeFromUri = (uri?: string | null): string | undefined => {
if (!uri) return undefined;
const stripped = uri.split(/[?#]/)[0];
const ext = stripped.split(".").pop()?.toLowerCase();
if (!ext) return undefined;
return TYPE_ALIASES[ext] ?? (isVisualizableType(ext) ? ext : undefined);
};

Comment on lines -15 to -60

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved to new file artifactType.ts

interface InlineContentProps {
type: string;
name: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@ import { getArtifactPreviewUrl } from "@/utils/URL";

import {
InlineContent,
isVisualizableType,
normalizeRawType,
PreviewContent,
PreviewSkeleton,
resolveArtifactType,
} from "./ArtifactPreviewContent";
import { ArtifactPreviewError } from "./ArtifactPreviewError";
import { ArtifactPreviewHeader } from "./ArtifactPreviewHeader";
import {
isVisualizableType,
normalizeRawType,
resolveArtifactType,
} from "./artifactType";

type ArtifactVisualizerProps = {
artifact: ArtifactNodeResponse;
Expand Down Expand Up @@ -165,6 +167,19 @@ const ArtifactVisualizer = ({
);
}

if (
error instanceof ArtifactFetchError &&
error.status === 413
) {
return (
<ArtifactPreviewError
title="Too large to preview"
preamble={error.message}
variant="warning"
/>
);
}

const statusDetail =
error instanceof ArtifactFetchError
? ` (${error.status}${error.statusText ? ` ${error.statusText}` : ""})`
Expand Down
Loading
Loading