45 lines
1.3 KiB
TypeScript
45 lines
1.3 KiB
TypeScript
import type { AgentWorkflowGoodsInfoApiConfig } from "@/types/agent";
|
|
|
|
export const AGENT_WORKFLOW_GOODS_INFO_API_CONFIG_KEY =
|
|
"agent_workflow_goods_info_api_config";
|
|
|
|
export const defaultAgentWorkflowGoodsInfoApiConfig: AgentWorkflowGoodsInfoApiConfig = {
|
|
enabled: false,
|
|
baseUrl: "https://www.jiansun.vip:63211",
|
|
clientKey: "",
|
|
secret: "",
|
|
};
|
|
|
|
function sanitizeText(value: unknown, maxLength: number) {
|
|
return String(value || "").trim().slice(0, maxLength);
|
|
}
|
|
|
|
export function normalizeAgentWorkflowGoodsInfoApiConfig(
|
|
value: unknown
|
|
): AgentWorkflowGoodsInfoApiConfig {
|
|
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
return defaultAgentWorkflowGoodsInfoApiConfig;
|
|
}
|
|
|
|
const raw = value as Partial<AgentWorkflowGoodsInfoApiConfig>;
|
|
|
|
return {
|
|
enabled: raw.enabled === true,
|
|
baseUrl:
|
|
sanitizeText(raw.baseUrl, 255) || defaultAgentWorkflowGoodsInfoApiConfig.baseUrl,
|
|
clientKey: sanitizeText(raw.clientKey, 255),
|
|
secret: sanitizeText(raw.secret, 255),
|
|
};
|
|
}
|
|
|
|
export function normalizeAgentWorkflowGoodsInfoApiConfigForPublic(
|
|
value: unknown
|
|
): AgentWorkflowGoodsInfoApiConfig {
|
|
const config = normalizeAgentWorkflowGoodsInfoApiConfig(value);
|
|
return {
|
|
...config,
|
|
clientKey: "",
|
|
secret: "",
|
|
};
|
|
}
|