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=["*"] +) 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)