Skip to content

Commit

Permalink
fix: identify image MIME type error
Browse files Browse the repository at this point in the history
  • Loading branch information
qq15725 committed Feb 1, 2023
1 parent 66d18d1 commit 41aa601
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { consoleWarn } from './log'

export const IN_BROWSER = typeof window !== 'undefined'
export const isElementNode = (node: Node): node is Element => node.nodeType === 1 // Node.ELEMENT_NODE
export const isSVGElementNode = (node: Element): node is SVGElement => typeof (node as SVGElement).className === 'object'
Expand Down Expand Up @@ -116,7 +118,7 @@ export function loadMedia(media: any, options?: LoadMediaOptions): Promise<any>
if (isSVGImageElementNode(node)) {
resolve(node)
} else {
node.decode().then(() => resolve(node))
node.decode().catch(consoleWarn).finally(() => resolve(node))
}
},
{ once: true },
Expand Down Expand Up @@ -163,9 +165,8 @@ const MIMES = {

const EXT_RE = /\.([^.\/]+?)$/

export function getMimeType(url: string): string {
const ext = url.match(EXT_RE)?.[1]?.toLowerCase()
return MIMES[ext as keyof typeof MIMES] ?? ext
export function getMimeType(url: string): string | undefined {
return MIMES[new URL(url).pathname.match(EXT_RE)?.[1]?.toLowerCase() as keyof typeof MIMES]
}

export async function waitLoaded(el: HTMLElement, timeout?: number) {
Expand Down

1 comment on commit 41aa601

@vercel
Copy link

@vercel vercel bot commented on 41aa601 Feb 1, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

modern-screenshot – ./

modern-screenshot-git-master-qq15725.vercel.app
modern-screenshot-qq15725.vercel.app
modern-screenshot.vercel.app

Please sign in to comment.