From cbbf5e2877cf4a290fe1b3cc36dab914b5c7516d Mon Sep 17 00:00:00 2001 From: ma-zhongxu Date: Wed, 5 Mar 2025 16:10:27 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=87=E4=BB=B6=E4=B8=8A=E4=BC=A0=E7=9A=84?= =?UTF-8?q?=E8=B7=AF=E5=BE=84=E9=97=AE=E9=A2=98,=E6=9C=AC=E5=9C=B0?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E5=8F=AF=E4=BB=A5=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- collector/index.js | 6 +++++- collector/utils/constants.js | 4 +++- frontend/src/utils/constants.js | 4 ++-- server/endpoints/workspaces.js | 5 ----- server/models/workspace.js | 1 - server/utils/files/index.js | 8 ++++++-- server/utils/files/multer.js | 18 ++++++------------ 7 files changed, 22 insertions(+), 24 deletions(-) diff --git a/collector/index.js b/collector/index.js index 8f3edab..0339360 100644 --- a/collector/index.js +++ b/collector/index.js @@ -72,7 +72,11 @@ app.post( const targetFilename = path .normalize(filename) .replace(/^(\.\.(\/|\\|$))+/, ""); - const inputPath = path.resolve("./hotdir"); + // const inputPath = path.resolve("./hotdir"); + const inputPath = process.env.NODE_ENV === "development" + ? path.resolve("../server/storage/hotdir") + : path.resolve("/app/server/storage/hotdir"); + console.log("输入路径:(((((((((((((((((((((((((((((((((((((((((:", inputPath,filename); const sourceFile = path.join(inputPath, filename); // 拼接文件路径 console.log("源文件路径:", sourceFile); diff --git a/collector/utils/constants.js b/collector/utils/constants.js index 236fc2f..e4e3f63 100644 --- a/collector/utils/constants.js +++ b/collector/utils/constants.js @@ -1,4 +1,6 @@ -const WATCH_DIRECTORY = require("path").resolve(__dirname, "../hotdir"); +const WATCH_DIRECTORY = process.env.NODE_ENV === "development" + ? require("path").resolve(__dirname, "../../server/storage/hotdir") + : require("path").resolve(__dirname, "../../../../app/server/storage/hotdir"); const ACCEPTED_MIMES = { "text/plain": [".txt", ".md", ".org", ".adoc", ".rst"], diff --git a/frontend/src/utils/constants.js b/frontend/src/utils/constants.js index 5d532c3..d84b9db 100644 --- a/frontend/src/utils/constants.js +++ b/frontend/src/utils/constants.js @@ -1,5 +1,5 @@ -// export const API_BASE = import.meta.env.VITE_API_BASE || "/api"; -export const API_BASE = 'http://172.16.2.9:3001/api' +export const API_BASE = import.meta.env.VITE_API_BASE || "/api"; +// export const API_BASE = 'http://172.16.2.9:3001/api' export const ONBOARDING_SURVEY_URL = "https://onboarding.anythingllm.com"; export const AUTH_USER = "anythingllm_user"; diff --git a/server/endpoints/workspaces.js b/server/endpoints/workspaces.js index f39b56c..b74379a 100644 --- a/server/endpoints/workspaces.js +++ b/server/endpoints/workspaces.js @@ -283,7 +283,6 @@ function workspaceEndpoints(app) { process.env.NODE_ENV === "development" ? path.resolve(__dirname, "../../server/storage/localFile") : path.resolve(process.env.STORAGE_DIR, "localFile"); - // 确保目标目录存在 if (!fs.existsSync(targetDir)) { fs.mkdirSync(targetDir, { recursive: true }); // 递归创建目录 @@ -294,7 +293,6 @@ function workspaceEndpoints(app) { const fileBuffer = Buffer.from(fileContent, "base64"); fs.writeFileSync(filePath, fileBuffer); - console.log(`文件保存成功!路径:${filePath}`); // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // 假设路径字符串 const location = documents[0].location; @@ -305,9 +303,7 @@ function workspaceEndpoints(app) { // 提取文件名 const parsedFileName = unixStylePath.substring(lastIndex + 1); const fileExtension = path.extname(request.file.path).toLowerCase(); - const sourceFile = path.resolve(__dirname, request.file.destination, request.file.originalname); const newFileName = uuidv4() + fileExtension; // 新文件名 - moveAndRenameFile(sourceFile, targetDir, newFileName); const deptDocData = { deptId: deptUserRecord.deptUser.deptId, parsedFileName: parsedFileName, @@ -543,7 +539,6 @@ function workspaceEndpoints(app) { const workspace = multiUserMode(response) ? await Workspace.getWithUser(user, { slug }) : await Workspace.get({ slug }); - console.log("workspace++++++++++++++++++++++++++++", workspace); response.status(200).json({ workspace }); } catch (e) { console.error(e.message, e); diff --git a/server/models/workspace.js b/server/models/workspace.js index f5b8593..bdfbda2 100644 --- a/server/models/workspace.js +++ b/server/models/workspace.js @@ -278,7 +278,6 @@ const Workspace = { documents: true, }, }); - console.log("0000000000000000000000000000000000000000000000000000000000000000",workspace); return workspace || null; } catch (error) { diff --git a/server/utils/files/index.js b/server/utils/files/index.js index 48e8938..b0c8867 100644 --- a/server/utils/files/index.js +++ b/server/utils/files/index.js @@ -202,8 +202,12 @@ async function viewLocalFiles(deptId) { // 遍历 deptDocuments for (const doc of deptDocuments) { try { - const filePath = doc.parsedFilePath; // 获取文件路径 - if (!fs.existsSync(filePath)) continue; // 如果文件不存在,跳过 + let filePath = doc.parsedFilePath; // 获取文件路径 + if (!fs.existsSync(filePath)) { + filePath = process.env.NODE_ENV === "development" + ? filePath + : path.resolve(process.env.STORAGE_DIR, "documents", filePath); + } // 读取文件内容 const rawData = fs.readFileSync(filePath, 'utf8'); diff --git a/server/utils/files/multer.js b/server/utils/files/multer.js index 81f8361..965769f 100644 --- a/server/utils/files/multer.js +++ b/server/utils/files/multer.js @@ -10,12 +10,10 @@ const { normalizePath } = require("."); */ const fileUploadStorage = multer.diskStorage({ destination: function (_, __, cb) { - console.log("进来了进来了进来了::::",process.env.NODE_ENV); const uploadOutput = - process.env.NODE_ENV === "development" - ? path.resolve(__dirname, `../../../collector/hotdir`) - : path.resolve(process.env.STORAGE_DIR, `../../collector/hotdir`); - console.log("又来了又来了又来了:::",uploadOutput) + process.env.NODE_ENV ==="development" + ? path.resolve(__dirname, "../../storage/hotdir") + : path.resolve(process.env.STORAGE_DIR, "hotdir"); cb(null, uploadOutput); }, filename: function (_, file, cb) { @@ -33,9 +31,9 @@ const fileUploadStorage = multer.diskStorage({ const fileAPIUploadStorage = multer.diskStorage({ destination: function (_, __, cb) { const uploadOutput = - process.env.NODE_ENV === "development" - ? path.resolve(__dirname, `../../../collector/hotdir`) - : path.resolve(process.env.STORAGE_DIR, `../../collector/hotdir`); + process.env.NODE_ENV ==="development" + ? path.resolve(__dirname, "../../storage/hotdir") + : path.resolve(process.env.STORAGE_DIR, "hotdir"); cb(null, uploadOutput); }, filename: function (_, file, cb) { @@ -174,13 +172,10 @@ function handlePfpUpload(request, response, next) { const commUploadStorage = multer.diskStorage({ destination: async function (_, __, cb) { try { - // const uploadOutput = "D:\\code2\\anything-llm-master\\server\\storage\\real"; - console.log("进来了进来了进来了::::",process.env.NODE_ENV); const uploadOutput = process.env.NODE_ENV === "development" ? path.resolve(__dirname, `../../../server/storage/localFile`) : path.resolve(process.env.STORAGE_DIR, `../../server/storage/localFile`); - console.log("又来了又来了又来了:::",uploadOutput) if (process.env.NODE_ENV !== "development" && !process.env.STORAGE_DIR) { throw new Error("STORAGE_DIR environment variable is required in production."); @@ -201,7 +196,6 @@ const commUploadStorage = multer.diskStorage({ // 文件上传中间件 function handleCommUpload(request, response, next) { - console.log("进来了进来了"); const upload = multer({ storage: commUploadStorage, limits: { fileSize: 100 * 1024 * 1024 }, }).single("file"); upload(request, response, function (err) {