Unverified Commit 72630039 authored by boojack's avatar boojack Committed by GitHub

chore: update image checks (#2092)

parent 5d5d8de9
import classNames from "classnames"; import classNames from "classnames";
import { getResourceUrl } from "@/utils/resource"; import { getResourceType, getResourceUrl } from "@/utils/resource";
import Icon from "./Icon"; import Icon from "./Icon";
import showPreviewImageDialog from "./PreviewImageDialog"; import showPreviewImageDialog from "./PreviewImageDialog";
import SquareDiv from "./kit/SquareDiv"; import SquareDiv from "./kit/SquareDiv";
...@@ -12,7 +12,7 @@ interface Props { ...@@ -12,7 +12,7 @@ interface Props {
const ResourceIcon = (props: Props) => { const ResourceIcon = (props: Props) => {
const { className, resource } = props; const { className, resource } = props;
if (resource.type.includes("image")) { if (getResourceType(resource).startsWith("image")) {
const url = getResourceUrl(resource); const url = getResourceUrl(resource);
return ( return (
<SquareDiv key={resource.id} className={classNames("cursor-pointer rounded hover:shadow", className)}> <SquareDiv key={resource.id} className={classNames("cursor-pointer rounded hover:shadow", className)}>
......
...@@ -7,7 +7,7 @@ export const getResourceUrl = (resource: Resource, withOrigin = true) => { ...@@ -7,7 +7,7 @@ export const getResourceUrl = (resource: Resource, withOrigin = true) => {
}; };
export const getResourceType = (resource: Resource) => { export const getResourceType = (resource: Resource) => {
if (resource.type.startsWith("image") && isImage(resource.type)) { if (isImage(resource.type)) {
return "image/*"; return "image/*";
} else if (resource.type.startsWith("video")) { } else if (resource.type.startsWith("video")) {
return "video/*"; return "video/*";
...@@ -34,5 +34,10 @@ export const getResourceType = (resource: Resource) => { ...@@ -34,5 +34,10 @@ export const getResourceType = (resource: Resource) => {
// isImage returns true if the given mime type is an image. // isImage returns true if the given mime type is an image.
export const isImage = (t: string) => { export const isImage = (t: string) => {
return t === "image/jpeg" || t === "image/png" || t === "image/gif" || t === "image/svg+xml" || t === "image/webp"; // Don't show PSDs as images.
return t.startsWith("image/") && !isPSD(t);
};
const isPSD = (t: string) => {
return t === "image/vnd.adobe.photoshop" || t === "image/x-photoshop" || t === "image/photoshop";
}; };
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment