更新 Scripts/authorization&cartId.js
This commit is contained in:
@@ -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();
|
||||||
|
|||||||
Reference in New Issue
Block a user