返回 DeepSeek-Reasonix
markdownImage.ts
根目录 / desktop / frontend / src / lib / markdownImage.ts
1 export const REMOTE_MARKDOWN_IMAGE_PATH = "/__reasonix_remote_markdown_image";
2
3 function runningInWailsShell(): boolean {
4 return typeof window !== "undefined" && window.runtime != null;
5 }
6
7 // WebView2 runs without the Windows system proxy. Route only absolute remote
8 // Markdown images back through the local Wails asset server; relative, data,
9 // blob, and workspace-media URLs remain local and unchanged.
10 export function markdownImageSource(src: string | undefined, nativeShell = runningInWailsShell()): string {
11 const value = src?.trim() ?? "";
12 if (!nativeShell || value === "") return value;
13
14 let remoteURL = value;
15 if (value.startsWith("//")) {
16 const protocol = typeof window !== "undefined" && /^https?:$/.test(window.location.protocol)
17 ? window.location.protocol
18 : "https:";
19 remoteURL = protocol + value;
20 } else if (!/^https?:\/\//i.test(value)) {
21 return value;
22 }
23
24 return `${REMOTE_MARKDOWN_IMAGE_PATH}?url=${encodeURIComponent(remoteURL)}`;
25 }
26
26 lines TYPESCRIPT