From 986ecb2561f07910013addb10b296f19111b2ef7 Mon Sep 17 00:00:00 2001 From: ssdfasd <2156608475@qq.com> Date: Fri, 13 Mar 2026 20:31:54 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20ai=20=E6=A8=A1?= =?UTF-8?q?=E5=9D=97=E4=B8=AD=20Python=20=E8=84=9A=E6=9C=AC=E8=B7=AF?= =?UTF-8?q?=E5=BE=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 使用 PROJECT_ROOT 替代 __dirname 计算,确保打包后能正确找到 tools 文件夹 --- api/modules/ai/routes.ts | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/api/modules/ai/routes.ts b/api/modules/ai/routes.ts index 83a39db..fc90237 100644 --- a/api/modules/ai/routes.ts +++ b/api/modules/ai/routes.ts @@ -1,16 +1,13 @@ import express, { type Request, type Response } from 'express' import { spawn } from 'child_process' import path from 'path' -import { fileURLToPath } from 'url' import fs from 'fs/promises' import fsSync from 'fs' import { asyncHandler } from '../../utils/asyncHandler.js' import { successResponse } from '../../utils/response.js' import { resolveNotebookPath } from '../../utils/pathSafety.js' import { ValidationError, NotFoundError, InternalError } from '../../../shared/errors/index.js' - -const __filename = fileURLToPath(import.meta.url) -const __dirname = path.dirname(__filename) +import { PROJECT_ROOT } from '../../config/paths.js' const router = express.Router() @@ -89,8 +86,7 @@ router.post( const content = await fs.readFile(fullPath, 'utf-8') - const projectRoot = path.resolve(__dirname, '..', '..', '..') - const scriptPath = path.join(projectRoot, 'tools', 'doubao', 'main.py') + const scriptPath = path.join(PROJECT_ROOT, 'tools', 'doubao', 'main.py') if (!fsSync.existsSync(scriptPath)) { throw new InternalError(`Python script not found: ${scriptPath}`)