(url: string)
| 101 | } |
| 102 | |
| 103 | export 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 | |
| 123 | export function correctImageSrc(src: string) { |
| 124 | if (src) { |