From 726300394b3561c24d217dc9bc97e6242d0f58f2 Mon Sep 17 00:00:00 2001 From: boojack <stevenlgtm@gmail.com> Date: Sun, 6 Aug 2023 10:38:39 +0800 Subject: [PATCH] chore: update image checks (#2092) --- web/src/components/ResourceIcon.tsx | 4 ++-- web/src/utils/resource.ts | 9 +++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/web/src/components/ResourceIcon.tsx b/web/src/components/ResourceIcon.tsx index 69b60117..32eb9804 100644 --- a/web/src/components/ResourceIcon.tsx +++ b/web/src/components/ResourceIcon.tsx @@ -1,5 +1,5 @@ import classNames from "classnames"; -import { getResourceUrl } from "@/utils/resource"; +import { getResourceType, getResourceUrl } from "@/utils/resource"; import Icon from "./Icon"; import showPreviewImageDialog from "./PreviewImageDialog"; import SquareDiv from "./kit/SquareDiv"; @@ -12,7 +12,7 @@ interface Props { const ResourceIcon = (props: Props) => { const { className, resource } = props; - if (resource.type.includes("image")) { + if (getResourceType(resource).startsWith("image")) { const url = getResourceUrl(resource); return ( <SquareDiv key={resource.id} className={classNames("cursor-pointer rounded hover:shadow", className)}> diff --git a/web/src/utils/resource.ts b/web/src/utils/resource.ts index 1216a125..36635eff 100644 --- a/web/src/utils/resource.ts +++ b/web/src/utils/resource.ts @@ -7,7 +7,7 @@ export const getResourceUrl = (resource: Resource, withOrigin = true) => { }; export const getResourceType = (resource: Resource) => { - if (resource.type.startsWith("image") && isImage(resource.type)) { + if (isImage(resource.type)) { return "image/*"; } else if (resource.type.startsWith("video")) { return "video/*"; @@ -34,5 +34,10 @@ export const getResourceType = (resource: Resource) => { // isImage returns true if the given mime type is an image. 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"; };