From dac82d3cd0383bc0142211895edcec7367e51b40 Mon Sep 17 00:00:00 2001 From: lintsinghua Date: Sat, 15 Nov 2025 18:51:07 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E8=BF=90=E8=A1=8C?= =?UTF-8?q?=E6=97=B6=E9=85=8D=E7=BD=AE=E4=B8=8D=E7=94=9F=E6=95=88=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修改 repoScan.ts 使用 env.ts 中的运行时配置 - 修改 repoZipScan.ts 使用 env.ts 中的运行时配置 - 修改 CreateTaskDialog.tsx 使用 env.ts 中的 token 配置 - 确保 Web 界面修改的配置(如最大文件数量)能够立即生效 --- src/components/audit/CreateTaskDialog.tsx | 14 +++----------- src/features/projects/services/repoScan.ts | 13 +++++++------ src/features/projects/services/repoZipScan.ts | 5 +++-- 3 files changed, 13 insertions(+), 19 deletions(-) diff --git a/src/components/audit/CreateTaskDialog.tsx b/src/components/audit/CreateTaskDialog.tsx index 7922853..bb12e3c 100644 --- a/src/components/audit/CreateTaskDialog.tsx +++ b/src/components/audit/CreateTaskDialog.tsx @@ -25,6 +25,7 @@ import TerminalProgressDialog from "./TerminalProgressDialog"; import { runRepositoryAudit } from "@/features/projects/services/repoScan"; import { scanZipFile, validateZipFile } from "@/features/projects/services/repoZipScan"; import { loadZipFile } from "@/shared/utils/zipStorage"; +import { env } from "@/shared/config/env"; interface CreateTaskDialogProps { open: boolean; @@ -170,17 +171,8 @@ export default function CreateTaskDialog({ open, onOpenChange, onTaskCreated, pr console.log('📡 调用 runRepositoryAudit...'); // 从运行时配置中获取 Token - const getRuntimeConfig = () => { - try { - const saved = localStorage.getItem('xcodereviewer_runtime_config'); - return saved ? JSON.parse(saved) : null; - } catch { - return null; - } - }; - const runtimeConfig = getRuntimeConfig(); - const githubToken = runtimeConfig?.githubToken || (import.meta.env.VITE_GITHUB_TOKEN as string | undefined); - const gitlabToken = runtimeConfig?.gitlabToken || (import.meta.env.VITE_GITLAB_TOKEN as string | undefined); + const githubToken = env.GITHUB_TOKEN; + const gitlabToken = env.GITLAB_TOKEN; taskId = await runRepositoryAudit({ projectId: project.id, diff --git a/src/features/projects/services/repoScan.ts b/src/features/projects/services/repoScan.ts index d96065e..524ee6d 100644 --- a/src/features/projects/services/repoScan.ts +++ b/src/features/projects/services/repoScan.ts @@ -1,6 +1,7 @@ import { api } from "@/shared/config/database"; import { CodeAnalysisEngine } from "@/features/analysis/services"; import { taskControl } from "@/shared/services/taskControl"; +import { env } from "@/shared/config/env"; type GithubTreeItem = { path: string; type: "blob" | "tree"; size?: number; url: string; sha: string }; @@ -9,16 +10,16 @@ const TEXT_EXTENSIONS = [ // 注意:已移除 .md,因为文档文件会导致LLM返回非JSON格式 ]; const MAX_FILE_SIZE_BYTES = 200 * 1024; -const MAX_ANALYZE_FILES = Number(import.meta.env.VITE_MAX_ANALYZE_FILES || 40); -const LLM_CONCURRENCY = Number(import.meta.env.VITE_LLM_CONCURRENCY || 2); -const LLM_GAP_MS = Number(import.meta.env.VITE_LLM_GAP_MS || 500); +const MAX_ANALYZE_FILES = env.MAX_ANALYZE_FILES; +const LLM_CONCURRENCY = env.LLM_CONCURRENCY; +const LLM_GAP_MS = env.LLM_GAP_MS; const isTextFile = (p: string) => TEXT_EXTENSIONS.some(ext => p.toLowerCase().endsWith(ext)); const matchExclude = (p: string, ex: string[]) => ex.some(e => p.includes(e.replace(/^\//, "")) || (e.endsWith("/**") && p.startsWith(e.slice(0, -3).replace(/^\//, "")))); async function githubApi(url: string, token?: string): Promise { const headers: Record = { "Accept": "application/vnd.github+json" }; - const t = token || (import.meta.env.VITE_GITHUB_TOKEN as string | undefined); + const t = token || env.GITHUB_TOKEN; if (t) headers["Authorization"] = `Bearer ${t}`; const res = await fetch(url, { headers }); if (!res.ok) { @@ -30,7 +31,7 @@ async function githubApi(url: string, token?: string): Promise { async function gitlabApi(url: string, token?: string): Promise { const headers: Record = { "Content-Type": "application/json" }; - const t = token || (import.meta.env.VITE_GITLAB_TOKEN as string | undefined); + const t = token || env.GITLAB_TOKEN; if (t) { // 支持两种 token 格式: // 1. 标准 Personal Access Token (glpat-xxx) @@ -215,7 +216,7 @@ export async function runRepositoryAudit(params: { // 为 GitLab 添加认证 Token if (isGitLab) { // 优先使用从 URL 提取的 token,否则使用配置的 token - let token = params.gitlabToken || (import.meta.env.VITE_GITLAB_TOKEN as string | undefined); + let token = params.gitlabToken || env.GITLAB_TOKEN; // 如果 URL 中包含 OAuth2 token,提取它 if (repoUrl.includes('@')) { diff --git a/src/features/projects/services/repoZipScan.ts b/src/features/projects/services/repoZipScan.ts index 9710ef9..e274940 100644 --- a/src/features/projects/services/repoZipScan.ts +++ b/src/features/projects/services/repoZipScan.ts @@ -2,6 +2,7 @@ import { unzip } from "fflate"; import { CodeAnalysisEngine } from "@/features/analysis/services"; import { api } from "@/shared/config/database"; import { taskControl } from "@/shared/services/taskControl"; +import { env } from "@/shared/config/env"; const TEXT_EXTENSIONS = [ ".js", ".ts", ".tsx", ".jsx", ".py", ".java", ".go", ".rs", ".cpp", ".c", ".h", ".cc", ".hh", @@ -10,10 +11,10 @@ const TEXT_EXTENSIONS = [ ]; const MAX_FILE_SIZE_BYTES = 200 * 1024; // 200KB -const MAX_ANALYZE_FILES = 50; +const MAX_ANALYZE_FILES = env.MAX_ANALYZE_FILES; // 从环境变量读取配置,豆包等API需要更长的延迟 -const LLM_GAP_MS = Number(import.meta.env.VITE_LLM_GAP_MS) || 2000; // 默认2秒,避免API限流 +const LLM_GAP_MS = env.LLM_GAP_MS || 2000; // 默认2秒,避免API限流 function isTextFile(path: string): boolean { return TEXT_EXTENSIONS.some(ext => path.toLowerCase().endsWith(ext));