diff --git a/src/main/window.ts b/src/main/window.ts index 467f96359c..42a92022b2 100644 --- a/src/main/window.ts +++ b/src/main/window.ts @@ -3,6 +3,7 @@ import { fileURLToPath } from "node:url" import { is } from "@electron-toolkit/utils" import { callGlobalContextMethod } from "@shared/bridge" +import { imageRefererMatches } from "@shared/image" import type { BrowserWindowConstructorOptions } from "electron" import { BrowserWindow, Menu, shell } from "electron" @@ -106,16 +107,6 @@ export function createWindow( }) } - const refererMatchs = [ - { - url: /^https:\/\/\w+\.sinaimg.cn/, - referer: "https://weibo.com", - }, - { - url: /^https:\/\/i\.pximg\.net/, - referer: "https://www.pixiv.net", - }, - ] window.webContents.session.webRequest.onBeforeSendHeaders( (details, callback) => { const trueUrl = @@ -130,7 +121,9 @@ export function createWindow( ), ) : details.url - const refererMatch = refererMatchs.find((item) => item.url.test(trueUrl)) + const refererMatch = imageRefererMatches.find((item) => + item.url.test(trueUrl), + ) callback({ requestHeaders: { ...details.requestHeaders, diff --git a/src/renderer/src/components/ui/markdown/renderers/BlockImage.tsx b/src/renderer/src/components/ui/markdown/renderers/BlockImage.tsx index d277bd49bd..4989e80d39 100644 --- a/src/renderer/src/components/ui/markdown/renderers/BlockImage.tsx +++ b/src/renderer/src/components/ui/markdown/renderers/BlockImage.tsx @@ -4,7 +4,12 @@ import { useWrappedElementSize } from "@renderer/providers/wrapped-element-provi import { Media } from "../../media" export const MarkdownBlockImage = ( - props: React.ImgHTMLAttributes, + props: React.ImgHTMLAttributes & { + proxy?: { + width: number + height: number + } + }, ) => { const size = useWrappedElementSize() diff --git a/src/renderer/src/components/ui/media.tsx b/src/renderer/src/components/ui/media.tsx index 1b25255e62..55c6a4dada 100644 --- a/src/renderer/src/components/ui/media.tsx +++ b/src/renderer/src/components/ui/media.tsx @@ -47,7 +47,7 @@ const MediaImpl: FC = ({ }) => { const { src, style, type, previewImageUrl, ...rest } = props const [hidden, setHidden] = useState(!src) - const [imgSrc, setImgSrc] = useState( + const [imgSrc, setImgSrc] = useState(() => proxy && src && !failedList.has(src) ? getProxyUrl({ url: src, diff --git a/src/renderer/src/components/ui/media/preview-media.tsx b/src/renderer/src/components/ui/media/preview-media.tsx index 5a36dfe52a..c868b689a8 100644 --- a/src/renderer/src/components/ui/media/preview-media.tsx +++ b/src/renderer/src/components/ui/media/preview-media.tsx @@ -2,14 +2,15 @@ import { m } from "@renderer/components/common/Motion" import { COPY_MAP } from "@renderer/constants" import { tipcClient } from "@renderer/lib/client" import { stopPropagation } from "@renderer/lib/dom" +import { replaceImgUrlIfNeed } from "@renderer/lib/img-proxy" import { showNativeMenu } from "@renderer/lib/native-menu" import type { FC } from "react" -import { useCallback, useState } from "react" +import { Fragment, useCallback, useState } from "react" import type { MediaModel } from "src/hono" import { Keyboard, Mousewheel, Scrollbar } from "swiper/modules" import { Swiper, SwiperSlide } from "swiper/react" -import { ActionButton } from "../button" +import { ActionButton, MotionButtonBase } from "../button" import { microReboundPreset } from "../constants/spring" import { useCurrentModal } from "../modal" @@ -112,7 +113,7 @@ export const PreviewMediaContent: FC<{ onClick={(e) => e.stopPropagation()} /> ) : ( - cover {media.map((med, index) => ( - + {med.type === "video" ? (