From 1db643daaa6536723290ee85b2021e566b1f4d11 Mon Sep 17 00:00:00 2001 From: chenpei Date: Wed, 26 Aug 2026 15:11:03 +0800 Subject: [PATCH] =?UTF-8?q?=E9=83=A8=E7=BD=B2=E9=85=8D=E7=BD=AE=E6=AD=A3?= =?UTF-8?q?=E5=BC=8F=E7=99=BB=E8=AE=B0=E5=AE=B6=E5=85=B7=E4=B8=9A=E5=8A=A1?= =?UTF-8?q?=E7=B3=BB=E7=BB=9F=E5=B9=B6=E4=BF=9D=E7=95=99=E6=9C=AA=E5=88=97?= =?UTF-8?q?=E5=87=BA=E7=9A=84=E5=B7=B2=E7=99=BB=E8=AE=B0=E9=A1=B9=E7=9B=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.example | 2 +- scripts/deploy-material-host.sh | 20 ++++++++++++++++++++ src/__tests__/deployment.test.ts | 5 +++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/.env.example b/.env.example index 35df98b..8a26b8a 100644 --- a/.env.example +++ b/.env.example @@ -16,7 +16,7 @@ DINGTALK_LOGIN_TICKET_TTL_SECONDS=60 # 每个项目必须使用不同密钥;allowedHosts 用于限制卡片跳转域名。 # login 省略或 enabled=false 时保持原直接跳转,不启用免登中转。 # 生产环境请使用足够长的随机密钥,不要把真实值提交到 Git。 -YYD_NOTIFICATION_PROJECTS_JSON=[{"code":"material_library","name":"素材库","secret":"replace-with-random-secret","allowedHosts":["sc.example.com"]},{"code":"fixed_asset","name":"固定资产","secret":"replace-with-another-random-secret","allowedHosts":["asset.example.com"],"login":{"enabled":true,"callbackUrl":"https://asset.example.com/api/dingtalk/broker-login","allowedRedirectPathPrefixes":["/workflows/disposals","/dashboard"]}}] +YYD_NOTIFICATION_PROJECTS_JSON=[{"code":"material_library","name":"素材库","secret":"replace-with-random-secret","allowedHosts":["sc.example.com"]},{"code":"fixed_asset","name":"固定资产","secret":"replace-with-another-random-secret","allowedHosts":["asset.example.com"],"login":{"enabled":true,"callbackUrl":"https://asset.example.com/api/dingtalk/broker-login","allowedRedirectPathPrefixes":["/workflows/disposals","/dashboard"]}},{"code":"furniture_platform","name":"家具业务系统","secret":"replace-with-furniture-random-secret","allowedHosts":["cp.example.com"]}] WORKER_ENABLED=true WORKER_INTERVAL_MS=1000 diff --git a/scripts/deploy-material-host.sh b/scripts/deploy-material-host.sh index da24664..a0e5761 100644 --- a/scripts/deploy-material-host.sh +++ b/scripts/deploy-material-host.sh @@ -185,7 +185,27 @@ projects = [ '/inventory', ], ), + project_with_preserved_login( + 'furniture_platform', + '家具业务系统', + ['cp.jiansun.vip'], + ), ] + +# 兜底:生产 .env 里已登记、但上面清单未列出的项目原样保留, +# 避免重新部署时把手动登记的接入方从初始化配置中覆盖丢失。 +known_codes = {item['code'] for item in projects} +for item in old_projects: + if not isinstance(item, dict): + continue + code = str(item.get('code') or '').strip() + if not code or code in known_codes: + continue + if len(str(item.get('secret') or '')) < 24: + continue + projects.append(dict(item)) + known_codes.add(code) + if any(item.get('login', {}).get('enabled') is True for item in projects) and not corp_id: raise SystemExit('已有项目启用了免登中转,但生产配置缺少 DINGTALK_CORP_ID') diff --git a/src/__tests__/deployment.test.ts b/src/__tests__/deployment.test.ts index 30c9961..f35f948 100644 --- a/src/__tests__/deployment.test.ts +++ b/src/__tests__/deployment.test.ts @@ -21,6 +21,11 @@ test('生产发布面透传免登配置并保留已有项目 login', () => { assert.match(deploy, /old_login = by_code\.get\(code, \{\}\)\.get\('login'\)/) assert.match(deploy, /def project_with_preserved_login/) assert.match(deploy, /project\['login'\] = login/) + // 家具系统已接入生产;正式登记进初始化清单,防止重部署覆盖。 + assert.match(deploy, /'furniture_platform'/) + assert.match(deploy, /'家具业务系统'/) + // 未列出的已登记项目必须原样保留,杜绝同类覆盖事故。 + assert.match(deploy, /known_codes = \{item\['code'\] for item in projects\}/) assert.match(deploy, /docker pause youyidian-notification-center/) assert.match(deploy, /docker cp youyidian-notification-center:\/app\/data\/\. "\$data_backup\/"/) assert.match(deploy, /test -s "\$data_backup\/notifications\.db"/)