From b7b165c860c17fc3cfff76f2edd3b6a3506041c1 Mon Sep 17 00:00:00 2001 From: a12110 Date: Sun, 12 Apr 2026 17:00:33 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0:=20=E5=88=A0=E9=99=A4=20?= =?UTF-8?q?=E9=80=9A=E8=BF=87=20.env=20=E8=AF=BB=E5=85=A5=20ossurl=20?= =?UTF-8?q?=E7=8E=AF=E5=A2=83=E5=8F=98=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env | 1 - .gitignore | 1 + src/env.ts | 10 ---------- src/utils/oss.ts | 2 +- 4 files changed, 2 insertions(+), 12 deletions(-) delete mode 100644 .env diff --git a/.env b/.env deleted file mode 100644 index 4ea20d2..0000000 --- a/.env +++ /dev/null @@ -1 +0,0 @@ -ossURL= \ No newline at end of file diff --git a/.gitignore b/.gitignore index 1575956..f5aa258 100644 --- a/.gitignore +++ b/.gitignore @@ -17,6 +17,7 @@ _.log report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json # dotenv environment variable files +.env .env.development.local .env.test.local .env.production.local diff --git a/src/env.ts b/src/env.ts index 09af65c..db8f322 100644 --- a/src/env.ts +++ b/src/env.ts @@ -1,6 +1,3 @@ -import dotenv from "dotenv"; -import path from "node:path"; - // 判断是否为打包后的 Electron 环境 const isElectron = typeof process.versions?.electron !== "undefined"; let isPackaged = false; @@ -9,13 +6,6 @@ if (isElectron) { isPackaged = app.isPackaged; } -// 仅在非 Electron 环境加载 .env(例如 Docker / Web 后端) -if (!isElectron) { - dotenv.config({ - path: path.resolve(process.cwd(), ".env"), - }); -} - //加载环境变量(打包环境默认使用 prod) const env = process.env.NODE_ENV; if (!env) { diff --git a/src/utils/oss.ts b/src/utils/oss.ts index d53dbfd..e95ed21 100644 --- a/src/utils/oss.ts +++ b/src/utils/oss.ts @@ -51,7 +51,7 @@ class OSS { const safePath = normalizeUserPath(userRelPath); // URL 始终使用 /,所以这里需要将系统分隔符转回 / let url = `/${prefix}/`; - if (!process.env.ossURL || process.env.ossURL != "") url = process.env.ossURL + `/${prefix}/`; + if (process.env.ossURL && process.env.ossURL !== "") url = process.env.ossURL + `/${prefix}/`; if (process.env.NODE_ENV == "dev") url = `http://localhost:10588/${prefix}/`; if (isEletron()) url = `http://localhost:${process.env.PORT}/${prefix}/`; return `${url}${safePath.split(path.sep).join("/")}`;