mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-19 05:01:15 +00:00
refactor: dedupe canvas lowercase helpers
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
import { resolveProviderCacheTtlEligibility } from "../../plugins/provider-runtime.js";
|
||||
import { normalizeLowercaseStringOrEmpty } from "../../shared/string-coerce.js";
|
||||
import {
|
||||
normalizeLowercaseStringOrEmpty,
|
||||
normalizeOptionalLowercaseString,
|
||||
} from "../../shared/string-coerce.js";
|
||||
import { isAnthropicFamilyCacheTtlEligible } from "./anthropic-family-cache-semantics.js";
|
||||
import { isGooglePromptCacheEligible } from "./prompt-cache-retention.js";
|
||||
|
||||
@@ -46,7 +49,7 @@ export function isCacheTtlEligibleProvider(
|
||||
}
|
||||
|
||||
function normalizeCacheTtlKey(value: string | undefined): string | undefined {
|
||||
return value?.trim().toLowerCase();
|
||||
return normalizeOptionalLowercaseString(value);
|
||||
}
|
||||
|
||||
function matchesCacheTtlContext(
|
||||
|
||||
@@ -3,6 +3,7 @@ import type { IncomingMessage, ServerResponse } from "node:http";
|
||||
import path from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { detectMime } from "../media/mime.js";
|
||||
import { normalizeLowercaseStringOrEmpty } from "../shared/string-coerce.js";
|
||||
import { resolveFileWithinRoot } from "./file-resolver.js";
|
||||
|
||||
export const A2UI_PATH = "/__openclaw__/a2ui";
|
||||
@@ -132,7 +133,7 @@ export function injectCanvasLiveReload(html: string): string {
|
||||
</script>
|
||||
`.trim();
|
||||
|
||||
const idx = html.toLowerCase().lastIndexOf("</body>");
|
||||
const idx = normalizeLowercaseStringOrEmpty(html).lastIndexOf("</body>");
|
||||
if (idx >= 0) {
|
||||
return `${html.slice(0, idx)}\n${snippet}\n${html.slice(idx)}`;
|
||||
}
|
||||
@@ -180,7 +181,7 @@ export async function handleA2uiHttpRequest(
|
||||
}
|
||||
|
||||
try {
|
||||
const lower = result.realPath.toLowerCase();
|
||||
const lower = normalizeLowercaseStringOrEmpty(result.realPath);
|
||||
const mime =
|
||||
lower.endsWith(".html") || lower.endsWith(".htm")
|
||||
? "text/html"
|
||||
|
||||
@@ -15,6 +15,7 @@ import { resolveStateDir } from "../config/paths.js";
|
||||
import { isTruthyEnvValue } from "../infra/env.js";
|
||||
import { detectMime } from "../media/mime.js";
|
||||
import type { RuntimeEnv } from "../runtime.js";
|
||||
import { normalizeLowercaseStringOrEmpty } from "../shared/string-coerce.js";
|
||||
import { ensureDir, resolveUserPath } from "../utils.js";
|
||||
import {
|
||||
CANVAS_HOST_PATH,
|
||||
@@ -393,7 +394,7 @@ export async function createCanvasHostHandler(
|
||||
await handle.close().catch(() => {});
|
||||
}
|
||||
|
||||
const lower = realPath.toLowerCase();
|
||||
const lower = normalizeLowercaseStringOrEmpty(realPath);
|
||||
const mime =
|
||||
lower.endsWith(".html") || lower.endsWith(".htm")
|
||||
? "text/html"
|
||||
@@ -464,7 +465,7 @@ export async function startCanvasHost(opts: CanvasHostServerOpts): Promise<Canva
|
||||
|
||||
const bindHost = opts.listenHost?.trim() || "127.0.0.1";
|
||||
const server: Server = http.createServer((req, res) => {
|
||||
if (String(req.headers.upgrade ?? "").toLowerCase() === "websocket") {
|
||||
if (normalizeLowercaseStringOrEmpty(req.headers.upgrade ?? "") === "websocket") {
|
||||
return;
|
||||
}
|
||||
void (async () => {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { ServerResponse } from "node:http";
|
||||
import { normalizeLowercaseStringOrEmpty } from "../shared/string-coerce.js";
|
||||
|
||||
export function createMockServerResponse(): ServerResponse & { body?: string } {
|
||||
const headers: Record<string, string> = {};
|
||||
@@ -13,10 +14,10 @@ export function createMockServerResponse(): ServerResponse & { body?: string } {
|
||||
headersSent: false,
|
||||
statusCode: 200,
|
||||
setHeader: (key: string, value: string) => {
|
||||
headers[key.toLowerCase()] = value;
|
||||
headers[normalizeLowercaseStringOrEmpty(key)] = value;
|
||||
return res;
|
||||
},
|
||||
getHeader: (key: string) => headers[key.toLowerCase()],
|
||||
getHeader: (key: string) => headers[normalizeLowercaseStringOrEmpty(key)],
|
||||
end: (body?: string) => {
|
||||
res.headersSent = true;
|
||||
res.body = body;
|
||||
|
||||
Reference in New Issue
Block a user