mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 10:07:41 +00:00
fix(media): harden unknown mime handling from #39199 (thanks @nicolasgrasset)
Co-authored-by: Nicolas Grasset <nicolas.grasset@gmail.com>
This commit is contained in:
@@ -457,7 +457,7 @@ describe("local media root guard", () => {
|
||||
}),
|
||||
).resolves.toEqual(
|
||||
expect.objectContaining({
|
||||
kind: "unknown",
|
||||
kind: undefined,
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -468,7 +468,7 @@ describe("local media root guard", () => {
|
||||
}),
|
||||
).resolves.toEqual(
|
||||
expect.objectContaining({
|
||||
kind: "unknown",
|
||||
kind: undefined,
|
||||
}),
|
||||
);
|
||||
});
|
||||
@@ -498,7 +498,7 @@ describe("local media root guard", () => {
|
||||
}),
|
||||
).resolves.toEqual(
|
||||
expect.objectContaining({
|
||||
kind: "unknown",
|
||||
kind: undefined,
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
@@ -19,7 +19,7 @@ import { resolveUserPath } from "../utils.js";
|
||||
export type WebMediaResult = {
|
||||
buffer: Buffer;
|
||||
contentType?: string;
|
||||
kind: MediaKind;
|
||||
kind: MediaKind | undefined;
|
||||
fileName?: string;
|
||||
};
|
||||
|
||||
@@ -284,12 +284,12 @@ async function loadWebMediaInternal(
|
||||
const clampAndFinalize = async (params: {
|
||||
buffer: Buffer;
|
||||
contentType?: string;
|
||||
kind: MediaKind;
|
||||
kind: MediaKind | undefined;
|
||||
fileName?: string;
|
||||
}): Promise<WebMediaResult> => {
|
||||
// If caller explicitly provides maxBytes, trust it (for channels that handle large files).
|
||||
// Otherwise fall back to per-kind defaults.
|
||||
const cap = maxBytes !== undefined ? maxBytes : maxBytesForKind(params.kind);
|
||||
const cap = maxBytes !== undefined ? maxBytes : maxBytesForKind(params.kind ?? "document");
|
||||
if (params.kind === "image") {
|
||||
const isGif = params.contentType === "image/gif";
|
||||
if (isGif || !optimizeImages) {
|
||||
@@ -324,7 +324,7 @@ async function loadWebMediaInternal(
|
||||
if (/^https?:\/\//i.test(mediaUrl)) {
|
||||
// Enforce a download cap during fetch to avoid unbounded memory usage.
|
||||
// For optimized images, allow fetching larger payloads before compression.
|
||||
const defaultFetchCap = maxBytesForKind("unknown");
|
||||
const defaultFetchCap = maxBytesForKind("document");
|
||||
const fetchCap =
|
||||
maxBytes === undefined
|
||||
? defaultFetchCap
|
||||
|
||||
Reference in New Issue
Block a user