diff --git a/backend/.env.example b/backend/.env.example index 37b592d..69e54d9 100644 --- a/backend/.env.example +++ b/backend/.env.example @@ -55,7 +55,7 @@ LOCAL_DB_QUERY_TIMEOUT_MS=60000 # 生产环境由部署脚本强制使用 /www/wwwroot/shujuku3/shared/image-search-secrets.json # 本地留空时使用 ~/.config/shujuku3/secrets.json SHUJUKU3_SECRET_STORE_PATH= -# 生产环境默认开启;公司图搜或 1688 图搜凭据缺失时拒绝启动 +# 可选:设为 true 时要求公司图搜和 1688 图搜凭据齐全 REQUIRE_PERSISTED_IMAGE_SEARCH_SECRETS=false # 系统库连接池建议保持小而稳,避免单个应用实例吃满 MySQL 连接 LOCAL_DB_CONNECTION_LIMIT=6 diff --git a/backend/src/services/imageSearchCredentialGuard.js b/backend/src/services/imageSearchCredentialGuard.js index bdda5d2..fa0007f 100644 --- a/backend/src/services/imageSearchCredentialGuard.js +++ b/backend/src/services/imageSearchCredentialGuard.js @@ -4,7 +4,7 @@ const { getAlibaba1688ImageSearchRuntimeConfig } = require('./alibaba1688ImageSe const { getSimilarProductsRuntimeConfig } = require('./similarProductsSettings'); function shouldRequireImageSearchCredentials() { - if (String(process.env.NODE_ENV || '').trim().toLowerCase() === 'production') return true; + // Image search is an optional integration in the PDD edition. const configured = String(process.env.REQUIRE_PERSISTED_IMAGE_SEARCH_SECRETS || '').trim().toLowerCase(); return configured === 'true' || configured === '1'; } diff --git a/backend/test/imageSearchCredentialGuard.test.js b/backend/test/imageSearchCredentialGuard.test.js index 35e3f21..cca5394 100644 --- a/backend/test/imageSearchCredentialGuard.test.js +++ b/backend/test/imageSearchCredentialGuard.test.js @@ -5,7 +5,7 @@ const assert = require('node:assert/strict'); const { shouldRequireImageSearchCredentials } = require('../src/services/imageSearchCredentialGuard'); -test('production requires persisted image-search credentials by default', (context) => { +test('optional image search never blocks production unless explicitly required', (context) => { const previousNodeEnv = process.env.NODE_ENV; const previousRequirement = process.env.REQUIRE_PERSISTED_IMAGE_SEARCH_SECRETS; context.after(() => { @@ -17,9 +17,9 @@ test('production requires persisted image-search credentials by default', (conte process.env.NODE_ENV = 'production'; delete process.env.REQUIRE_PERSISTED_IMAGE_SEARCH_SECRETS; - assert.equal(shouldRequireImageSearchCredentials(), true); + assert.equal(shouldRequireImageSearchCredentials(), false); process.env.REQUIRE_PERSISTED_IMAGE_SEARCH_SECRETS = 'false'; - assert.equal(shouldRequireImageSearchCredentials(), true); + assert.equal(shouldRequireImageSearchCredentials(), false); process.env.NODE_ENV = 'development'; delete process.env.REQUIRE_PERSISTED_IMAGE_SEARCH_SECRETS;