MCPcopy
hub / github.com/marktext/marktext / checkImageContentType

Function checkImageContentType

packages/muya/src/utils/image.ts:103–121  ·  view source on GitHub ↗
(url: string)

Source from the content-addressed store, hash-verified

101}
102
103export async function checkImageContentType(url: string) {
104 try {
105 const res = await fetch(url, { method: 'HEAD' });
106 const contentType = res.headers.get('content-type');
107
108 if (
109 contentType
110 && res.status === 200
111 && /^image\/(?:jpeg|png|gif|svg\+xml|webp)$/.test(contentType)
112 ) {
113 return true;
114 }
115
116 return false;
117 }
118 catch {
119 return false;
120 }
121}
122
123export function correctImageSrc(src: string) {
124 if (src) {

Callers 1

loadImageFunction · 0.70

Calls 1

getMethod · 0.80

Tested by

no test coverage detected