From c209f7b4599dde61bf87224092b63cf49debb6e5 Mon Sep 17 00:00:00 2001 From: luo Date: Sun, 3 Aug 2025 16:35:14 +0800 Subject: [PATCH 1/2] fix: avoid cors error --- backend/app/__init__.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/backend/app/__init__.py b/backend/app/__init__.py index 5d97950fb..ddd4b1f93 100644 --- a/backend/app/__init__.py +++ b/backend/app/__init__.py @@ -1,4 +1,8 @@ from fastapi import FastAPI +from fastapi.middleware.cors import CORSMiddleware api = FastAPI() +api.add_middleware( + CORSMiddleware, allow_origins=["*"], allow_credentials=True, allow_methods=["*"], allow_headers=["*"] +) From 85b6539a17fa85894ab0d3cb5941f9b1d7100909 Mon Sep 17 00:00:00 2001 From: luo Date: Sun, 3 Aug 2025 17:43:23 +0800 Subject: [PATCH 2/2] fix: avoid folder permission problem --- electron/main/init.ts | 16 ++++++++++++++-- electron/main/utils/process.ts | 10 +++++++++- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/electron/main/init.ts b/electron/main/init.ts index 3059f5800..05a297723 100644 --- a/electron/main/init.ts +++ b/electron/main/init.ts @@ -1,4 +1,4 @@ -import { getBackendPath, getBinaryPath, isBinaryExists, runInstallScript } from "./utils/process"; +import { getBackendPath, getBinaryPath, getCachePath, isBinaryExists, runInstallScript } from "./utils/process"; import { spawn, exec } from 'child_process' import log from 'electron-log' import fs from 'fs' @@ -105,7 +105,19 @@ export async function installDependencies() { return timezone === 'Asia/Shanghai'; } console.log('isInChinaTimezone', isInChinaTimezone()) - const node_process = spawn(uv_path, ['sync', '--no-dev', ...(isInChinaTimezone() ? proxy : [])], { cwd: backendPath }) + + const node_process = spawn(uv_path, [ + 'sync', + '--no-dev', + '--cache-dir', getCachePath('uv_cache'), + ...(isInChinaTimezone() ? proxy : [])], { + cwd: backendPath, + env: { + ...process.env, + UV_TOOL_DIR: getCachePath('uv_tool'), + UV_PYTHON_INSTALL_DIR: getCachePath('uv_python'), + } + }) node_process.stdout.on('data', (data) => { log.info(`Script output: ${data}`) // notify frontend install log diff --git a/electron/main/utils/process.ts b/electron/main/utils/process.ts index bd4f1b4ed..5d1bcd437 100644 --- a/electron/main/utils/process.ts +++ b/electron/main/utils/process.ts @@ -63,10 +63,18 @@ export async function getBinaryPath(name?: string): Promise { const binaryName = await getBinaryName(name) const binariesDir = path.join(os.homedir(), '.eigent', 'bin') const binariesDirExists = await fs.existsSync(binariesDir) - + return binariesDirExists ? path.join(binariesDir, binaryName) : binaryName } +export function getCachePath(folder: string): string { + const cacheDir = path.join(os.homedir(), '.eigent', 'cache', folder) + console.log('cacheDir+++++++++++++++++++++++++++') + console.log('Cache directory:', cacheDir) + console.log('cacheDir--------------------') + return cacheDir +} + export async function isBinaryExists(name: string): Promise { const cmd = await getBinaryPath(name)