mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-30 13:20:21 +00:00
refactor: dedupe infra lowercase helpers
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import { normalizeOptionalLowercaseString } from "../shared/string-coerce.js";
|
||||
|
||||
/** Read loose boolean params from tool input that may arrive as booleans or "true"/"false" strings. */
|
||||
export function readBooleanParam(
|
||||
params: Record<string, unknown>,
|
||||
@@ -7,14 +9,12 @@ export function readBooleanParam(
|
||||
if (typeof raw === "boolean") {
|
||||
return raw;
|
||||
}
|
||||
if (typeof raw === "string") {
|
||||
const trimmed = raw.trim().toLowerCase();
|
||||
if (trimmed === "true") {
|
||||
return true;
|
||||
}
|
||||
if (trimmed === "false") {
|
||||
return false;
|
||||
}
|
||||
const normalized = normalizeOptionalLowercaseString(raw);
|
||||
if (normalized === "true") {
|
||||
return true;
|
||||
}
|
||||
if (normalized === "false") {
|
||||
return false;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
requestBodyErrorToText,
|
||||
} from "../infra/http-body.js";
|
||||
import { pruneMapToMaxSize } from "../infra/map-size.js";
|
||||
import { normalizeOptionalLowercaseString } from "../shared/string-coerce.js";
|
||||
import type { FixedWindowRateLimiter } from "./webhook-memory-guards.js";
|
||||
|
||||
export type WebhookBodyReadProfile = "pre-auth" | "post-auth";
|
||||
@@ -144,7 +145,7 @@ export function isJsonContentType(value: string | string[] | undefined): boolean
|
||||
if (!first) {
|
||||
return false;
|
||||
}
|
||||
const mediaType = first.split(";", 1)[0]?.trim().toLowerCase();
|
||||
const mediaType = normalizeOptionalLowercaseString(first.split(";", 1)[0]);
|
||||
return mediaType === "application/json" || Boolean(mediaType?.endsWith("+json"));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user