优化后端鉴权与日志安全
This commit is contained in:
@@ -11,8 +11,8 @@ import {
|
||||
import { KUAISHOU_CLOUD_FIXED_VN_KEY, type JsonObject } from "./domain.js";
|
||||
|
||||
export function resolveKuaishouCloudBindingResources(
|
||||
flow,
|
||||
{ skuItems = [], knapsackItems = [] } = {}
|
||||
flow: JsonObject,
|
||||
{ skuItems = [], knapsackItems = [] }: { skuItems?: unknown[], knapsackItems?: unknown[] } = {}
|
||||
) {
|
||||
const normalizedSkuItems = Array.isArray(skuItems)
|
||||
? skuItems.filter(isCloudSkuLikeItem)
|
||||
@@ -70,7 +70,7 @@ export function resolveKuaishouCloudBindingResources(
|
||||
};
|
||||
}
|
||||
|
||||
export function resolveKuaishouCloudVnKeyCandidates(_input = {}) {
|
||||
export function resolveKuaishouCloudVnKeyCandidates(_input: JsonObject = {}) {
|
||||
return [KUAISHOU_CLOUD_FIXED_VN_KEY];
|
||||
}
|
||||
|
||||
@@ -159,7 +159,7 @@ export async function prepareKuaishouCloudBindResourceWithFallback(input: JsonOb
|
||||
);
|
||||
}
|
||||
|
||||
function collectKuaishouCloudNameCandidates(flow) {
|
||||
function collectKuaishouCloudNameCandidates(flow: JsonObject) {
|
||||
return Array.from(
|
||||
new Set(
|
||||
[
|
||||
@@ -171,10 +171,10 @@ function collectKuaishouCloudNameCandidates(flow) {
|
||||
);
|
||||
}
|
||||
|
||||
function findCloudItemByNames(items, nameCandidates, preferredId = 0) {
|
||||
function findCloudItemByNames(items: JsonObject[], nameCandidates: string[], preferredId = 0) {
|
||||
const normalizedItems = Array.isArray(items) ? items : [];
|
||||
const normalizedNames = nameCandidates
|
||||
.map((item) => ({
|
||||
.map((item: string) => ({
|
||||
raw: String(item || "").trim(),
|
||||
normalized: normalizeProductName(item),
|
||||
}))
|
||||
@@ -182,34 +182,34 @@ function findCloudItemByNames(items, nameCandidates, preferredId = 0) {
|
||||
|
||||
if (normalizedNames.length === 0 || normalizedItems.length === 0) {
|
||||
return preferredId > 0
|
||||
? normalizedItems.find((item) => Number(item.id || 0) === preferredId) ||
|
||||
? normalizedItems.find((item: JsonObject) => Number(item.id || 0) === preferredId) ||
|
||||
null
|
||||
: null;
|
||||
}
|
||||
|
||||
if (preferredId > 0) {
|
||||
const preferred =
|
||||
normalizedItems.find((item) => Number(item.id || 0) === preferredId) ||
|
||||
normalizedItems.find((item: JsonObject) => Number(item.id || 0) === preferredId) ||
|
||||
null;
|
||||
if (preferred) {
|
||||
return preferred;
|
||||
}
|
||||
}
|
||||
|
||||
const exactMatches = normalizedItems.filter((item) => {
|
||||
const exactMatches = normalizedItems.filter((item: JsonObject) => {
|
||||
const itemName = normalizeProductName(item.name);
|
||||
return normalizedNames.some(
|
||||
(candidate) => candidate.normalized === itemName
|
||||
(candidate: { normalized: string }) => candidate.normalized === itemName
|
||||
);
|
||||
});
|
||||
if (exactMatches.length > 0) {
|
||||
return exactMatches[0];
|
||||
}
|
||||
|
||||
const partialMatches = normalizedItems.filter((item) => {
|
||||
const partialMatches = normalizedItems.filter((item: JsonObject) => {
|
||||
const itemName = normalizeProductName(item.name);
|
||||
return normalizedNames.some(
|
||||
(candidate) =>
|
||||
(candidate: { normalized: string }) =>
|
||||
itemName.includes(candidate.normalized) ||
|
||||
candidate.normalized.includes(itemName)
|
||||
);
|
||||
@@ -224,13 +224,15 @@ function findCloudItemByNames(items, nameCandidates, preferredId = 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
function isCloudSkuLikeItem(item) {
|
||||
return Boolean(item) && typeof item === "object" && Number(item.id || 0) > 0;
|
||||
function isCloudSkuLikeItem(item: unknown): item is JsonObject {
|
||||
const current = item && typeof item === "object" ? item as JsonObject : {};
|
||||
return Number(current.id || 0) > 0;
|
||||
}
|
||||
|
||||
function isRecoverableKuaishouCloudVnKeyError(error) {
|
||||
const errorCode = String(error?.errorCode || error?.code || "").trim();
|
||||
const errorMessage = String(error?.message || "").trim();
|
||||
function isRecoverableKuaishouCloudVnKeyError(error: unknown) {
|
||||
const current = error && typeof error === "object" ? error as JsonObject : {};
|
||||
const errorCode = String(current.errorCode || current.code || "").trim();
|
||||
const errorMessage = String(current.message || "").trim();
|
||||
return (
|
||||
errorCode === "cloudtentacles_vn_bind_url_failed" &&
|
||||
errorMessage.includes("不支持的游戏类型")
|
||||
|
||||
Reference in New Issue
Block a user