更新 Scripts/authorization&cartId.js

This commit is contained in:
2026-06-02 00:23:10 +09:00
parent 281921efed
commit 2bd2074a82

View File

@@ -6,14 +6,34 @@
* - 把每次捕获追加到 cart_records 数组cartId 去重) * - 把每次捕获追加到 cart_records 数组cartId 去重)
*/ */
const pattern = /^https:\/\/cart\.production\.store-web\.dynamics\.com\/v1\.0\/Cart\/eligibilityCheck\?/; const patterns = [
const url = $request.url; /^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 条 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 { try {
const authorization = $request.headers['authorization']; const authorization = getHeader('authorization');
const urlObj = new URL(url); const urlObj = new URL(url);
const cartId = urlObj.searchParams.get('cartId'); const cartId = urlObj.searchParams.get('cartId');
const now = Date.now(); const now = Date.now();
@@ -63,4 +83,4 @@ function appendCartRecord(entry) {
console.log(`[cart] ✅ 已记录 cartId=${entry.cartId}, total=${records.length}`); console.log(`[cart] ✅ 已记录 cartId=${entry.cartId}, total=${records.length}`);
} }
$done({}); $done({});