From 2bd2074a82ec33479de84f86a14ab4a922e9d4b9 Mon Sep 17 00:00:00 2001 From: XXhaos Date: Tue, 2 Jun 2026 00:23:10 +0900 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20Scripts/authorization&cart?= =?UTF-8?q?Id.js?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Scripts/authorization&cartId.js | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/Scripts/authorization&cartId.js b/Scripts/authorization&cartId.js index da7f257..288b353 100644 --- a/Scripts/authorization&cartId.js +++ b/Scripts/authorization&cartId.js @@ -6,14 +6,34 @@ * - 把每次捕获追加到 cart_records 数组(cartId 去重) */ -const pattern = /^https:\/\/cart\.production\.store-web\.dynamics\.com\/v1\.0\/Cart\/eligibilityCheck\?/; -const url = $request.url; +const patterns = [ + /^https:\/\/cart\.production\.store-web\.dynamics\.com\/v1\.0\/cart\/eligibilityCheck\?/i, + /^https:\/\/cart\.production\.store-web\.dynamics\.com\/cart\/v1\.0\/cart\/eligibilityCheck\?/i, + /^https:\/\/cart\.production\.store-web\.dynamics\.com\/.*eligibilityCheck\?/i +]; + +const url = $request.url || ""; +const matched = patterns.some(p => p.test(url)); const MAX_RECORDS = 10; // cart 记录保留最近 10 条 -if ($request.method === "PUT" && pattern.test(url)) { +// 兼容不同平台 Header 大小写差异 +function getHeader(name) { + const headers = $request.headers || {}; + const target = name.toLowerCase(); + + for (const key in headers) { + if (key.toLowerCase() === target) { + return headers[key]; + } + } + + return undefined; +} + +if (($request.method || "").toUpperCase() === "PUT" && matched) { try { - const authorization = $request.headers['authorization']; + const authorization = getHeader('authorization'); const urlObj = new URL(url); const cartId = urlObj.searchParams.get('cartId'); const now = Date.now(); @@ -63,4 +83,4 @@ function appendCartRecord(entry) { console.log(`[cart] ✅ 已记录 cartId=${entry.cartId}, total=${records.length}`); } -$done({}); +$done({}); \ No newline at end of file