import { Modal } from "antd"; import { Button } from "~/components/ui/button"; import type { CheckVersionResponse } from "~/service/api/version/state"; const IGNORED_VERSIONS_KEY = "GOWVP_IGNORED_VERSIONS"; const MAX_IGNORED_VERSIONS = 3; interface VersionUpdateModalProps { versionInfo: CheckVersionResponse | null; onClose: () => void; } // 获取已忽略的版本列表 function getIgnoredVersions(): string[] { try { const stored = localStorage.getItem(IGNORED_VERSIONS_KEY); if (stored) { return JSON.parse(stored); } } catch { // ignore } return []; } // 添加忽略的版本 function addIgnoredVersion(version: string): void { const versions = getIgnoredVersions(); if (!versions.includes(version)) { versions.push(version); // 保持最多 3 个 while (versions.length > MAX_IGNORED_VERSIONS) { versions.shift(); } localStorage.setItem(IGNORED_VERSIONS_KEY, JSON.stringify(versions)); } } // 检查版本是否被忽略 export function isVersionIgnored(version: string): boolean { return getIgnoredVersions().includes(version); } // 简单的 Markdown 渲染(支持基本格式) function renderMarkdown(text: string): React.ReactNode { if (!text) return null; const lines = text.split("\n"); const elements: React.ReactNode[] = []; for (let i = 0; i < lines.length; i++) { const line = lines[i]; // 处理标题 if (line.startsWith("### ")) { elements.push(
{renderInlineMarkdown(line)}
, ); } return
{codeMatch[1]}
,
);
remaining = remaining.slice(codeMatch.index! + codeMatch[0].length);
} else {
parts.push(remaining);
break;
}
}
return parts.length === 1 ? parts[0] : <>{parts}>;
}
export default function VersionUpdateModal({
versionInfo,
onClose,
}: VersionUpdateModalProps) {
if (!versionInfo) return null;
const handleIgnore = () => {
addIgnoredVersion(versionInfo.new_version);
onClose();
};
const handleConfirm = (): void => {
// 直接关闭弹窗,不触发任何请求
onClose();
};
return (