fix: avoid cors error, avoid permission folder error (#59)

This commit is contained in:
Wendong-Fan 2025-08-03 23:22:04 +08:00 committed by GitHub
commit fd62230c46
3 changed files with 27 additions and 3 deletions

View file

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

View file

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

View file

@ -63,10 +63,18 @@ export async function getBinaryPath(name?: string): Promise<string> {
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<boolean> {
const cmd = await getBinaryPath(name)