refactor: dedupe extension lowercase readers

This commit is contained in:
Peter Steinberger
2026-04-07 11:28:02 +01:00
parent fbf7859f6d
commit b39c7eece6
16 changed files with 64 additions and 37 deletions

View File

@@ -8,6 +8,7 @@ import {
} from "openclaw/plugin-sdk/channel-actions";
import { createLazyRuntimeNamedExport } from "openclaw/plugin-sdk/lazy-runtime";
import { isPrivateNetworkOptInEnabled } from "openclaw/plugin-sdk/ssrf-runtime";
import { normalizeOptionalLowercaseString } from "openclaw/plugin-sdk/text-runtime";
import { extractToolSend } from "openclaw/plugin-sdk/tool-send";
import { resolveBlueBubblesAccount } from "./accounts.js";
import {
@@ -100,7 +101,7 @@ export const bluebubblesMessageActions: ChannelMessageActionAdapter = {
const normalizedTarget = currentChannelId
? normalizeBlueBubblesMessagingTarget(currentChannelId)
: undefined;
const lowered = normalizedTarget?.trim().toLowerCase() ?? "";
const lowered = normalizeOptionalLowercaseString(normalizedTarget) ?? "";
const isGroupTarget =
lowered.startsWith("chat_guid:") ||
lowered.startsWith("chat_id:") ||

View File

@@ -1,7 +1,10 @@
import crypto from "node:crypto";
import path from "node:path";
import { formatErrorMessage } from "openclaw/plugin-sdk/error-runtime";
import { normalizeOptionalString } from "openclaw/plugin-sdk/text-runtime";
import {
normalizeOptionalLowercaseString,
normalizeOptionalString,
} from "openclaw/plugin-sdk/text-runtime";
import { resolveBlueBubblesServerAccount } from "./account-resolve.js";
import { assertMultipartActionOk, postMultipartFormData } from "./multipart.js";
import {
@@ -54,7 +57,7 @@ function ensureExtension(filename: string, extension: string, fallbackBase: stri
}
function resolveVoiceInfo(filename: string, contentType?: string) {
const normalizedType = contentType?.trim().toLowerCase();
const normalizedType = normalizeOptionalLowercaseString(contentType);
const extension = path.extname(filename).toLowerCase();
const isMp3 =
extension === ".mp3" || (normalizedType ? AUDIO_MIME_MP3.has(normalizedType) : false);

View File

@@ -4,7 +4,10 @@ import {
sendMediaWithLeadingCaption,
} from "openclaw/plugin-sdk/reply-payload";
import { isPrivateNetworkOptInEnabled } from "openclaw/plugin-sdk/ssrf-runtime";
import { normalizeOptionalString } from "openclaw/plugin-sdk/text-runtime";
import {
normalizeOptionalLowercaseString,
normalizeOptionalString,
} from "openclaw/plugin-sdk/text-runtime";
import { downloadBlueBubblesAttachment } from "./attachments.js";
import { markBlueBubblesChatRead, sendBlueBubblesTyping } from "./chat.js";
import { resolveBlueBubblesConversationRoute } from "./conversation-route.js";
@@ -93,7 +96,7 @@ const pendingOutboundMessageIds: PendingOutboundMessageId[] = [];
let pendingOutboundMessageIdCounter = 0;
function normalizeSnippet(value: string): string {
return stripMarkdown(value).replace(/\s+/g, " ").trim().toLowerCase();
return normalizeOptionalLowercaseString(stripMarkdown(value).replace(/\s+/g, " ")) ?? "";
}
type BlueBubblesChatRecord = Record<string, unknown>;

View File

@@ -1,5 +1,9 @@
import crypto from "node:crypto";
import { normalizeOptionalString, stripMarkdown } from "openclaw/plugin-sdk/text-runtime";
import {
normalizeOptionalLowercaseString,
normalizeOptionalString,
stripMarkdown,
} from "openclaw/plugin-sdk/text-runtime";
import { resolveBlueBubblesServerAccount } from "./account-resolve.js";
import {
getCachedBlueBubblesPrivateApiStatus,
@@ -62,10 +66,10 @@ const EFFECT_MAP: Record<string, string> = {
};
function resolveEffectId(raw?: string): string | undefined {
if (!raw) {
const trimmed = normalizeOptionalLowercaseString(raw);
if (!trimmed) {
return undefined;
}
const trimmed = raw.trim().toLowerCase();
if (EFFECT_MAP[trimmed]) {
return EFFECT_MAP[trimmed];
}