From 8efb4e71d919f42e615958fe3944f20613928685 Mon Sep 17 00:00:00 2001 From: EGOIST Date: Mon, 23 May 2022 18:54:48 +0800 Subject: [PATCH] Allow images from any domain --- src/markdown/plugin-image.ts | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/src/markdown/plugin-image.ts b/src/markdown/plugin-image.ts index a7ce5376..29d41b18 100644 --- a/src/markdown/plugin-image.ts +++ b/src/markdown/plugin-image.ts @@ -1,17 +1,8 @@ import Markdown from "markdown-it" -import { R2_URL } from "~/lib/env" import { getUserContentsUrl } from "~/lib/user-contents" const isExternLink = (url: string) => /^https?:\/\//.test(url) -const ALLOW_IMAGE_ORIGINS = [ - "user-images.githubusercontent.com", - "cdn.jsdelivr.net", - "images.unsplash.com", - "source.unsplash.com", - R2_URL.replace(/^https?\:\/\//, ""), -] - export const pluginImage = (md: Markdown) => { const imageRule = md.renderer.rules.image! md.renderer.rules.image = (tokens, idx, options, env, self) => { @@ -23,9 +14,8 @@ export const pluginImage = (md: Markdown) => { } if (isExternLink(url)) { - const { hostname } = new URL(url) - if (!ALLOW_IMAGE_ORIGINS.includes(hostname)) { - throw new Error(`Image from ${hostname} is not allowed`) + if (!url.startsWith("https:")) { + throw new Error(`External image url must start with https`) } return imageRule(tokens, idx, options, env, self) }