fix: 修复运行时配置不生效的问题

- 修改 repoScan.ts 使用 env.ts 中的运行时配置
- 修改 repoZipScan.ts 使用 env.ts 中的运行时配置
- 修改 CreateTaskDialog.tsx 使用 env.ts 中的 token 配置
- 确保 Web 界面修改的配置(如最大文件数量)能够立即生效
This commit is contained in:
lintsinghua 2025-11-15 18:51:07 +08:00
parent 30f670bfd3
commit dac82d3cd0
3 changed files with 13 additions and 19 deletions

View File

@ -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,

View File

@ -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<T>(url: string, token?: string): Promise<T> {
const headers: Record<string, string> = { "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<T>(url: string, token?: string): Promise<T> {
async function gitlabApi<T>(url: string, token?: string): Promise<T> {
const headers: Record<string, string> = { "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('@')) {

View File

@ -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));